Mit den folgenden beiden Funktionen kann man die Nodes eines TreeView in eine ini speichern, bzw. aus einer ini lesen.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
| 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 begin Tree.Items[0].Expand(True); Tree.Items[0].MakeVisible; end; finally tTv.Free; MS.Free; end; end; |
_________________
Michael
(principal certified lotus professional - developer)