Friends in the use of Delphi programming, often encounter the need to get their own IP address in the program. In previous versions, you could have done this by writing a piece of code or a function. But with Delphi 7, the job can be simplified. This functionality can be easily achieved by using a control with just one sentence of code.
Create a new Project1, add control statusbar1 (Win32 page) and control IdIPWatch1 (Indy misc page) to Form1. Then set the control properties: Add 0-tstatuspanel and 1-tstatuspanel two items to the STATUSBAR1 panels, and IdIPWatch1 's Historyenabled property to False.
Write code: Add the following code to Tform1.formcreate (sender:tobject):
StatusBar1. PANELS[1]. Text:=idipwatch1.localip;
Ok! Press the F9 function key, run the program, look at the bottom of the window is not the status bar has shown the IP address of this machine?
Tip: If IdIPWatch1 's Historyenabled property is set to True, a file (the value set by the Historyfilename property) is automatically generated when the program exits, recording the current IP address.