Still feeling a bit green in RB to participate in discussions (for
the time being I prefer learning by lurking) like this but what is
wrong with this?
on Windowlevel create a Dictionary ControlDict
In the windows open event
Dim i as Integer
ControlDict = new Dictionary
For i = 0 to Self.ControlCount-1
ControlDict.Value(Self.control(i).name) = Self.control(i)
Next
you can modify this in order to store more info about the control
into the Dict like this
Dim i as integer
ControlDict = new Dictionary
For i = 0 to Self.ControlCount-1
Dim aDict as new Dictionary
Select Case True
case Self.control(i) isa Editfield
aDict.Value("controlType") = "Editfield"
case ......
end Select
aDict.Value("control") = Self.Control(i)
ControlDict.Value(Self.control(i).name) = aDict
Next
From now on I can retrieve any control by name
(using example 1)
Dim aControl as Editfield
aControl = ControlDict.Value("editfield1")
aControl.Text = aControl.name
UNTESTED "mail-code"
just to communicate the idea
I most certainly would like to know what the disadvantages are of
this approach
Bart Pietercil
On 7-mei-07, at 10:47, Dirk Cleenwerck wrote:
> If youn mean from code, the answer is not directly as in you can't say
> editfield("editfield1").text="myeditfieldtext"
>
> My solution is something like this,
>
> dim i As Integer
> Dim controlname As String
> Dim myeditfield As EditField
> for i=1 to 3
> controlname="EditField" + Cstr(i)
> myeditfield=geteditfield(self, controlname) //pass the window that
> contains the control and the name of the control
> if myeditfield<>nil then
> myeditfield.Text=Cstr(i)
> end if
> next i
>
> What this does is fill editfield1 with 1, editfield2 with 2 and
> editfield3 with 3
>
> The function I'm calling is geteditfield and is defined like this
> function geteditfield(mywindow as Window, controlname As String) As
> Editfield
> dim myobject As object
> dim myeditfield As EditField
> myeditfield=nil
> myobject=getcontrol(mywindow, controlname)
> if myobject<>nil and myobject IsA EditField then
> myeditfield=EditField(myobject)
> end if
> return myeditfield
>
> The function use the secondary function getcontrol and looks if the
> control exists and is an editfield
> If so it returns the control casted as an editfield, if not, it
> returns
> nil (there is no editfield with this name on this window)
> The secondary function getcontrol is defined like this
>
> Function getcontrol(mywindow as Window, controlname As String) As
> object
> Dim i As Integer
> Dim oReturn As Object
> oReturn=nil
> if mywindow<>nil then
> for i=0 to mywindow.ControlCount-1
> if mywindow.Control(i).Name=controlname then
> oReturn=mywindow.Control(i)
> exit for
> end if
> next i
> end if
> return oReturn
>
> This loops all the controls on the window and compares the name of the
> control with the name passed to the function
> If a control exists with this name, it return the control as an object
> (to be casted to an editfield in the calling function)
> If it doesn't exist, it returns nil
>
> By splitting the function up in two parts I can easily define
> geteditfield, getpushbutton, getlistbox... and always call the same
> getcontrol code
>
> Hope it helps.
>
> Dirk Cleenwerck
> Chief Programmer
> Useitgroup NV
>
> Giovanni schreef:
>> Is there a list of the controls i can see what controls are on the
>> form
>> while on the IDE?
>>
>> thanks,
>>
>> giovanni
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>