kkelchev Posted April 11, 2020 Posted April 11, 2020 Hi , How to loadFromFile(TUniTreeView) like standart VCL TreeView . It should be possible because in Design time TUniTreeView.Items editor have button "Load" -> Browse (file) and it work fine. How to do this at RunTime. There is no (or I can't'see it ) TUniTreeView .LoadFromFile method Thanks Kamen Quote
Sherzod Posted April 12, 2020 Posted April 12, 2020 20 hours ago, kkelchev said: How to do this at RunTime. There is no (or I can't'see it ) TUniTreeView .LoadFromFile method Hello, As one of the possible solutions at the moment, I tested the second solution from here and it works. https://stackoverflow.com/questions/18578683/saving-and-loading-treeview-using-xml Quote
Freeman35 Posted April 12, 2020 Posted April 12, 2020 Hi, You can look this link too. http://forums.unigui.com/index.php?/topic/8787-tunitreeview-export-to-xml/&tab=comments#comment-45188 Quote
kkelchev Posted April 12, 2020 Author Posted April 12, 2020 Thanks both of you . Actually I Did something similar. Thanks again. Quote
filfor Posted March 29, 2022 Posted March 29, 2022 I solved in this way: type TUniTreeViewHelper=class helper for TUniTreeView procedure SaveToFile(aFileName:string); procedure LoadFromFile(aFileName:string); end; { TUniTreeViewHelper } procedure TUniTreeViewHelper.LoadFromFile(aFileName: string); var f:textfile; ss:Tstringlist; s,s1:string; i,j:integer; ind,level:array of integer; curlength:integer; begin try assignfile(f,aFileName); reset(f); ss:=Tstringlist.Create; //first pass check the owner setlength(level,0); repeat readln(f,s); s1:=s.Replace(#9,''); ss.Add(s1);//label setlength(level,ss.Count); level[ss.Count-1]:=length(s)-length(s1); until eof(f); setlength(ind,length(level)); ind[0]:=0; for i:=ss.Count-1 downto 1 do begin j:=i; repeat dec(j); until level[j]=level[i]-1; ind[i]:=j; end; //now I create treeview Items.Clear(); Items.Add(nil,ss[0]); for i := 1 to length(ind)-1 do begin if ind[i]<0 then Items.Add(nil,ss[i]) else Items.Add(Items[ind[i]],ss[i]); end; finally closefile(f); ss.Free; end; end; procedure TUniTreeViewHelper.SaveToFile(aFileName: string); var f:textfile; i:integer; begin try assignfile(f,aFileName); rewrite(f); for i:=0 to Items.Count-1 do begin writeln(f,StringOfChar(#9,items[i].Level)+items[i].Text); end; finally closefile(f) end; end; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.