I'm having trouble getting data from a user-defined type into a My Little Grid control.
I have verified that the user-defined type is populated with correct data. All members in the UDT are strings, so that shouldn't be an issue. I can even populate a listview no problem with this data.
When I try assigning these values to cells in a MLG control, I keep getting an "Error 480: PARAMETER MISMATCHES DEFINITION".
Setting hard-coded test works fine:
MLG_Put HWND_MLGCONTROL, 1, 1, "testvalue1", 0
MLG_Put HWND_MLGCONTROL, 1, 2, "testvalue2", 0
MLG_Put HWND_MLGCONTROL, 1, 3, "testvalue3", 0
But setting values from a UDT does not work:
MLG_Put HWND_MLGCONTROL, 1, 1, MyUDT.Value1, 0
MLG_Put HWND_MLGCONTROL, 1, 2, MyUDT.Value2, 0
MLG_Put HWND_MLGCONTROL, 1, 3, MyUDT.Value3, 0
My UDT is defined similarly as follows:
Type MyUDT
Value1 AS String * 5
Value2 AS String * 10
Value3 AS String * 1
End Type
Displaying MyUDT.Value1 in a MsgBox immediately before the first MLG_Put displays data, so I know it's there.
Am I missing something obvious??
Not sure if Jim will see your message here but in case he does not, you should send any MLG support questions directly to James Klutho at mlg@planetsquires.com
Thanks -- I'll try e-mailing James!
Try:
MLG_Put HWND_MLGCONTROL, 1, 1, TRIM$(MyUDT.Value1, chr$(0,32)), 0
Maybe the engine is not made for null characters.
Thanks Elias... that seemed to work. Seems a bit messy having to do that for each MLG_Put, but it gets the job done!
I wonder if the problem is that you are sending a fixed length string to a parameter that expects to be a dynamic string?
Maybe try something like;
MLG_Put HWND_MLGCONTROL, 1, 1, ByCopy MyUDT.Value1, 0
Thanks -- ByCopy works too! It never would have crossed my mind to use that.
Just to finalize this -- Mr. Klutho kindly responded to my e-mail, and simply suggested wrapping the UDT string value with Trim$(). Worked!
Many ways to do this apparently. Thanks to all!
If you don't want to trim then you could change your udt to be asciiz.
Type MyUDT
Value1 AS Asciiz * 5
Value2 AS Asciiz * 10
Value3 AS Asciiz * 1
End Type
A UDT with fix length strings, or array of them, is to be fast. Adding code to automatically "Trim" or what ever one would want to do would add a lot of overhead when it might not be needed.
If you think about it, it would be difficult to impossible to tell when to add this code. For example, if you use Array Sort should it be added and how.
To get what you want, you could use an class/object. An object can have a dynamically sized string.
Code not tested
Class myClass
instance m_sName as string
interface myClassInterface
property get Name() as string
property = m_sName
end property
end interface
end class
A collection class would allow you to have multiple. In the end this might be more work to load into the grid, but it also may allow more flexibility.
It would be even better if dynamic strings where allowed in UDT's, but they are not and I fought and lost that new feature suggestion many moons ago in the PB forum (some people just can't get past the "UDT's must be fixed length" argument).
Likewise, dynamic arrays in UDT's would be a great addition. These days, it is probably just as easy to convert your code to use classes rather than play with manually allocating/deallocating dynamic strings in UDT's (like I am doing in all my code).