Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,58 @@
|
|||
program Test;
|
||||
{$mode objfpc}{$h+}
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
type
|
||||
TProc = procedure of object;
|
||||
|
||||
{$push}{$m+}
|
||||
TMyObj = class
|
||||
strict private
|
||||
FName: string;
|
||||
public
|
||||
constructor Create(const aName: string);
|
||||
property Name: string read FName;
|
||||
published
|
||||
procedure Foo;
|
||||
procedure Bar;
|
||||
end;
|
||||
{$pop}
|
||||
|
||||
constructor TMyObj.Create(const aName: string);
|
||||
begin
|
||||
FName := aName;
|
||||
end;
|
||||
|
||||
procedure TMyObj.Foo;
|
||||
begin
|
||||
WriteLn(Format('This is %s.Foo()', [Name]));
|
||||
end;
|
||||
|
||||
procedure TMyObj.Bar;
|
||||
begin
|
||||
WriteLn(Format('This is %s.Bar()', [Name]));
|
||||
end;
|
||||
|
||||
procedure CallByName(o: TMyObj; const aName: string);
|
||||
var
|
||||
m: TMethod;
|
||||
begin
|
||||
m.Code := o.MethodAddress(aName);
|
||||
if m.Code <> nil then begin
|
||||
m.Data := o;
|
||||
TProc(m)();
|
||||
end else
|
||||
WriteLn(Format('Unknown method(%s)', [aName]));
|
||||
end;
|
||||
|
||||
var
|
||||
o: TMyObj;
|
||||
|
||||
begin
|
||||
o := TMyObj.Create('Obj');
|
||||
CallByName(o, 'Bar');
|
||||
CallByName(o, 'Foo');
|
||||
CallByName(o, 'Baz');
|
||||
o.Free;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue