0
votes

I would like to dynamically load and display into a TVirtualStringTree, data from some different SQL tables. This mean that the header and the content of each column will contain each time different type of data.

My problem is how to optimize in regards of memory usage, the definition of the record and the pointer for this case.

My thinking was to do it like this:

type
  TDataType = (dtUnknown, dtString, dtInteger, dtText, dtFloat, dtDateTime, dtDate, dtTime, dtBoolean);

  TData = record
    DataType: TDataType;
    AsString: String;
    AsInteger: Integer;
    AsText: TStrings;
    AsWord: Word;
    AsDateTime: TDateTime;
    AsDate: TDate;
    AsTime: TTime;
    AsBoolean: Boolean;
  end;
  TTreeData = array of TData;

  PTreeData= ^TTreeData;

In practice only 2 fields from the record will contained data: DataType (all the time) and a second field, depends by the DataType defined (e.g AsString, AsInteger). Will be also the others fields allocated as memory when Node will be initialized? Also I don't like the fact the DataType is allocated to each node. There must be a simple way to optimize this record.

Please some suggestions.

1
I'm pretty sure there's a data-aware descendant of that component already. Have you looked for that yet? It might prove more effective than attempting to reinvent that feature yourself. - Rob Kennedy
Here's a data-aware version of VTV: github.com/TurboPack/VirtualTreeView - Johan
Is it data-aware? I can see only usual TVirtualStringTree/TVirtualDrawTree here, no new components and no new properties. - Andrew
there was someone's contribution long ago - but it was never maintained for what I remember - Arioch 'The
you may use TValue datatype - docwiki.embarcadero.com/Libraries/XE2/en/System.Rtti.TValue (there are also a number of optimized 3rd party implementation of it, like TOmniValue) . Also for older Delphi you may use Variant datatype docwiki.embarcadero.com/RADStudio/Seattle/en/Variant_Types - Arioch 'The

1 Answers

0
votes

When I need to do something like this I use a case statement in the TData record.

Something like

type
   TData = record
      case DataType: TDataType of
       dtUnknown:
         (AsUnknown: ???);
       dtString:
         (AsString: string);  // this is incorrect, string (and some others are not allowed)
       dtInteger:
         (AsInteger: Integer);

       ... and so on

         end;
      end;

http://docwiki.embarcadero.com/RADStudio/Seattle/en/Structured_Types#Variant_Parts_in_Records

Have a look at TVarRec. Delphi uses open arrays TVarRec when implementing 'array of const' variables ans in the Format statement.

You probably only need two columns in the VirtualStringTree. One for the type and other for the value (represented as a string)