For Programmers: Free Programming Magazines  


Home > Archive > Delphi > February 2005 > looping object code question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author looping object code question
rob williams

2005-01-31, 8:59 pm

Hi there,

could do with some help with this code, new to delphi, but i've managed to make what i want actually work so far. However, i'm uncertain how to do this 'properly' and make it flexible enough to loop a different amount of times.

The code below has to be run X times and refer to the next object each time:

HostToSend:=MainForm.host1.text;
PortToSend:=strtoint(MainForm.port1.text);
InitiateCheckofhost(HostToSend, PortToSend);
If ResultCheckbox then MainForm.CheckBoxHost1.state:=cbchecked
else MainForm.CheckBoxHost1.state:=cbunchecked;
MainForm.ProgressBar1.max:= TimeOutTime;
MainForm.ProgressBar1.Position:= Delay;
CompletionGauge.Progress:=CompletionGauge.Progress+1;
ResultCheckBox:=false;
Delay:=0;

so the next one would be:

HostToSend:=MainForm.host2.text;
PortToSend:=strtoint(MainForm.port2.text);
InitiateCheckofhost(HostToSend, PortToSend);
If ResultCheckbox then MainForm.CheckBoxHost2.state:=cbchecked
else MainForm.CheckBoxHost2.state:=cbunchecked;
MainForm.ProgressBar2.max:= TimeOutTime;
MainForm.ProgressBar2.Position:= Delay;
CompletionGauge.Progress:=CompletionGauge.Progress+1;
ResultCheckBox:=false;
Delay:=0;

and so on, probably about 80 times - but i have no idea how to handle objects to do this!

can somebody point me in the right direction? or to the correct group if this is the wrong place :)

many thanks,

- - rob williams - -
J West

2005-02-05, 4:00 pm

Hi!
There are many way's to do this here is just one and I'm sure others will have alternative suggestions!
A form has a controls property which lists all the descendants of TControl

Hee is the example taken straight from the Delphi help on TForm.ControlCount

var

I: Integer;
Temp: TComponent;
begin
for I := ComponentCount - 1 downto 0 do
begin
Temp := Components[I];
if not (Temp is TControl) then
begin
RemoveComponent(Temp);
DataModule2.InsertComponent(Temp);
end;
end;

end;

You should be able to easily substitute TComponent for the type of control you are using! Hope this helps!

Regards

James West
"rob williams" <rob@rob-w.com> wrote in message news:Y6yLd.34889$v8.3846@fe2.news.blueyonder.co.uk...
Hi there,

could do with some help with this code, new to delphi, but i've managed to make what i want actually work so far. However, i'm uncertain how to do this 'properly' and make it flexible enough to loop a different amount of times.

The code below has to be run X times and refer to the next object each time:

HostToSend:=MainForm.host1.text;
PortToSend:=strtoint(MainForm.port1.text);
InitiateCheckofhost(HostToSend, PortToSend);
If ResultCheckbox then MainForm.CheckBoxHost1.state:=cbchecked
else MainForm.CheckBoxHost1.state:=cbunchecked;
MainForm.ProgressBar1.max:= TimeOutTime;
MainForm.ProgressBar1.Position:= Delay;
CompletionGauge.Progress:=CompletionGauge.Progress+1;
ResultCheckBox:=false;
Delay:=0;

so the next one would be:

HostToSend:=MainForm.host2.text;
PortToSend:=strtoint(MainForm.port2.text);
InitiateCheckofhost(HostToSend, PortToSend);
If ResultCheckbox then MainForm.CheckBoxHost2.state:=cbchecked
else MainForm.CheckBoxHost2.state:=cbunchecked;
MainForm.ProgressBar2.max:= TimeOutTime;
MainForm.ProgressBar2.Position:= Delay;
CompletionGauge.Progress:=CompletionGauge.Progress+1;
ResultCheckBox:=false;
Delay:=0;

and so on, probably about 80 times - but i have no idea how to handle objects to do this!

can somebody point me in the right direction? or to the correct group if this is the wrong place :)

many thanks,

- - rob williams - -
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com