Dynamic Request sample (Delphi)
Overview
This sample shows how to use the TRODynamicRequest component to perform remote requests dynamically at runtime with no service information (i.e. Proxy objects and other structures produced by code generation) defined at compile time.
Getting Started
- Compile and launch the server.
- Compile and run the client.
- Call every implemented service method by clicking the corresponding button.
Examine the Code
-
See how the three methods were defined by editing the service library. To edit the service library, make the server the selected project and use the menu command:
Tools | Remoting SDK | Edit Service Library
. Note: if you don't see this menu item, but seeService Builder
instead, you still have the client set as the current project. Examine the methods added to theDynamicRequestService
. -
See the simple code used to invoke the methods in
DynamicRequestClientMain.pas
. It is necessary to set theRemoteService
,MethodName
andParams
properties of the TRODynamicRequest instance either in design- or runtime for dynamic request executing.
procedure TDynamicRequestClientMainForm.bSumClick(Sender: TObject);
begin
with DynamicRequestSum do begin
ParamByName('A').AsInteger := 1;
ParamByName('B').AsInteger := 2;
Log('Sum');
Log('--------');
Log('sending:' + #9 + ParamByName('A').AsString + ' ' + ParamByName('B').AsString);
Execute;
Log('received:' + #9 + ParamByName('result').AsString);
Log('');
end;
end;
- Notice that the function result is returned as an output parameter with the predefined name
result
.