2018/11/14 - [ - Delphi] - 문자열로 함수 호출하기 - 1
type
TProcList = class
public
procedure TestStringCallMethod1;
function TestStringCallMethod2(s1, s2, s3 : string): Boolean;
end;
...
implementation
uses
Rtti;
procedure ExecMethod(MethodName:string; const Args: array of TValue);
var
R : TRttiContext;
T : TRttiType;
M : TRttiMethod;
begin
T := R.GetType(TProcList);
for M in t.GetMethods do
begin
if (m.Parent = t) and (m.Name = MethodName) then
M.Invoke(TProcList.Create, Args);
end;
end;
procedure TProcList.TestStringCallMethod1;
begin
ShowMessage('1번 문자열 함수 호출 성공!');
end;
function TProcList.TestStringCallMethod2(s1, s2, s3 : string): Boolean;
begin
ShowMessage(s1 + ' ' + s2 + ' ' + s3);
end;
문자열로 함수 호출하기
ExecMethod('TestStringCallMethod1',[]);
ExecMethod('TestStringCallMethod2',['2번 문자열', '함수 호출', '성공!']);