[Gambas-user] Dynamic Objects

Rodney Rundstrom iecltd at ...2113...
Tue Mar 31 05:27:03 CEST 2009


Thanks using last.text works in this case, can you clarify how I would
access using parent/child can a form itself be the container or my I use
another although a similar arrangement is available in VB I am not really
sure how to use it?

Thanks once again

Rodney

-----Original Message-----
From: Doriano Blengino [mailto:doriano.blengino at ...1909...] 
Sent: Monday, 30 March 2009 9:52 p.m.
To: mailing list for gambas users
Subject: Re: [Gambas-user] Dynamic Objects

Rodney Rundstrom ha scritto:
> Thanks to some of the member I can now create objects dynamically.
>
> If I create a number of buttons I can position and label them differently.
I
> can also name them differently
>
> However I can have a number of objects with the same name on a form?
>
> I can access an event say click on any of the button but cannot write to a
> property of individual labels even using its created name
>
> being told it is not static.
>   
When you create controls at design time, those controls obtain a field 
(or slot) in the compiled code; ie, they have a true name because they 
become members of the class you are creating - both the Name property of 
the control, and a variable named the same, are retained.

When you create controls at run time, the class is already formed (it 
contains all the controls created at design time, but nothing else). So, 
they don't have a name in the class, and you can't access them that way. 
A control created in this way may or may not have a name assigned to its 
Name property - it is used for other purposes.

But you can still access them by saving/keeping the variable you used to 
instanciate them, either as a global one, a class member one (public or 
private), or inside an array, or whatever:

    private lMyLabel as Label

    lMyLabel = new Label(fmMain) as "another"

in this case, "another" is the name used for event management, but the 
real handle of the label will be "lMyLabel", and you can access 
"lMyLabel.text" in the usual way. But if lMylabel was DIMed as a local 
variable in a subroutine, then its handle gets lost after the subroutine 
terminates.

You can access controls in two ways, even if their handle is lost. The 
first is using "LAST" pseudo-variable in a event handler; the second is 
to use the Children property of a container control.

Regards,
Doriano Blengino


----------------------------------------------------------------------------
--
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list