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.
procedure TfrQuota.vstGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize:= SizeOf(TObject);
end;
procedure TfrQuota.AddNewNode(node:PVirtualNode; AQDef: TQuotaDef);
begin
VST.AddChild(node, AQDef); // vst is virtual string tree.
VST.Expanded[HNode] := True;
end;
procedure TfrQuota.vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
var
Data: TQuotaDef;
begin
Data := TQuotaDef(Sender.GetNodeData(Node)^);
case Column of
0: if VST.GetNodeLevel(Node) = 0 // ); Node.Parent = Sender as TVir
then CellText := IntToStr(Data.QNumber)
else CellText := IntToStr(Data.Code);
1: CellText := Data.Caption;
2: CellText := IntToStr(Data.TargetN);
3: CellText := IntToStr(Data.MaxN);
4: CellText := IntToStr(Data.CurrentN);
5: CellText := IntToStr(Data.TargetN - Data.CurrentN);
6: if Data.TargetN = 0
then CellText := '- '
else CellText := Format('%.1f%%', [100.0 * Data.CurrentN/Data.TargetN]);
end;
end;
procedure TfrQuota.vstNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; const NewText: String);
var
AQDef: TQuotaDef;
NewTarget: integer;
AText: string;
begin
AQDef := TQuotaDef(Sender.GetNodeData(Node)^);
NewTarget := StrToIntDef(NewText, -1);
if (NewTarget < 0) then begin
ShowMessage('Zero or positive number only for target number');
vstGetText(Sender, Node, Column, ttNormal, AText);
end
else begin
if Column = 2
then AQDef.TargetN := NewTarget
else AQDef.MaxN := NewTarget;
with aQDef do UpdateNewTargets(QNumber, Code, TargetN, MaxN);
end;
end;
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?