Autor Beitrag
stratege15
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 28.10.03 02:07 
hallo,

ich wollte das netzerkchat-tutorial mal ausprobieren .. nur bei der compilierung bekomme ich folgenden fehler:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure ClientSocket1Read;
var s : String;

   begin
   s := Socket.ReceiveText;   // nicht genügend wirkliche parameter
   Memo1.Lines.add(s);

  end;

wodran liegts? ich hoffe ihr könnt mir helfen. schonmal danke im voraus,
Stratege

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
maze2k
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 252

WIN 95, WIN NT 4.0, WIN 98, WIN 98SE, WIN 2000, RedHat Linux 7.3, Mandrake Linux 9.2, Knoppix Linux 3.3
D6 Pers
BeitragVerfasst: Di 28.10.03 03:19 
Hmm, da fehlt wohl ein bißchen was bei dir *g*

Also ich nehme mal an dein Memo und dein ClientSocket hast du auf der Form plaziert.
Um das onRead-Event des ClientSocket zu bearbeiten, markier den Clientsocket auf der Form oder wähl in der Objekt-Hierarchie aus und geh dann im Objektinspektor auf Ereignisse.
Da klickst du dann mal doppelt auf "OnRead".
Damit erstellst du eine neue Prozedur für das OnRead-Ereignis des ClientSockets.
Wenn du es so machst, dann kannst du sicher sein, dass du nichts vergessen hast, zumindest beim Rahmen der Prozedur, also bei der Deklaration.

So sollte es aussehen (Vergleich einfach mal meins und deins und dann fällt dir vielleicht auf dass bei dir ein bißchen was fehlt *g*)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
var s: String;
begin
  s := Socket.ReceiveText;
  Memo1.Lines.Add(s);
end;

_________________
Wer das Konzept der Unendlichkeit verstehen will, muss nur das Ausmaß menschlicher Dummheit betrachten. (Voltaire)
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 28.10.03 15:04 
das ist ja genau das problem .. ich habe keine serversocket - komponente auf der form eingefügt, weil ich bei meinem delphi (3) irgendwie keine icon-komponente davon habe. wie kann ich das problem lösen ?
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Di 28.10.03 15:22 
dann musst du auf den Procedure-Kopf aufpassen :!:

so:
ausblenden Delphi-Quelltext
1:
2:
procedure TForm1.ClientSocket1Read(Sender: TObject; 
  Socket: TCustomWinSocket);

nicht so:
ausblenden Delphi-Quelltext
1:
procedure ClientSocket1Read;					

MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 28.10.03 22:46 
danke .. das hab ich soweit. nur der chat funktioniert nicht?! ich habe beide sockets auf den selben port eingestellt (port 50), doch wenn ich ein server-programm und ein client-programm starte, wird kommt beim jeweils anderen programm keine chatnachricht zum vorschein.
ne ahnung?
JJJ666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

Win XP

BeitragVerfasst: Di 28.10.03 23:02 
hmm poste doch einfach mal den code hier!
denke ma wir köönen dann besser helffen!

cya JJJ

_________________
Nicht denken, wissen!
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Di 28.10.03 23:14 
hier der code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, scktcomp, winsock,
  StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Memo1: TMemo;
    Memo2: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  clientsocket1: tclientsocket;
  serversocket1: tserversocket;

implementation

{$R *.DFM}


function getIPs: Tstrings;
type 
  TaPInAddr = array[0..10of PInAddr; 
  PaPInAddr = ^TaPInAddr; 
var 
  phe: PHostEnt;  
  pptr: PaPInAddr; 
  Buffer: array[0..63of Char;  
  I: Integer; 
  GInitData: TWSAData;  
begin 
  WSAStartup($101, GInitData);  
  Result := TstringList.Create; 
  Result.Clear;  
  GetHostName(Buffer, SizeOf(Buffer));  
  phe := GetHostByName(buffer); 
  if phe = nil then Exit;  
  pPtr := PaPInAddr(phe^.h_addr_list);  
  I    := 0
  while pPtr^[I] <> nil do  
  begin  
    Result.Add(inet_ntoa(pptr^[I]^)); 
    Inc(I);  
  end;  
  WSACleanup; 
end;  




procedure ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
var s : String;

   begin
//
   s := Socket.ReceiveText;
   form1.Memo1.Lines.add(s);

   end;

procedure ServerSocket1Read(Sender: TObject; 
  Socket: TCustomWinSocket);
var s : String;

   begin
//   
   s := Socket.ReceiveText;
   form1.Memo1.Lines.add(s);

   end;


procedure TForm1.Button1Click(Sender: TObject);
begin 
   if (Form1.Caption = 'Client'then
   begin

   Clientsocket1.Socket.Sendtext(form1.Edit3.Text + ': ' + form1.Edit1.Text);
   form1.Memo1.Lines.add(form1.Edit3.Text + ': ' + form1.Edit1.Text);
   form1.Edit1.Text := '';

   if form1.Edit1.Text = '' then
   begin
   form1.Edit1.Text := '';
   end;
   end;

   if (Form1.Caption = 'Server'then
   begin

   ServerSocket1.Socket.Connections[0].SendText(form1.Edit3.Text + ': ' + form1.Edit1.Text);
   form1.Memo1.Lines.add(form1.Edit3.Text + ': ' +form1.Edit1.Text);
   form1.Edit1.Text := '';
   if form1.Edit1.Text = '' then
   begin
   form1.Edit1.Text := '';
   end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 //
 clientsocket1:=tclientsocket.Create(self);
 clientsocket1.port:=50;
 //
 ClientSocket1.Address := form1.Edit2.Text;
   ClientSocket1.Active := true;
   Form1.Caption := 'Client';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 //
 serversocket1:=tserversocket.Create(self);
 serversocket1.port:=50;
 //
      Serversocket1.Active := true;
   Form1.Caption := 'Server';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Memo2.Lines := GetIps;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
serversocket1.free;
clientsocket1.free;
end;

end.


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 29.10.03 00:32 
ich weiß schon wo der fehler liegt:

vorher muss ich folgendes initialisieren:
ausblenden Delphi-Quelltext
1:
2:
clientsocket1.OnRead:=clientsocket1read(Sender,tcustomwinsocket);
serversocket1.OnRead:=serversocket1read(Sender,tcustomwinsocket);

mein problem: welchen parameter muss ich bei tcustomwinsocket angeben, damit ich die proceduren clientsocket1read und serversocket1read aufrufen kann?

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.