Recent

Author Topic: Suggestions on new features of VirtualStringTree  (Read 222 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1694
Suggestions on new features of VirtualStringTree
« on: September 09, 2025, 07:27:52 am »
I'm using virtualstringtree with limit. I'm not quite familiar with setting it.
But I have managed to use it with objects (not records) rather easily.

In following example, TQuotaDef is a class.

Code: Pascal  [Select][+][-]
  1. procedure TfrQuota.vstGetNodeDataSize(Sender: TBaseVirtualTree;
  2.   var NodeDataSize: Integer);
  3. begin
  4.    NodeDataSize:= SizeOf(TObject);
  5. end;
  6.  
  7. procedure TfrQuota.AddNewNode(node:PVirtualNode; AQDef: TQuotaDef);
  8. begin
  9.     VST.AddChild(node, AQDef);  // vst is virtual string tree.
  10.     VST.Expanded[HNode] := True;
  11. end;
  12.  
  13. procedure TfrQuota.vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  14.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  15. var
  16.   Data: TQuotaDef;
  17. begin
  18.   Data := TQuotaDef(Sender.GetNodeData(Node)^);
  19.   case Column of
  20.     0: if VST.GetNodeLevel(Node) = 0  // ); Node.Parent = Sender as TVir
  21.           then CellText := IntToStr(Data.QNumber)
  22.           else CellText := IntToStr(Data.Code);
  23.     1: CellText := Data.Caption;
  24.     2: CellText := IntToStr(Data.TargetN);
  25.     3: CellText := IntToStr(Data.MaxN);
  26.     4: CellText := IntToStr(Data.CurrentN);
  27.     5: CellText := IntToStr(Data.TargetN - Data.CurrentN);
  28.     6: if Data.TargetN = 0
  29.           then CellText := '-  '
  30.           else CellText := Format('%.1f%%', [100.0 * Data.CurrentN/Data.TargetN]);
  31.   end;
  32. end;
  33.  
  34. procedure TfrQuota.vstNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  35.    Column: TColumnIndex; const NewText: String);
  36. var
  37.    AQDef: TQuotaDef;
  38.    NewTarget: integer;
  39.    AText: string;
  40.  
  41. begin
  42.    AQDef := TQuotaDef(Sender.GetNodeData(Node)^);
  43.    NewTarget := StrToIntDef(NewText, -1);
  44.  
  45.    if (NewTarget < 0) then begin
  46.        ShowMessage('Zero or positive number only for target number');
  47.        vstGetText(Sender, Node, Column, ttNormal, AText);
  48.    end
  49.    else begin
  50.       if Column = 2
  51.          then AQDef.TargetN := NewTarget
  52.          else AQDef.MaxN := NewTarget;
  53.       with aQDef do UpdateNewTargets(QNumber, Code, TargetN, MaxN);
  54.    end;
  55. end;
  56.  

Not sure the above codes are enough to adding an object to the Treeview. But the gist is simple. I'd like to display six properties of TQuotaDef (and edit only two of them) with VirtualStringTree --- Caption, TargetN, MaxN, CurrentN, and two ratios.

I think that if we can assign a property of the object to each column (and others being done automatically), then it would be quote nice feature. It's like RTTI controls.

How would you think?
« Last Edit: September 09, 2025, 11:46:19 am by egsuh »

 

TinyPortal © 2005-2018