Tag Property

Started by Anonymous, June 11, 2004, 07:53:31 PM

Previous topic - Next topic

Anonymous

One thing I miss a lot from my VB development projects is a tag value for controls on a form, so I guess it would be nice to add this if it were possible.

One place I use tags (string values) is to record information about checkboxes. So if I've got a dozen checkboxes on a form I would use the tag to record a value identifying that particular control. This was particularly useful when recording values in an INI file - you could set the tag to be the key name in the INI file and then iterate thru the controls without having to remember the values.

I appreciate it is possible to use the index number of the control to do this, but a tag property would round this out nicely. There's also the issue of sometimes moving checkboxes around on a form to change the order, and the index sequence might be updated.

Andrew

TechSupport

You can also use the SetProp and GetProp API functions to store a 32-bit value with the control's window handle (i.e. the HWND_ variable).

I believe that the Tag request has come up before. I'll add it to "the list" again.

Anonymous

Paul

Please give me an example how it works SetProp and GetProp?

Thanks
Stephane

Roger Garstang

Paul uses it as a neat way to store control/form information in the generated code:

ff = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, SIZEOF(@ff)) 'Allocate Memory for FF_DATA Structure
IF ff THEN SetProp hWndControl, "FF_PTR", ff  'Store the pointer for later use

Then when he wants to get data from the structure for a certain control:

ff = GetProp(hWndControl, "FF_PTR") ' Get Value of FF_PTR structure pointer that we stored

The "FF_PTR" in the Prop calls is the Name of the value to retrieve from the control, not to be confused with the actual FF_PTR structure that the handle it stores/returns is pointing to.

Think of it as the Dialog Get User and Dialog Set User in PB's DDT...only better.

Note: The documentation says you need to remove the properties you added when the control/form is destroyed (WM_DESTROY), so for this example use: RemoveProp hWndControl, "FF_PTR"

You'd also need to free allocated memory with HeapFree(GetProcessHeap(), 0, BYVAL ff).