[Lazarus] Should using frames result in duplicate name errors?

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Nov 17 20:28:59 CET 2010


On Wed, 17 Nov 2010 17:45:01 +0000
Frank Church <vfclists at gmail.com> wrote:

> I am trying to use frames to create the same element repeatedly on a form,
> but when I copy them in the IDE or create them and set their parents at
> runtime, I get duplicate name errors. Isn't Lazarus supposed to give them
> different names.

No.
The name is needed for reference.

 
>   embFrame1 := TEmbBoothFrame.Create(self);
>   embFrame1.Parent := Panel10;
>   embFrame1.lblDestination.Caption := 'XXXXX';
> 
>   embFrame2 := TEmbBoothFrame.Create(self);
>   embFrame2.Parent := Panel11;
>   embFrame2.lblDestination.Caption := 'YYYYY';
> 
> The above code generates the error:
> 
> Duplicate name: A component named EmbBoothFrame already exists.

You can set a new name or set it to the empty name:
   embFrame1 := TEmbBoothFrame.Create(self);
   embFrame1.Name:='';
   embFrame1.Parent := Panel11;
   embFrame1.lblDestination.Caption := 'YYYYY';

 
> Is it possible to get it to set a new name at creation time? On closer look
> it looks like the use of self means it is being attached to the form, would Application
> work much better
> 
> ie embFrame1 := TEmbBoothFrame.Create(Application)?
> 
> I tested with Application and it works
> 
> On the other hand it appears that when I add the frames from the IDE, the
> duplicate name issue exists.
> 
> Is it possible to pass the desired name to the Create function in this case?

There is a complicated way. But I doubt you really need that.

 
> Are frames the right thing for this or is it templates instead? But I can't
> find templates in the IDE menu or the palette (Lazarus 0.9.28.3).

What is 'this'?

Mattias




More information about the Lazarus mailing list