Mega Code Archive

 
Categories / Delphi / Files
 

Save a TTreeView to a Ini File

Title: save a TTreeView to a Ini-File? 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;