PDA

View Full Version : Indy in Delphi


goldfish
03-19-03, 13:31
Hey, ive just got Indy for Delphi 7, dunno if anyone else has that?


Well, basically im playing around with the ICMP object, and some pings. Here is some example code that ive been given:

procedure TForm1.ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
var
sTime: string;
begin
if (ReplyStatus.TimeToLive = 0) then
sTime := '<1'
else
sTime := '=';
Memo1.Lines.Add(Format('%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms',
[ReplyStatus.BytesReceived,
ReplyStatus.FromIpAddress,
ReplyStatus.SequenceId,
ReplyStatus.TimeToLive,
sTime,
ReplyStatus.MsRoundTripTime]));
end;

So i have a memo box called Memo1 and every time it recives somthing it adds a line to it. What i want to do is ONLY ADD when the ttl is more than 0. (so basically i want it to tell me when there is somthing on the end. or not)

How could i do this?

iamien
03-19-03, 17:14
you have Stime as a local variable. change it to global and use an if statement to check if it equals <1 or =

goldfish
03-21-03, 16:24
BLOODY HELLLLL!!!!!!!!!!!!!!
EEEEEDDEEDDDEDEEEEE!!!!!!!

WHYYYYY...........sorry.......why.


procedure TForm1.ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
var
FromIPAddress : string;
begin
FromIPAddress := ReplyStatus.FromIpAddress;
ShowMessage(FromIPAddress);
if (FromIPAddress <> '0.0.0.0') then
Memo1.Lines.Add(Format('%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms',
[ReplyStatus.BytesReceived,
ReplyStatus.FromIpAddress,
ReplyStatus.SequenceId,
ReplyStatus.TimeToLive,
sTime,
ReplyStatus.MsRoundTripTime]))
else
ShowMessage('Not there');
end;
end.

Right now see anything wrong there? i do. there is no end; at the end of the procedure. But if i correct it, delphi says its wrong? It was expecting end. not end; why? is it not usual to put an end at the end of a if/then branch?

ooh, wait a sec, just had a brainwave!

goldfish
03-21-03, 16:25
to have end; you need begin!

HAHA! i beat you again delphi!

iamien
04-03-03, 00:00
'%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms' that looks like C :D ooh i can't wait to start on Indy