I'm using Delphi 5 and I'm creating a number of panels at runtime, then creating buttons on the panels, obviously again at runtime. I need to do it this way because I may need to dynamically create more panel/button combinations in the future.
I can do all of this, but I'm at a loss as to how to reference the panels I've created, because I can't find a way to access the panels' component name. Hunting around the Internet I've found that I can use FindComponent to find the panel components by name, but I still don't know how to use that name, because I can't use a string variable to refer to it - e.g. StringVar := Panel.Name. I get a type mismatch, TComponentName versus String.
I created the buttons for each panel as I created the panels. Simplified, it looks like this:
With TypeQuery do begin // Create Panels
First;
While (not eof) do begin // create the actual panel
panelno := FieldByName('Product_type_id').AsInteger;
pnl := Tpanel.Create(Self);
pnl.name := FieldByName('PanelName').AsString;
pnl.color := clInactiveCaption;
pnl.parent := MainForm;
pnl.width := 365;
pnl.Height := 551;
pnl.left := 434
pnl.top := 122;
pnl.caption := '';
With ButtonQuery do begin
Close;
Parameters.parambyname('PanelID').Value := PanelNo;
Open;
First;
While (not eof) and (FieldByName('Product_type_id').AsInteger = PanelNo) do begin //put the buttons on it.
btnName := FieldByName('ButtonName').AsString;
BtnText := FieldByName('ButtonText').AsString;
BtnGroup := FieldByName('Product_Group_ID').AsString;
GrpColour := FieldByName('ButtonColour').AsString;
btn := TColorButton.Create(Self);
btn.Parent := pnl;
btn.Name := BtnName;
Btn.backcolor := HexToTColor(GrpColour);
btn.Font.Name := 'Arial Narrow';
btn.Font.Style := [fsBold];
btn.Font.Size := 10;
. . .
end;
. . .
end;
end;
I've read on several forums (including this one) that there is no way to reference the panels by name directly. I've tried using a component array, but I strike the same problem - I need to refer to the component by its assigned component name.
Okay, I'm not a gun programmer - I've used Delphi for years to create simple programs, but this one is a lot more complex. I've never worked with runtime component creation before.
Can I use FindComponent to make the panels visible or invisible? If so, given what I have shown you above, can you give me the approach I should take in baby-steps?
Thanks in advance ...