프로시져 이름으로 호출하기

From YYpBD's MediaWiki

Jump to: navigation, search

프로시져 이름으로 호출하기.  
출처 : http://jansfreeware.com

Delphi methods by name
by Jan Verhoeven, 15 November 2002


In Delphi you can call published methods by name.

function TPascalServerF.ExecProc(MyProcStr : String):boolean;
Var
MyProc : procedure of object;
Begin
TMethod(myProc).data:=self;
TMethod(MyProc).code :=MethodAddress(MyProcStr);
result:=true;
if not Assigned(MyProc) Then
   result:=false
else
   MyProc;
end;


Re: 이벤트도 연결 가능합니다.  
메뉴를 동적으로 생성하고 클릭이벤트를 할당할때 사용한 방법입니다.

주의해야하는 것은 이벤트 프로시저를 published에 선언을 해야 연결됩니다.

var
myMeth : TMethod;
pi : PPropInfo;
begin
Result := False;
myMeth.Code := MethodAddress(EventName);
myMeth.Data := Self;

if myMeth.Code = nil then
begin
   Exit;
end;

pi := GetPropInfo(AMenu.classInfo, 'OnClick');
if Assigned(pi) then
   SetMethodProp(AMenu,pi,myMeth);
Result := True;
end;

출처는 델마당 어디선가......

맞춤검색