Dovendo adattare questo pezzo di codice ad un Form:
L'ho compilato in questo modo. Ho usato due bottoni uno per la connessione e l'altro per ottenere i dati:
Quando premo il pulsante di connessione procede bene ma quando premo info mi restituisce una finestra con questo errore:
Access violation at address 004cb7c2
allego file completo
Codice:
var
client: TIdTCPClient;
begin
client := TIdTCPClient.Create;
client.Port := 2630;
client.Host := '127.0.0.1';
client.ReadTimeout := 10000;
Writeln('Starting client...');
while True do
begin
try
if not client.Connected then
begin
client.Connect;
Writeln('Connected!');
SendHello(client.IOHandler);
end;
while client.Connected do
if not HandleResponse(client.IOHandler) then
break;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end;
Writeln('Closing');
end.
Codice:
procedure TForm1.Button1Click(Sender: TObject);
var
client: TIdTCPClient;
begin
client := TIdTCPClient.Create;
client.Port := 2630;
client.Host := '127.0.0.1';
client.ReadTimeout := 10000;
client.Connect;
Label1.Caption := 'Connesso'
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendHello(client.IOHandler);
end;
Quando premo il pulsante di connessione procede bene ma quando premo info mi restituisce una finestra con questo errore:
Access violation at address 004cb7c2
allego file completo