Mega Code Archive

 
Categories / Delphi / VCL
 

How to Backup and Restore the content of a TreeView

Title: How to Backup and Restore the content of a TreeView Question: How can I backup (save) and the restore (load) the content of my TreeView to a file? Answer: Use the following two procedures to Backup and Restore the content of your TreeView: ******************************************************************* procedure TForm1.BackupTreeView(MyTree:TTReeView; ToFile:String); begin with TFileStream.Create( ToFile, fmCreate ) do try WriteComponent( MyTree ) ; finally Free ; end ; end; procedure TForm1.RestoreTreeView(MyTree:TTReeView; FromFile:String); begin with TFileStream.Create( FromFile, fmOpenRead ) do try MyTree.Clear; ReadComponent( MyTree ) ; finally Free ; end ; end; ****************************************************************** Enjoy, Roni Havas