Esque ando aburrido y ya ni se que hacer.

Quice hacer diferente las dos partes, asi que para los 2 botones con mensaje use IDStack
y para el boton que muestre en texto use edit1.text + la función getip
Código: Seleccionar todo
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IDStack,Winsock, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
Edit1: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetIp: string;
var
Buffer: array[0..127] of char;
WSAData: TWSADATA;
HostEnt: phostent;
begin
Result:= '';
FillChar(Buffer,Sizeof(Buffer),#0);
if WSAStartup(MAKEWORD(1, 1), WSADATA) = 0 then
begin
if GetHostName(@Buffer,Sizeof(Buffer)) = 0 then
begin
HostEnt:= gethostbyname(@Buffer);
if HostEnt <> nil then
Result:= String(inet_ntoa(PInAddr(HostEnt.h_addr_list^)^));
end;
WSACleanup;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
with TIdStack.CreateStack do
Try
For i:=0 to LocalAddresses.Count-1 do
showmessage (LocalAddresses[i]);
finally
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
with TIdStack.CreateStack do
Try
For i:=0 to LocalAddresses.Count-1 do
showmessage(LocalAddress)
finally
Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.text := GetIp;
end;
//coded by Matabarras
end.
Descarga del Compilado: [Enlace externo eliminado para invitados]
Descarga del Source: [Enlace externo eliminado para invitados]
Espero que les sirva para algunas aplicacionés o algo que hagan saludos.