First sample (Delphi)
Overview
This sample provides an introduction to using the Delphi edition of the Remoting SDK product.
The example shows how to define/implement methods on the server and how to access them from the client. The data consists of name information; four simple methods are provided by the service: Nicknames
, VerifyName
, CheckName
and FullNames
.
Getting Started
- Build or compile both projects.
- Launch the server (via the menu command:
Tools -> Remoting SDK -> Launch Server Executable
). - Ensure that
FirstSampleClient
is the selected project and run it. - Check that the client buttons work as expected.
- Modify the server names list and retry client actions.
Examine the Code
- See how the four methods were defined by editing the service library. Do this by making the server the selected project and by using the menu option:
Tools -> Remoting SDK -> Edit Service Library
.
Note: If you don't see this menu option, but Service Builder
instead, you still have the client set as the current project. Examine the methods added to FirstSampleService
.
- Check how the server methods were implemented in
FirstSampleService_Impl.pas
. For example, theNicknames
method's code is:
function TFirstSampleService.Nicknames(const FullName: Unicodestring): Unicodestring;
var
i: integer;
begin
Result := '';
with FirstSampleServerMainForm do begin
MultiReadSingleWriter.BeginRead;
try
with ValueListEditor.Strings do
for i := 0 to Count - 1 do
if (Fullname = '') or (CompareText(Values[Names[i]], FullName) = 0) then
Result := Result + ',' + Names[i];
finally
MultiReadSingleWriter.EndRead;
end;
end;
if Result <> '' then Delete(Result, 1, 1);
end;
- Examine the simple code needed to invoke the methods in
FirstSampleClientMain.pas
. First of all, it is necessary to create a service instance:
constructor TFirstSampleClientMainForm.Create(aOwner: TComponent);
begin
inherited;
fFirstService := (RORemoteService as IFirstSampleService);
end;
And call its method, Nicknames
for example:
procedure TFirstSampleClientMainForm.GetButtonClick(Sender: TObject);
begin
NamesBox.Items.CommaText := fFirstService.Nicknames(eFullname.Text);
end;