Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-11

Should using frames result in duplicate name errors?

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Frank Church

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.

  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.

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?

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).

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101117/a993bfce/attachment.html>

Reply by email

Mattias Gaertner
to Frank Church
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.

Show quoted text 11 lines
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';
Show quoted text 12 lines
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

Reply by email

Frank Church
to Mattias Gaertner
Mattias Gaertner wrote 58 lines
On Wed, 17 Nov 2010 17:45:01 +0000 Frank Church 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'?

Because it is the same frame being created from the IDE palette, is it possible to have the child elements in the frame, having the same name, so that at runtime if the parent frames have names such as Parent1, Parent2, Parent3 it possible to write such code as Parent1.Label1.Caption, Parent2.Label1.Caption etc , ie can Lazarus allow child elements to have duplicate names at runtime so long as the parents have different names?

I want to attach events to the child elements, but it seems I can only do it runtime with the Application owning the objects, rather than the form, which is why I am asking whether templates are better for this, rather than frames.

Mattias

Show quoted text 7 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101117/5d216e6f/attachment.html>

Reply by email

Steve Smith

On Wed, 17 Nov 2010 17:45:01 +0000 Frank Church
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.

How can Lazarus do it? You are entering code directly. If you use the IDE
to add frames, Lazarus will do it for you. If you wish to do it in code
CORRECTLY, do the following.

  embFrame1 := TEmbBoothFrame.Create(self);
  embFrame1.Name := 'embBoothFrame1';
  embFrame1.Parent := Panel10;
  embFrame1.lblDestination.Caption := 'XXXXX';
  embFrame2 := TEmbBoothFrame.Create(self);
  embFrame2.Name := 'embBoothFrame2';
  embFrame2.Parent := Panel11;
  embFrame2.lblDestination.Caption := 'YYYYY';

Alternatively, you can add code in the TEmbBoothFrame constructor yourself
to build unique names.

There is a routine somewhere to generate a unique name but I can't be bothered to search for it.

Reply by email

Marc Weustink
to Steve Smith
Steve Smith wrote 29 lines
On Wed, 17 Nov 2010 17:45:01 +0000 Frank Church 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. How can Lazarus do it? You are entering code directly. If you use the IDE to add frames, Lazarus will do it for you. If you wish to do it in code CORRECTLY, do the following. embFrame1 := TEmbBoothFrame.Create(self); embFrame1.Name := 'embBoothFrame1'; embFrame1.Parent := Panel10; embFrame1.lblDestination.Caption := 'XXXXX'; embFrame2 := TEmbBoothFrame.Create(self); embFrame2.Name := 'embBoothFrame2'; embFrame2.Parent := Panel11; embFrame2.lblDestination.Caption := 'YYYYY'; Alternatively, you can add code in the TEmbBoothFrame constructor yourself to build unique names. There is a routine somewhere to generate a unique name but I can't be bothered to search for it.

BTW, if you onlt create components in code, you don't have to give it a name.

Marc

Reply by email

Frank Church
to Marc Weustink
Marc Weustink wrote 53 lines
Steve Smith wrote: > On Wed, 17 Nov 2010 17:45:01 +0000 Frank Church > 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. >> > > How can Lazarus do it? You are entering code directly. If you use the IDE > to add frames, Lazarus will do it for you. If you wish to do it in code > CORRECTLY, do the following. > > embFrame1 := TEmbBoothFrame.Create(self); > embFrame1.Name := 'embBoothFrame1'; > embFrame1.Parent := Panel10; > embFrame1.lblDestination.Caption := 'XXXXX'; > > embFrame2 := TEmbBoothFrame.Create(self); > embFrame2.Name := 'embBoothFrame2'; > embFrame2.Parent := Panel11; > embFrame2.lblDestination.Caption := 'YYYYY'; > > Alternatively, you can add code in the TEmbBoothFrame constructor yourself > to build unique names. > > There is a routine somewhere to generate a unique name but I can't be > bothered to search for it. > BTW, if you onlt create components in code, you don't have to give it a name. Marc -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Templates were what I had in mind initially,
http://delphi.about.com/library/howto/htcomptemplate.htm, but I can't find them in the IDE (Lazarus 0.9.28.3),
Are they available in Lazarus.

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101118/34a8087f/attachment-0001.html>

Reply by email

Frank Church
to Frank Church: Because it is the same frame being created from the IDE palette, is it possible to have…
Frank Church wrote 77 lines
On 17 November 2010 19:28, Mattias Gaertner wrote: > On Wed, 17 Nov 2010 17:45:01 +0000 > Frank Church 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'? > > Because it is the same frame being created from the IDE palette, is it possible to have the child elements in the frame, having the same name, so that at runtime if the parent frames have names such as Parent1, Parent2, Parent3 it possible to write such code as Parent1.Label1.Caption, Parent2.Label1.Caption etc , ie can Lazarus allow child elements to have duplicate names at runtime so long as the parents have different names? I want to attach events to the child elements, but it seems I can only do it runtime with the Application owning the objects, rather than the form, which is why I am asking whether templates are better for this, rather than frames.

Templates were what I had in mind initially,
http://delphi.about.com/library/howto/htcomptemplate.htm, but I can't find them in the IDE (Lazarus 0.9.28.3),
Are they available in Lazarus?

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101118/3e2a43cd/attachment.html>

Reply by email