Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-03

List the procedures of a object.

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth
to Everton Vieira
Everton Vieira 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.

Regards,
Sven

Reply by email

Everton Vieira
to Everton Vieira: 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.
Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120327/9b0c0a01/attachment.html>

Reply by email

Everton Vieira
to 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
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. > -- Everton Vieira.
Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120327/ab3fadbd/attachment.html>

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 8 lines
On Tue, Mar 27, 2012 at 04:51:52PM +0200, 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 ;-)

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.

Reply by email

Marco van de Voort
to Michael Van Canneyt
Michael Van Canneyt wrote 11 lines
> > 2010 actually. And since this list has been _very_ sensitive about bloat > recently, I would not even dare to suggest that way ;-) 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.

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.

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 16 lines
On Tue, Mar 27, 2012 at 09:00:07PM +0200, Michael Van Canneyt wrote: >> >> 2010 actually. And since this list has been _very_ sensitive about bloat >> recently, I would not even dare to suggest that way ;-) > > 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. 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.

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.

Reply by email

Everton Vieira
to Michael Van Canneyt

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
On Tue, 27 Mar 2012, Marco van de Voort wrote: On Tue, Mar 27, 2012 at 09:00:07PM +0200, Michael Van Canneyt wrote: > >> >>> 2010 actually. And since this list has been _very_ sensitive about bloat >>> recently, I would not even dare to suggest that way ;-) >>> >> >> 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. >> > > 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. > 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. -- ______________________________**_________________ Lazarus mailing list .**freepascal.org http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120327/1c7dc3d5/attachment-0001.html>

Reply by email

Sven Barth
to Everton Vieira: Well, i manage to 'find' the procedure now is giving the SIGSEV when is executed. For the…
Everton Vieira wrote
Well, 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

Reply by email