Einzelnen Beitrag anzeigen

KLS

Registriert seit: 20. Jun 2004
Ort: Berlin
89 Beiträge
 
Delphi 7 Enterprise
 
#12

Re: Funktionsnamen aus Variablen?

  Alt 7. Aug 2005, 15:49
es gibt eine recht einfache möglichkeit

Delphi-Quellcode:
procedure StarteRoutineByName(Instance : TObject; Name : string); //instance z.b. Form1
type
  TExecute = procedure of object;
var
  Routine : TMethod;
  Execute : TExecute;
begin
  Routine.Data := Pointer(Instance);
  Routine.Code := Instance.MethodAddress(Name);
  if Routine.Code = nil then Exit;
  Execute := TExecute(Routine);
  Execute;
end;
und damit die sache perfekt ist

Delphi-Quellcode:
function FindFormByName(Formname : string) : Tform;
var
  i : byte;
begin
  result := nil;
  for i := 0 to screen.FormCount-1 do if screen.Forms[i].Name = Formname then
  begin
    result := screen.Forms[i];
    break;
  end;
end;
Thomas H.
  Mit Zitat antworten Zitat