I am new to using RTTI and now I'm stuck on an error.
I am trying to call a procedure by name and pass parameter with an array of TValue. The first problem is that GetParameters returns an array of 0 length (instead of 1), and I can't ignore this an try to call the procedure with an empty array.
Here's the code:
procedure TFormGenPopUpMessaggi.ExecMethod(Form : TObject; MethodName:string; const Args: array of TValue);
var
R : TRttiContext;
T : TRttiType;
M : TRttiMethod;
LParams : TArray<TRttiParameter>;
begin
T := R.GetType(TFormAcqGestioneRichiesteAcquisto);
for M in t.GetDeclaredMethods do
if (m.Parent = t) and (m.Name = MethodName)then
Begin
LParams := m.GetParameters;
showmessage(IntToStr(Length(LParams)));
M.Invoke(TFormAcqGestioneRichiesteAcquisto.Create(Self), Parametri);
End;
end;
procedure TFormGenPopUpMessaggi.EseguiMessaggio(Sender : TObject);
var Procedura, TipoClasse : String;
Argomenti : String;
ArrayArgomenti : Array of TValue;
IdMessaggio, IdElenco : Integer;
I : Integer;
C : TRttiContext;
O : TObject;
begin
[...]`
Procedura := QGenerica.FieldByName('NOME_PROCEDURA').AsString;
[...]
TipoClasse := 'U' + Copy(QGenerica.FieldByName('NOME_FORM').AsString, 6, 1000) + '.' + QGenerica.FieldByName('NOME_FORM').AsString;
O := (C.FindType(TipoClasse) as TRttiInstanceType).MetaClassType.Create;
if Length(ArrayArgomenti) = 0 then
ExecMethod(O, Procedura,[])
else
ExecMethod(O, Procedura, ArrayArgomenti);
[...]
End;
And the called procedure is:
procedure TrovaRichiesta(Id : Integer);
declared in public in another class type TFormAcqGestioneRichiesteAcquisto.
The code find the procedure name correctly, create the new form class correctly but don't give me any parameter showmessage(IntToStr(Length(LParams))) result is 0.
All the other variables are correctly initialized. Are there any type of keys to define, in order to enable RTTI?