John Barrat wrote:
> OK Thsnks for your help, I can now add the frames at runtime
> I am adding them in the formShow event at the moment just for testing.
>
> I still can't access the frame's sub components.
> As you can see I am setting the subcomponents true.
> How do I access these properties from my main form?
>
> In my main form show event I load up 8 instances of the frame:
>
> procedure TfmFuseConfig.FormShow(Sender: TObject);
> Var i: Integer;
> begin
> for i := 0 to 7 do
>   AddFuseItem(i);
> end;
>
> procedure TfmFuseConfig.AddFuseItem(pIndex: Integer);
> begin
> FuseList := TFrmFuse.Create(Self);
> with FuseList do
>   begin
>     Parent := Self;
>     Visible := True;
>     Align := alTop;
>     Name := 'FuseNo' + IntToStr(pIndex);
>   end;
> end;
>
> This leaves me with 8 frames visible on my form, I assume with Names of
> FuseNo0 throught to FuseNo7.
> How do I access these frames and their sub components?

Right now, you're storing a reference to each new frame in some variable
named FuseList. At the end of your loop, that will contain only a
reference to the last frame you created. If you want to keep references to
all of them, use an array or a list.

Otherwise, you can only access them indirectly. You can use the form's
FindComponent function to find something by name, or you can iterate over
the Components or Controls arrays searching for whatever frame you're
looking for.

> I have tried
> populating their properties in the AddFuseItem procedure but I just get a
> syntax error saying undeclared identifier.
>
> E.g.
>
> procedure TfmFuseConfig.AddFuseItem(pIndex: Integer);
> begin
> FuseList := TFrmFuse.Create(Self);

Does that line actually compile? Mark declared FuseList as a TList, not
any superclass of TFrmFuse. What is FuseList in your code?

> with FuseList do
>   begin
>     Parent := Self;
>     Visible := True;
>     Align := alTop;
>     Name := 'FuseNo' + IntToStr(pIndex);
>     ItemDesc.Caption := Name;// this line errors......
>   end;
> end;

Remove the "with" block. Write everything out. Does the error still occur
on the same line?

> This is the source for the
> frame...........................................
> unit PICFuseItem;
>
> interface
>
> uses
>   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
> Forms,
>
>   Dialogs, StdCtrls, ExtCtrls;
>
> type
>   TfrmFuse = class(TFrame)
>     pnlFuseEntry: TPanel;
>     cmbValue: TComboBox;
>     pnlName: TPanel;
>     pnlDescription: TPanel;
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>     Constructor Create(AOwner: TComponent);

Surely that's supposed to be marked as "override."

>     property ItemName: TPanel Read pnlName Write pnlName;
>     property ItemValues: TComboBox Read cmbValue Write cmbValue;
>     property ItemDesc: TPanel Read pnlDescription Write pnlDescription;

Those properties are simply providing alias names for the component
fields. The fields are already published. You don't need to access the
components via the properties since anyone can access them via the fields
already.

-- 
Rob


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to