whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

75 Visitors Online


 
...save a TTreeView to a Ini-File?
Autor: Michael Fritzsche
Homepage: http://www.frifra.de
[ Print tip ]  

Tip Rating (5):  
     


procedure TreeToIni(Tree: TTreeView; INI: TIniFile; Section: string);
var
  
n: Integer;
  MS: TMemoryStream;
  tTv: TStringList;
  Msg: string;
begin
  
tTv := TStringList.Create;
  MS := TMemoryStream.Create;
  try
    
Tree.SaveToStream(MS);
    MS.Position := 0;
    tTv.LoadFromStream(MS);
    INI.EraseSection(Section);
    for n := 0 to tTv.Count - 1 do
      
INI.WriteString(Section, 'Node' + IntToStr(n), StringReplace(tTv[n], #9,
        '#', [rfReplaceAll]));
  finally
    
tTv.Free;
    MS.Free;
  end;
end;

procedure TreeFromIni(Tree: TTreeView; INI: TIniFile; Section: string;
  Expand: Boolean);
var
  
n: Integer;
  MS: TMemoryStream;
  tTv: TStringList;
  Msg: string;
begin
  
tTv := TStringList.Create;
  MS  := TMemoryStream.Create;
  try
    
INI.ReadSection(Section, tTv);
    for n := 0 to tTv.Count - 1 do
      
tTv[n] := StringReplace(INI.ReadString(Section, tTv[n], ''), '#', #9,
        [rfReplaceAll]);
    tTv.SaveToStream(MS);
    MS.Position := 0;
    Tree.LoadFromStream(MS);
    if (Expand = True) and (Tree.Items.Count > 0) then
      
Tree.Items[0].Expand(True);
  finally
    
tTv.Free;
    MS.Free;
  end;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners