Oliver
  • Oliver
  • Advanced Member Topic Starter
2013-11-28T10:17:38Z
Hello 10Tec

Currently, you can only set the properties of the main iGrid.Font-object directly. Any other .Font-object (Header.Font, column-default.oFont, .CellFont) must first be set to a self-created StdFont-object. While this is possible, it would be nice when iGrid would do this by itself. For example by creating the object when the respective Font property is first accessed/written.

Our Grid uses many different styles to display information, so I have to create 5 different StdFont objects, just to use different combinations of Bold, Underline, Italics and Strikethrough.

Regards,
Oliver
Igor/10Tec
2013-11-29T09:59:13Z
Originally Posted by: Oliver 

it would be nice when iGrid would do this by itself. For example by creating the object when the respective Font property is first accessed/written.



Every Font property is a classic object property, i.e. an object of the corresponding type is stored inside. There are techniques how to create it on the fly when we access it, but the question is whether it is a good approach for controls like grid - when we can have tons of cells?

A font object (StdFont) uses much more resources than say an Integer value, and in iGrid we do not create font objects for column headers or cells automatically to save resources. This allows us to save memory and increase performance dramatically.

To tell you even more, iGrid uses special optimization technique to store only different font objects inside! In fact, the used (different!) font objects are stored in an internal array, and every cell stores only the corresponding font index inside. Here is the corresponding snippet from the iGrid source code:

Public Property Get CellFont(ByVal vRow As Variant, ByVal vCol As Variant) As StdFont
   Dim iFntIdx As Long

'***** Checking/converting parameters

   mFontRow = flConvRowCellArray(vRow)
   mFontCol = frlConvCol(vCol)

'***** Main body

   iFntIdx = m_tCells(mFontCol, mFontRow).iFntIndex
   If iFntIdx = 0 Then
      Set mFontCell = FontClone(UserControl.Font)
   Else
      Set mFontCell = FontClone(m_oCellFonts(iFntIdx))
   End If
   Set CellFont = mFontCell
End Property

Public Property Let CellFont(ByVal vRow As Variant, ByVal vCol As Variant, ByVal sFnt As StdFont)
   Dim locRow As Long
   locRow = flConvRow(vRow)
   With m_tCells(frlConvCol(vCol), m_tRows(locRow).lCellArrayRow)
      .iFntIndex = friAddFontIfRequired(sFnt)
      pSetCellDirtyFlag .CellBits1
   End With
   pDrawOnCellXXXXChangeIfRequired locRow
End Property
Oliver
  • Oliver
  • Advanced Member Topic Starter
2013-11-29T11:50:19Z
In VBA, I can define a "Property Get" function that is called when a user accesses that property. Inside that function, you could create a new object and return it on first use. That way you can avoid creating the unnecessary objects.

Imagine this in a Class-Module:


Private m_oFont As StdFont

Public Property Get Font() As StdFont
    If (m_oFont Is Nothing) Then
        Set m_oFont = New StdFont
    End If
    
    Set Font = m_oFont
End Property
Public Property Set Font(Font As StdFont)
    Set m_oFont = Font
End Property

Thinking about it, while this would work, there would be a resource issue when I imagine using this in a 1000 cell-loop. Currently, I can assign the SAME font object to all these cells, while by using my property, 1000 individual Font objects get created.

One could try to create only "distinct" Font objects to a cache, but this leads to a very big effort...

I think I understand your approach now :)

Regards,
Oliver
Oliver
  • Oliver
  • Advanced Member Topic Starter
2013-11-29T14:49:24Z
Very nice! It seems it's already in there. I really didnt notice that it already works for individual cells. Where it's not working the way you showed is in the Header and column-default objects:

' The following fails, because the Font Is Nothing:
objGrid.Header.Font.Bold = True

' The following fails, because the oFont Is Nothing:
With .AddCol(sKey:="mykey")
    Set .oFont.Bold = True
End With

Using the same approach you already have here could help.