(Moderator)
Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
Delphi 2007 Enterprise
|
Re: Dynamischer Funktionsaufruf
13. Aug 2009, 14:36
So gehts:
Delphi-Quellcode:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm4 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure ExecMethod(aObject: TObject; MethodName, Param: string);
published
procedure Test(Astring: string);
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
type
TStringParamProc = procedure(aString: string) of object;
procedure TForm4.Button1Click(Sender: TObject);
begin
ExecMethod(Self, ' Test', ' Hallo');
end;
procedure TForm4.Test(Astring: string);
begin
showmessage(' Bingo ' + aString);
end;
procedure TForm4.ExecMethod(aObject: TObject; MethodName, Param: string);
var
Routine: TMethod;
Exec: TStringParamProc;
begin
Routine.Data := Pointer(aObject);
Routine.Code := aObject.MethodAddress(MethodName);
if not Assigned(Routine.Code) then Exit;
Exec := TStringParamProc(Routine);
Exec(Param);
end;
end.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
|
|
Zitat
|