Delphi and C++Builder DataSnap Server tip - displaying the TCP/IP and Port

Posted by on in Blogs
I've always wanted to display the TCP/IP address and Port number on the caption of my Delphi and C++ DataSnap servers.  Here is the code that accomplishes this for my DataSnap Server form's OnCreate event.

For Delphi:

1) Add the IdStack unit to the uses clause in your form's implementation section

2) Add the following code to your OnCreate event handler:

    Form1.Caption := 'Embarcadero DSServer Application. IP Addr: '
    + GStack.LocalAddress
    + ' Port: '
    + IntToStr(DSTCPServerTransport1.Port);

For C++Builder:

1) Add #include <IdStack.hpp> near the top of the form's source code

2) Add the following code to your OnCreate event handler:

    Form1->Caption = "Embarcadero DSServer Application. IP Addr: "
    + GStack->LocalAddress
    + " Port: "
    + IntToStr(DSTCPServerTransport1->Port);

For which form should you add the uses/#include and code?  On the form or data module that contains the DataSnap server, server class and transport components.


About
Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.

Comments

Check out more tips and tricks in this development video: