Witam.
Napisałem prosty program będący jednocześnie klientem i serwerem. Służy on do połaczenia TCP/IP. Na formie mam
1xlabel, 1xbutton, 1xgroupbox, 1xmemo, 1xedit1, TidTCPClient i TidTCPServer.
Źródło wygląda tak:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdCustomTCPServer, IdTCPServer, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdIOHandler, IdIOHandlerSocket;
type
TForm1 = class(TForm)
Client: TIdTCPClient;
Server: TIdTCPServer;
Edit1: TEdit;
Label1: TLabel;
GroupBox1: TGroupBox;
Memo1: TMemo;
Button1: TButton;
procedure ClientConnected(Sender: TObject);
procedure ClientDisconnected(Sender: TObject);
procedure ServerConnect(AContext: TIdContext);
procedure ServerDisconnect(AContext: TIdContext);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ClientConnected(Sender: TObject);
begin
Memo1.Lines.Add('Connected');
end;
procedure TForm1.ClientDisconnected(Sender: TObject);
begin
Memo1.Lines.Add('Disconnected');
end;
procedure TForm1.ServerConnect(AContext: TIdContext);
begin
Memo1.Lines.Add('Client connected');
end;
procedure TForm1.ServerDisconnect(AContext: TIdContext);
begin
Memo1.Lines.Add('Client disconnected');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Client.Connected then
begin
Client.Disconnect;
Button1.Caption:= 'Connect';
end else
begin
Server.Active:=False;
Client.Host:=Edit1.text;
Client.Connect;
Button1.Caption:='Disconnect';
end;
end;
end.
Było to pisane na podstawie książki "Delphi 7. Ćwiczenia zaawansowane"
Wszystko byłoby ok, gdyby nie fakt, że w linijce
procedure ServerConnect(AContext: TIdContext);
krzyczy mi o błąd:
[Error] Unit1.pas(21): Undeclared identifier: 'TIdContext'
Podobnie sprawy się mają, gdy napisałem program podobny do poprzedniego tylko na komponentach TidIRC Client i Server. Tylko że wtedy w linijce z poleceniem
procedure IdIRCServer1TIdCommandHandler0Command(ASender: TIdCommand);
wyskakuje mi błąd
[Error] Unit1.pas(28): Undeclared identifier: 'TIdCommand'
O co chodzi? Czy brakuje mi czegoś w sekcji Uses?
Pozdrawiam,
bht