Creating the Client application (TObjects and DataSnap Tutorial)

From RAD Studio
Jump to: navigation, search

Go Up to Tutorial: Passing Plain Old Delphi Objects with DataSnap

Creating the Client application

Follow the next steps in order to build the client application:

1. Right-click the Group project and select Add New Project

2. From the C++Builder Projects or Delphi Projects node, select Multi-Device Application and press OK.

3. Save the project in the same location as the server and set the name of the first unit to FormClientUnit, of the project to PODOClient, and of the group to PODOGrp.

4. Select File > New > Other.

5. From the DataSnap Server node from C++Builder Projects or Delphi Projects in the left column, select DataSnap Client Module and press OK.

Opo4.png

6. Specify the type of the module:

  • Keep the default value selected -- Local server -- and press Next.
  • Keep the default value selected -- DataSnap stand alone server -- and press Next.
  • Keep the default value selected -- TCP/IP Protocol -- and press Next.
  • Press Test Port to verify whether the Port 211 is open and press Finish.

Note: Make sure the server application is running.

  • Now the wizard has generated ClientModuleUnit and ClassesClientUnit.

Notice: In ClientClassesUnit, the TServerMehods1Client class was generated, along with its GetPerson function. It has the same signature as the class from the server. You must call this method locally.

7. Move SharedStuffUnit from the server project to the client project using a drag-and-drop operation.

8. Implement a small graphical user interface for the client:

  • In the FormClientUnit design page, add two TEdit elements, using the Tool Palette, and change their names to EditLastname and EditFirstname.
  • Add a TButton component, using the Tool Palette, and change its caption to Show Person.
Opo5.png

9. In the FormClientUnit, select File > Use Unit....

10. Select ClientClassesUnit1, ClientModuleUnit1, and SharedStuffUnit and press OK.

11. Double-click the Show Person button to implement its functionality.

Delphi:

  var
    p: TPerson;
  begin
    p := ClientModule1.ServerMethods2Client.GetPerson(EditFirstname.Text, EditLastname.Text);

    if p <> nil then
    begin	
      ShowMessage(p.ToString);
    end;
  end;

C++Builder:

 
  TPerson *p;
  p = new TPerson(EditFirstname->Text, EditLastname->Text);

  if (p != NULL)
    ShowMessage(p->ToString());
  • The implementation of the ShowPerson button calls the server to return a person object (TPerson, derived from TObject). After that, it tests whether the server actually returned something. If it does, the message contains the Firstname and the Lastname of the person.

Next

Previous

See Also