我已使用下一个命令将TreeView保存在数据库中:
var
BlobField :TField;
Query:TADOQuery;
Stream:TStream;
...
try
Query.SQL.Text := 'Select TOP(1) * From MyTable';
DBQueryConnect(Query); // I used this Procedure to connect the Query to the database
try
Query.First;
Query.Edit;
try
BlobField := Query.FieldByName('MyField') as TField;
Stream := Query.CreateBlobStream(BlobField, bmWrite);
try
MyTreeView.SaveToStream(Stream,TEncoding.UTF8);
finally
Stream.Free;
end;
Query.Post;
except
Query.Cancel;
raise;
end;
finally
Query.Close;
end;
finally
Query.Free;
end;
end;
并且我使用next命令从数据库中加载回TTreeView:
...
var
Query:TADOQuery;
Stream:TStream;
begin
Query:=TADOQuery.Create(Self);
try
Query.SQL.Add('Select * From MyTable') ;
DBQueryConnect(Query);
Query.First;
Stream:=Query.CreateBlobStream(Query.FieldByName('MyField'), bmread);
MyTreeView.LoadFromStream(Stream);
Stream.Free;
finally
Query.Free;
end;
如何从保存的数据中检索TreeView项的imageindex ..谢谢。
1条答案
按热度按时间brccelvz1#
也许我们可以这样修改现有的
SaveTreeToStream
和LoadTreeFromStream
:可以将
MyTreeView.SaveToStream(Stream,TEncoding.UTF8);
替换为SaveTreeToStream(MyTreeView.Items,Stream,TEncoding.UTF8);
,将MyTreeView.LoadFromStream(Stream);
替换为LoadTreeFromStream(MyTreeView.Items,Stream,TEncoding.UTF8);