unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, VirtualTrees,
DB, DBClient, xmldom, Provider, Xmlxform,
Grids, DBGrids;
type
PNodeData = ^TNodeData;
TNodeData =
record
FBookmark: TBookmark;
end;
TForm1 =
class(TForm)
VST: TVirtualStringTree;
btnLoad: TButton;
ClientDataSet: TClientDataSet;
XMLTransformProvider: TXMLTransformProvider;
DataSource: TDataSource;
DBGrid1: TDBGrid;
btnAdd: TButton;
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
procedure btnLoadClick(Sender: TObject);
procedure VSTNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: WideString);
procedure btnAddClick(Sender: TObject);
procedure VSTGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnAddClick(Sender: TObject);
var
Node: PVirtualNode;
NodeData: PNodeData;
begin
ClientDataSet.Append;
ClientDataSet.FieldValues['
test'] := '
123';
ClientDataSet.Post;
Node := VST.AddChild(
nil);
NodeData := VST.GetNodeData(Node);
NodeData^.FBookmark := ClientDataSet.GetBookmark;
end;
procedure TForm1.btnLoadClick(Sender: TObject);
var
Node: PVirtualNode;
NodeData: PNodeData;
begin
XMLTransformProvider.XMLDataFile := '
test.xml';
ClientDataSet.XMLData := XMLTransformProvider.TransformRead.Data;
ClientDataSet.DisableControls;
try
ClientDataSet.First;
//Auf ersten Datensatz positionieren, EOF wird dadurch auf False gesetzt
while not ClientDataSet.Eof
do // Schleife durchlaufen, bis EOF True ist.
begin
Node := VST.AddChild(
nil);
NodeData := VST.GetNodeData(Node);
NodeData^.FBookmark := ClientDataSet.GetBookmark;
ClientDataSet.Next;
//EOF ist True, wenn Next scheitert, da dann der letzte Datensatz erreicht wurde
end;
finally
ClientDataSet.EnableControls;
end;
end;
procedure TForm1.VSTGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := SizeOf(PNodeData);
end;
procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
begin
ClientDataSet.GotoBookmark(TBookmark(PNodeData(Sender.GetNodeData(Node)).FBookmark));
CellText := ClientDataSet.FieldByName('
test').asString;
end;
procedure TForm1.VSTNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: WideString);
var
NodeData: PNodeData;
begin
ClientDataSet.GotoBookmark(TBookmark(PNodeData(Sender.GetNodeData(Node)).FBookmark));
ClientDataSet.Edit;
ClientDataSet.FieldValues['
test'] := NewText;
ClientDataSet.Post;
//NodeData := VST.GetNodeData(Node);
//NodeData^.FBookmark := ClientDataSet.GetBookmark;
ClientDataSet.GotoBookmark(TBookmark(PNodeData(Sender.GetNodeData(Node)).FBookmark));
end;
end.