Reference a control by name OR static id#

Started by David Maruca, March 27, 2011, 02:24:13 PM

Previous topic - Next topic

David Maruca

I'm in the process of converting some of my VB classes to PB and ran into this wall with FF3. Long story short is that I need to be able to reference a control by either its name or id# at runtime without using the idc constants. I'm talking about the IDC_FORM1_Control constant that is generated.

Let me illustrate. I made a data map class that will automatically map a control on a form to a data set. All I have to do during design is to drop a control onto a form, give it a name, and add an entry for that control to a table. The table maps the control name or id to a recordset column and defines its behavior. This table is fed at runtime to a custom class that will handle everything else such as dirty/corrupt events, saving/loading, best practices, and so on. It really speeds up my development tremendously for VB, so I would love to get this into PB.

So, I notice that there is no provided method to lookup a control by name during runtime. I'm fine to use ID#'s, but how can I know the number FF will assign to the control? I could make a workaround like this:
Function GetControl(Name as string) as Long
    Select Case Name
    ...
End Function


but that could get cumbersome for larger forms. Does anyone here have a better way?

Haakon Birkeland

Not reading to detailed into your post, I might not really answer your question, but all controls are assigned equates listed in the handle & ID dialog (F4).
Haakon 8o)

David Maruca

at runtime without using the idc constants

Paul Squires

I don't know 100% what it is you are doing, but if you know the Windows Handle of the control then you can get the ID via the GetDlgCtrlID api function:

http://msdn.microsoft.com/en-us/library/ms645478(v=vs.85).aspx

Paul Squires
PlanetSquires Software

David Maruca

All that I'm asking is there a way to list the id's of the controls inside firefly at design time? I know that I can hit F4 to get a list of constants, but that does me no good in this case as I need to store the number and I don't see it anywhere in the IDE. I'm sorry if my attempt to describe what I was doing added to confusion.

For instance if I were to create a dialog without using FF3, I would start out by listing all of my controls like so..

%Textbox_01_id = 1000
%Textbox_02_id = 1002
%Textbox_03_id = 1004

Michael Shillito

Look in the  Sub     'FLY_InitializeVariables()'     in the .bas file in the release folder of your project

Paul Squires

hmmm, that's a tough one - the numeric id's are not actually created until the code is generated for the Form. Therefore, at design time, the only thing that is known for sure is the symbolic equate for the control id (IDC_FORM1_TEXTBOX1, etc...). When you generate the sour code, then FF3 will output the list of equates and assign values to them (like Michael says, check out the FLY_InitializeVariables function - it contains the values).

Thinking to myself, I can't see a workaround for knowing the actual id number at design time prior to compiling.
Paul Squires
PlanetSquires Software

Ian Vincent

This is a particularly interesting discussion for me.

Occasionally I have issues when adding a option button to a control array.
Everything looks normal, but my code doesn't work as I expect.
When I look at  'FLY_InitializeVariables()' I see this has happened:
    IDC_OFFSETS_OPTION1(3) = 1004
    IDC_OFFSETS_OPTION1(0) = 1005
    IDC_OFFSETS_OPTION1(1) = 1006
    IDC_OFFSETS_OPTION1(2) = 1007

Note that index 3 has the lowest number control ID

This means that the following line won't work as expected:
FF_Control_SetOption( hWndForm, IDC_OFFSETS_OPTION1(0), IDC_OFFSETS_OPTION1(3), IDC_OFFSETS_OPTION1(n) )
and needs to be changed to
FF_Control_SetOption( hWndForm, IDC_OFFSETS_OPTION1(3), IDC_OFFSETS_OPTION1(2), IDC_OFFSETS_OPTION1(n) )

This of course only applies to Option Buttons and only when using control arrays. But I really like control arrays!
Not a big problem when you are aware of it, but it would be nice to be able to easily view control IDs.
( I haven't reported this as it is impossible to create a scenario where it can be reproduced reliably. For me it
happens after working on a program for some time, and then going back and finding I need an extra option. When it
is added, I see the problem, but only sometimes)

Whilst on the subject of adding controls though, a quick new feature suggestion:
How about when pasting controls, the user is given the option of how many they want and if they
want them accross or down. Especially with things like Options and Check boxes, I find I want to
paste 6 or 8 or more, and it would be nice to avoid the question box that pops up each time.



Paul Squires

Hi Ian,

I do remember a numbering problem with Option Buttons a while back. It had to do with control arrays and the "Index" property. When you copy/paste the controls you have to ensure that you also set the Index property correctly otherwise the control id numbering will be screwed up. I can't remember when this was fixed because I do not have access to my bug tracker at the moment.
Paul Squires
PlanetSquires Software

David Maruca

Thanks for the reply. I can use the values in FLY_InitializeVariables. I do notice they change when controls are added/removed (new controls are added to the top and bump everything down in my few tests). This gives me something to think about.

Ian Vincent

Thanks Paul.

I think I set the indexes correctly at the time, but it is something that happens so rarely that it is difficult to
reproduce.

Anyway, it's not really a big issue, and easily gotten around.