Jump to content
Sign in to follow this  
Mark-

TVirtualStringTree...

Recommended Posts

Hello,

 

Delphi 10.2

 

I just started using TVirtualStringTree and all is working well (Thanks Jam Software). I need to save all the node captions to a text file with the same format as TTreeview (tab character for indent level followed by caption string) so, at a later time, the file can be loaded and parsed. Has anyone done such a thing?

 

Cheers,

 

Mark

Share this post


Link to post

Hello,

 

What I came up with for my needs.

procedure SaveVTToFileLikeTTreeView(tree:TVirtualStringTree; const fName:string);
var
 data:TVTABFetch;
 strList:TStringList;
 tmpNode:PVirtualNode;

 function CreateTabPrefix(count:integer):string;
 var
  i:integer;
 begin
  result:='';
  for i:=0 to count -1 do
   result:=result + #09;            //tab
 end;

begin
 if (fName = '') then
  Exit;

 strList:=TStringList.Create;
 if not Assigned(strList) then
  Exit;

 try
  tmpNode:=tree.GetFirst;
  if not Assigned(tmpNode) then   //if nothing, scram
   Exit;

  repeat
   data:=TVTABFetch(Pointer(tree.GetNodeData(tmpNode)^));
   if Assigned(Data) then            //safety
    strList.Add(CreateTabPrefix(tree.GetNodeLevel(tmpNode)) + data.caption);

   tmpNode:=tree.GetNext(tmpNode);

  until (not Assigned(tmpNode));

  strList.SaveToFile(fName);
 finally
  strList.free;
 end;
end;

Cheers,

 

Mark

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×