Registriert seit: 11. Aug 2003
Ort: München
6.537 Beiträge
|
Re: TreeView in ini speichern/aus ini lesen
1. Mai 2004, 22:54
Also, ich habe mir mal erlaubt, den Code von FriFra abzuändern. Nun wird für jedes Item gespeichert, ob es auf- oder zugeklappt ist.
Delphi-Quellcode:
procedure TreeToIni(Tree: TTreeView; INI: TIniFile; Section: string);
var
n: integer;
MS: TMemoryStream;
tTv: TStringList;
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])+#1+BoolToStr(Tree.Items[n].Expanded,True));
finally
tTv.Free;
MS.Free;
end;
end;
procedure TreeFromIni(Tree: TTreeView; INI: TIniFile; Section: string;
Expand: boolean);
var
n, PosDel: integer;
MS: TMemoryStream;
tTv: TStringList;
Temp: String;
begin
tTv := TStringList.Create;
MS := TMemoryStream.Create;
try
INI.ReadSection(Section, tTv);
for n := 0 to tTv.Count - 1 do
begin
Temp := StringReplace(INI.ReadString(Section, tTv[n], ''), '#', #9,
[rfReplaceAll]);
PosDel := Pos(#1,Temp);
Delete(Temp,PosDel,Length(Temp)-PosDel+1);
tTv[n] := Temp;
end;
tTv.SaveToStream(MS);
MS.Position := 0;
Tree.LoadFromStream(MS);
if (Expand = True) and (Tree.Items.Count > 0) then
begin
INI.ReadSection(Section, tTv);
for n := 0 to tTv.Count - 1 do
begin
tTv[n] := StringReplace(INI.ReadString(Section, tTv[n], ''), '#', #9,
[rfReplaceAll]);
PosDel := Pos(#1,tTv[n]);
if StrToBool(Copy(tTv[n],PosDel+1,Length(tTv[n])-PosDel)) then
Tree.Items[n].Expand(False);
end;
end;
finally
tTv.Free;
MS.Free;
end;
end;
Andreas B. Die Mutter der Dummen ist immer schwanger.
Ein Portal für Informatik-Studenten: www.infler.de
|
|
Zitat
|