Hello,
Following with this :
https://support.tmssoftware.com/t/problem-with-overloaded-method-rtti-registered/15111/8
I would like to register method TCustomRESTRequest.AddBody to the scripter.
Problem there is a same number of arguments in this case :
procedure AddBody(const ABodyContent: string; AContentType: TRESTContentType = ctNone); overload;
procedure AddBody(AObject: TJsonObject; AOwnsObject: TRESTObjectOwnership = ooApp); overload;
I know how to detect argument count using TatVirualMachine.InputArgCount like this :
procedure TatRESTClientLibrary.__TRESTRequestParameterListAddItem(AMachine: TatVirtualMachine);
var
AResult: variant;
TempVar:TRESTRequestParameterOptions;
begin
with AMachine do
begin
case InputArgCount of
0,1: AResult := ObjectToVar(TRESTRequestParameterList(CurrentObject).AddItem);
2: AResult := ObjectToVar(TRESTRequestParameterList(CurrentObject).AddItem(AMachine.GetInputArgAsString(0), AMachine.GetInputArgAsString(1)));
3: AResult := ObjectToVar(TRESTRequestParameterList(CurrentObject).AddItem(AMachine.GetInputArgAsString(0), AMachine.GetInputArgAsString(1),TRESTRequestParameterKind(AMachine.GetInputArgAsInteger(2))));
4: begin
IntToSet(TempVar, VarToInteger(GetInputArg(3)), SizeOf(TempVar));
AResult := ObjectToVar(TRESTRequestParameterList(CurrentObject).AddItem(AMachine.GetInputArgAsString(0), AMachine.GetInputArgAsString(1),TRESTRequestParameterKind(AMachine.GetInputArgAsInteger(2)),TempVar));
end;
5: begin
IntToSet(TempVar, VarToInteger(GetInputArg(3)), SizeOf(TempVar));
AResult := ObjectToVar(TRESTRequestParameterList(CurrentObject).AddItem(AMachine.GetInputArgAsString(0), AMachine.GetInputArgAsString(1),TRESTRequestParameterKind(AMachine.GetInputArgAsInteger(2)),TempVar,TRESTContentType(AMachine.GetInputArgAsInteger(4))));
end;
6: begin
IntToSet(TempVar, VarToInteger(GetInputArg(3)), SizeOf(TempVar));
AResult := ObjectToVar(TRESTRequestParameterList(CurrentObject).AddItem(AMachine.GetInputArgAsString(0), TStream(AMachine.GetInputArgAsObject(1)),TRESTRequestParameterKind(AMachine.GetInputArgAsInteger(2)),TempVar,TRESTContentType(AMachine.GetInputArgAsInteger(4)),TRESTObjectOwnership(AMachine.GetInputArgAsInteger(5))));
end;
end;
ReturnOutputArg(AResult);
end;
end;
But what is the good way to detect is an argument is a String, an integer or a Object ?
Like the 1st argument of AddBody which can be a TJsonObject or a string.
In TIdCustomHTTP.Post have tried this ulgy :
if assigned(AMachine.GetInputArgAsClass(1)) and (TObject(GetInputArgAsClass(1)) is TStrings ) and assigned(GetInputArgAsClass(2)) and (TObject(NativeUInt(GetInputArg(2))) is TStream) then
Which doesn't seems to work fine.
Does the unique solution is to register a custom method with each case of arguments type ?