Board index » delphi » looping

looping


2003-10-01 04:23:32 PM
delphi204
I have the following procedure that I have attached to the CBL Click of a
panel, how can I make this procedure common so that if I have panel2 panel 3
etc I can use this procedure without changing it to say
roomname:=panel2.Caption;
panel2.Width:=strtoint(edit5.Text);
panel2.Height:=strtoint(edit6.Text);
etc etc
ie instead of panel1.click do panel(x).click
procedure TForm1.Panel1DblClick(Sender: TObject);
var roomname:string;
begin
roomname:=panel1.Caption;
if checkbox1.checked=true then
begin
panel1.Width:=strtoint(edit5.Text);
panel1.Height:=strtoint(edit6.Text);
end
else
begin
if adoconnection1.Connected=true then
begin
fromdate:=datetostr(date1.date);
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add(QUERY TEXT HERE)
adoquery3.Open;
else
end;
end;
Similarly I wat to read and write co-ordinates of the panels
panel1.Left:= readinteger('PANEL','PANEL1left',0);
panel1.top:= readinteger('PANEL','PANEL1top',0);
panel1.Width :=readinteger('PANEL','PANEL1Width',105);
panel1.Height :=readinteger('PANEL','PANEL1Height',40);
How can I make use this to loop through all the panels in question ( I have
50 panels)
thanks in advance
Charlie
 
 

Re:looping

Hi,
You can use the Sender parameter wich is a reference to the sending
component seen as a TObject.
Simply use (Sender as TPanel) to get the sending panel.
Make sure that no other component class may call this proc because it can
result in conversion error.
If you only want to acces to width, height, left and top property, you may
see the sender as the component which introduce these properties : (Sender
as TControl).
Regards,
Florent
"Charlie" <XXXX@XXXXX.COM>a écrit dans le message de
Quote
I have the following procedure that I have attached to the CBL Click of a
panel, how can I make this procedure common so that if I have panel2 panel
3
etc I can use this procedure without changing it to say

roomname:=panel2.Caption;
panel2.Width:=strtoint(edit5.Text);
panel2.Height:=strtoint(edit6.Text);


etc etc

ie instead of panel1.click do panel(x).click

procedure TForm1.Panel1DblClick(Sender: TObject);
var roomname:string;
begin
roomname:=panel1.Caption;
if checkbox1.checked=true then
begin
panel1.Width:=strtoint(edit5.Text);
panel1.Height:=strtoint(edit6.Text);
end
else

begin
if adoconnection1.Connected=true then
begin
fromdate:=datetostr(date1.date);
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add(QUERY TEXT HERE)
adoquery3.Open;
else
end;
end;



Similarly I wat to read and write co-ordinates of the panels

panel1.Left:= readinteger('PANEL','PANEL1left',0);
panel1.top:= readinteger('PANEL','PANEL1top',0);
panel1.Width :=readinteger('PANEL','PANEL1Width',105);
panel1.Height :=readinteger('PANEL','PANEL1Height',40);

How can I make use this to loop through all the panels in question ( I
have
50 panels)

thanks in advance


Charlie