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

Frank Church vfclists at gmail.com
Thu Nov 18 11:03:39 CET 2010


On 17 November 2010 20:22, Frank Church <vfclists at gmail.com> wrote:

>
>
> On 17 November 2010 19:28, Mattias Gaertner <nc-gaertnma at netcologne.de>wrote:
>
>> 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'?
>>
>>
> 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-ide.org/pipermail/lazarus/attachments/20101118/3e2a43cd/attachment-0003.html>


More information about the Lazarus mailing list