Creating the Client application (TObjects and DataSnap Tutorial)

From Appmethod Topics
Jump to: navigation, search

Go Up to Tutorial: Passing Plain Old Object Pascal Objects with DataSnap

Creating the Client application

Follow the next steps in order to build the client:

1. Right-click the Group project, select Add New Project, then select VCL Forms Application and press OK.

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

3. Select File > New > Other.

4. From the DataSnap Server node in the left column, select DBX DataSnap Client Module and press OK.


5. Specify the type of the module:

  1. Keep the default value selected--Local server--and press Next.
  2. Keep the default value selected--DataSnap stand-alone server--and press Next.
  3. Keep the default value selected--TCP/IP Protocol--and press Next.
  4. Press Test Port to verify whether the Port 211 is open and press Finish.
Now the wizard has generated ClientModuleUnit and ClassesClientUnit.
Notice that, in ClientClassesUnit.pas, the TServerMehods2Client 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.

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

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

  1. In the FormClientUnit design page, add two TEdit elements, using the Tool Palette, and change their names to EditLastname and EditFirstname.
  2. Add a TButton component, using the Tool Palette, and change its caption to ShowPerson.

8. In the FormClientUnit, select File > Use Unit > ClientClassesUnit1.pas, ClientModuleUnit1.pas, and SharedStuffUnit.pas and press OK.

9. Double-click the ShowPerson button, to implement its functionality.

    p: TPerson;

    p := ClientModule1.ServerMethods2Client.GetPerson(EditFirstname.Text, EditLastname.Text);
    if p <> nil then
  TPerson *p;

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

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



See Also