String or Variant as ItemData

The place for threads about TimoSoft ComboListBoxControls
Post Reply
User avatar
Mex
Captain
Posts: 129
Joined: 24 Sep 2009, 19:47

String or Variant as ItemData

Post by Mex » 01 Nov 2009, 14:39

Hi Timo!

Thnx for the UniCombo :)

Is it possible to use string as ItemData or in the future maby add class or object as ComboItem, like in .NET?


BR;
Meelis

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: String or Variant as ItemData

Post by TiKu » 02 Nov 2009, 16:49

Hi,

using Strings as ItemData is possible using two helper functions. If I have time tonight and if find the sourcecode in my mail archive, I'll post both functions tonight.
The baseline is to allocate memory for the string and store the address as ItemData. When you need the string, read it from this address. And don't forget to free the memory when removing the item (use the FreeItemData event).
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: String or Variant as ItemData

Post by TiKu » 03 Nov 2009, 19:54

I've finally found the functions. They are for usage with the TabStrip control, but all you have to do to use it with ComboBox is change some data types.

Code: Select all

Private Function GetTabTag(ByVal tsTab As TabStripCtlLibUCtl.TabStripTab) As String
  Dim pMem As Long
  Dim s As String
  Dim sz As Long
 
  If Not (tsTab Is Nothing) Then
    pMem = tsTab.TabData
    If pMem Then
      CopyMemoryNew VarPtr(sz), pMem, 4
      s = String$(sz / 2, Chr$(0))
      CopyMemoryNew StrPtr(s), pMem + 4, sz
    End If
  End If
  GetTabTag = s
End Function
 
 
Private Sub FreeTabTag(ByVal tsTab As TabStripCtlLibUCtl.TabStripTab)
  If Not (tsTab Is Nothing) Then
    If tsTab.TabData <> 0 Then
      HeapFree GetProcessHeap(), 0, tsTab.TabData
      tsTab.TabData = 0
    End If
  End If
End Sub
 
Private Sub SetTabTag(ByVal tsTab As TabStripCtlLibUCtl.TabStripTab, ByVal Tag As String)
  Const HEAP_ZERO_MEMORY = &H8
  Dim pMem As Long
  Dim sz As Long
 
  If Not (tsTab Is Nothing) Then
    If tsTab.TabData <> 0 Then FreeTabTag tsTab
 
    sz = LenB(Tag)
    pMem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz + 4)
    If pMem Then
      CopyMemoryNew pMem, VarPtr(sz), 4
      CopyMemoryNew pMem + 4, StrPtr(Tag), sz
      tsTab.TabData = pMem
    End If
  End If
End Sub
 
Private Sub TabStrip1_FreeTabData(ByVal tsTab As TabStripCtlLibUCtl.ITabStripTab)
  If Not tsTab Is Nothing Then
    FreeTabTag tsTab
  End If
End Sub
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

Post Reply