Naja, eigentlich habe ich das (habe auf der Form1 nicht selbst Instanziiert, sondern von der Komponentenleiste
auf die Form1 plaziert)..
Delphi-Quellcode:
//Form1
uses [...], clMessages, [...];
//clMessages ist die .pas Datei von der Form2.
type
TForm1 = class(TForm)
ClientSock: TClientSocket;
procedure FormDestroy(Sender: TObject);
procedure ClientSockConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSockConnecting(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSockDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSockRead(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
fForm2: TForm2;
fForm3: TForm3;
fForm4: TForm4;
fForm5: TForm5;
fForm6: TForm6;
fForm7: TForm7;
fForm8: TForm8;
fForm9: TForm9;
fForm10: TForm10;
fForm11: TForm11;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form2.Show;
fForm2 := TForm2.Create(Self);
fForm2.Clientsocket := Self.ClientSock;
fForm3 := TForm3.Create(Self);
fForm3.Clientsocket := Self.ClientSock;
fForm4 := TForm4.Create(Self);
fForm4.Clientsocket := Self.ClientSock;
fForm5 := TForm5.Create(Self);
fForm5.Clientsocket := Self.ClientSock;
fForm6 := TForm6.Create(Self);
fForm6.Clientsocket := Self.ClientSock;
fForm7 := TForm7.Create(Self);
fForm7.Clientsocket := Self.ClientSock;
fForm8 := TForm8.Create(Self);
fForm8.Clientsocket := Self.ClientSock;
fForm9 := TForm9.Create(Self);
fForm9.Clientsocket := Self.ClientSock;
fForm10 := TForm10.Create(Self);
fForm10.Clientsocket := Self.ClientSock;
fForm11 := TForm11.Create(Self);
fForm11.Clientsocket := Self.ClientSock;
ClientSock.Port := 7000;
ClientSock.Host := gHostAddr;
currentHost := gHostAddr;
ClientSock.Active := true;
end;
//Form2
type
TForm2 = class(TForm)
procedure cmdSendClick(Sender: TObject);
procedure cmdCloseClick(Sender: TObject);
private
fSocket: TClientSocket;
{ Private-Deklarationen }
public
property Clientsocket: TClientSocket read fSocket write fSocket;
{ Public-Deklarationen }
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
fSocket.Socket.SendText('Hallo Server');
end;