Is there any how to list the procedures of a object? Att.
Everton Vieira.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120327/b20c7773/attachment.html>
Mailing lists / lazarus / 2012-03
List the procedures of a object.
10 messages · 4 people · –
- EEverton Vieira 4
- MMarco van de Voort 2
- MMichael Van Canneyt 2
- SSven Barth 2
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Everton Vieira wroteIs there any how to list the procedures of a object?
If you mean in runtime code: there isn't currently any supported method for this. We'd need the extended RTTI of Delphi 2009 for this.
Regards,
Sven
Is there any how to list the procedures of a object? Att. Everton Vieira. --------------…
I need to execute an procedure of an object if his exists, i'm doing some tests and get into this, but this is generating an SIGSEV:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TTeste }
TTeste = class
procedure Proc;
end;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
type
TProc = procedure of object;
implementation
procedure DoProc(Sender: TObject);
var
Proc: TProc;
begin
Proc := TProc(Sender.MethodAddress('Proc')^);
Proc;
end;
{ TTeste }
procedure TTeste.Proc;
begin
ShowMessage('oi');
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
DoProc(TTeste.Create);
end;
end.2012/3/27 Everton Vieira
Is there any how to list the procedures of a object? Att. Everton Vieira.
Well, i manage to 'find' the procedure now is giving the SIGSEV when is executed.
For the MethodAddress finds was need to be published.
unit Unit1;
{$mode objfpc}{$M+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TTeste }
TTeste = class
published
procedure Proc;
end;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
type
TProc = procedure of object;
implementation
procedure DoProc(Sender: TObject);
var
Proc: TProc;
begin
Proc := TProc(Sender.MethodAddress('Proc')^);
Proc; <-- Aqui gera o SIGSEV
end;
{ TTeste }
procedure TTeste.Proc;
begin
ShowMessage('oi');
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
DoProc(TTeste.Create);
end;
end.2012/3/27 Everton Vieira
Show quoted text 77 lines
If you mean in runtime code: there isn't currently any supported method for this. We'd…
Sven Barth wrote> Is there any how to list the procedures of a object? If you mean in runtime code: there isn't currently any supported method for this. We'd need the extended RTTI of Delphi 2009 for this.
2010 actually. And since this list has been _very_ sensitive about bloat recently, I would not even dare to suggest that way ;-)
Marco van de Voort wrote 8 lines
I would.
Under command of some switch, of course, it surely would come in handy.
The rtti unit they made for it is of course totally convoluted, but the idea to be able to use introspection on all aspects of a class is definitely useful and would make RPC frameworks a breeze.
Michael.
Michael Van Canneyt wrote 11 lines
That's roughly my opinion too, after a short read-up during D2010 times. Never enable it globally only for certain classes in frameworks that benefit from it. Haven't really used it yet though.
Marco van de Voort wrote 16 lines
Well, I am using it - I'm exposing a JSON RPC through it.
The 'only for certain classes' is my point of view as well.
It would only be necessary for the classes that get exposed as data, and the interfaces.
Michael.
I just did, the real case just saved me to do about 10.000 lines of code in a very tedious job.
Became like this:
unit Unit1;
{$mode objfpc}{$M+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TTeste }
TTeste = class
published
procedure Proc;
end;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
type
TProc = procedure of object;
implementation
procedure DoProc(Sender: TObject);
var
M : TMethod;
P: TProc;
begin
M.Data := Pointer(Sender) ;
M.Code := Sender.MethodAddress('Proc') ;
P := TProc(M);
P;
end;
{ TTeste }
procedure TTeste.Proc;
begin
ShowMessage('oi');
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
DoProc(TTeste.Create);
end;
end.2012/3/27 Michael Van Canneyt
Show quoted text 44 lines
Well, i manage to 'find' the procedure now is giving the SIGSEV when is executed. For the…
Everton Vieira wroteWell, i manage to 'find' the procedure now is giving the SIGSEV when is executed. For the MethodAddress finds was need to be published.
Note: It is sufficient if you enabled $M only for specific classes. Descendents of TPersistent (e.g. TControl, TComponent, TForm, etc) all have it enabled by default.
E.g.
{$M+}
TTeste = class
end;
{$M-}Also your code is wrong. You wrote:
Proc := TProc(Sender.MethodAddress('Proc')^);but it should be
Proc := TProc(Sender.MethodAddress('Proc'));Note the missing "^"! (a procedural variable IS a method address)
Regards,
Sven
