...save and load a TTreeView?

Author: Thomas Stutz

Category: VCL

{
  Treeview1.SaveToFile('...') doesn't store images.
  Instead, use the code below.
}

{
 Treeview1.SaveToFile('...') speichert Bitmaps im Treeview nicht.

 Um auch die Bitmaps eines Treeviews zu speichern,
 benütze untenstehenden Code.
}

// Save

procedure TForm1.Button1Click(Sender: TObject);
var
  
F: TFileStream;
begin
  
F := TFileStream.Create('c:\TreeView.txt', fmCreate or fmShareCompat);
  try
    
F.WriteComponent(TreeView1);
  finally
    
F.Free;
  end;
end;


// Load

procedure TForm1.Button2Click(Sender: TObject);
var
  
F: TFileStream;
begin
  
F := TFileStream.Create('c:\TreeView.txt', fmOpenRead or fmShareDenyWrite);
  try
    
F.ReadComponent(TreeView1);
  finally
    
F.Free;
  end;
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base