How to rapidly stream TTreeView contents
- John Hunt
- CIS 100343,3317
Bulk operations on a TTreeView are often painfully slow, because every time a
node is referenced using an index, the TTreeView has to walk through its
linked list of nodes to get to the specified index; for bulk operations like
streaming, this can take up a lot of time.
The trick for speeding up such bulk operations is to avoid using indexes to
refer to the TTreeView's nodes. This is simple enough to do when you're
streaming out the contents of the TTreeView - you simply use GetNext to move
from one node to the next while you are streaming. The problem is, how do you
reconstruct the hierarchy of the TTreeView when you stream the data back in?
The solution to this is to precede each node in the stream with an integer
value that denotes that node's relationship to the previous node in the tree.
A node can be related to its previous node in one (and only one) of the
following ways:
(1) the node has no previous node (it's the first one in the tree)
(2) the node is the first child of the previous node
(3) the node is the first sibling of the previous node
(4) the node is the first sibling of the previous node's parent
(5) the node is the first sibling of the previous node's grandparent
(6) etc.
By examing the "relational-degree" integer when you stream the node back in,
you can tell where the node needs to be inserted in the TTreeView.
The example program shows how to do this. When the program starts, it creates
ca. 3600 tree nodes containing both some text and some miscellaneous data (a
record that holds four integer values); the nodes are added to the TTreeView
at 4 levels of nesting.
To stream out the TTreeView's contents, press the "Stream to disk" button
(the streamed contents are saved in the file 'treeview.stm' in the current
directory); to read it back it, press the "Read from disk" button; to clear
the list, press the "Clear" button. To test whether the program is really
reconstructing the hierarchy correctly, you can select a node and move the
mouse a little, so that the node goes into editing mode; then you can type
some text into the node. If you then stream the tree view out, clear it, and
stream the tree view back in, you'll notice that your text is just where you
typed it. To view the random data at any node, select the node and then press
the ENTER key; you get a verbalized description of the integers constituting
the data of that node.
When you press the "Stream to disk" button, the program calls the
GetRelToPrev function for each node, which returns an integer denoting the
current node's relationship to its previous node (see the comments under the
function header). That relational-degree integer is then written to the
stream, followed by the node's text and data. To cut down on storage space, I
used a short integer (signed byte) as the relational-degree value; this
allows up to 127 levels of nesting. If you need more levels of nesting, use a
larger-sized integer as the result type of the GetRelToPrev function.
When you press the "Read from disk" button, the relational-degree integer is
read back in for each node, as well as the node's text and data; the node is
then inserted at the proper point in the tree view based on the
relational-degree integer.
Even if you use a different streaming mechanism or model for your TTreeViews,
it should be possible to adapt the above strategy to it so that you obtain
the fastest possible streaming performance.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
《Delphi 7组件编程参考手册》附带的光盘内容 (1005个子文件)
speedis.avi 4.69MB
cool.avi 35KB
CIBAB.bmp 2.25MB
circle.bmp 117KB
ex.bmp 29KB
Icon.bmp 19KB
tick.bmp 7KB
circle_sm.bmp 3KB
Draw.bmp 3KB
loss.bmp 3KB
win.bmp 3KB
ex_sm.bmp 3KB
arrow.bmp 3KB
human.bmp 2KB
RECTANG.BMP 2KB
ELLIPSE.BMP 2KB
ROUNDREC.BMP 2KB
HLEFT.BMP 322B
HRIGHT.BMP 322B
HNOTE.BMP 322B
HCENTER.BMP 322B
Forward.bmp 246B
Beginning.bmp 246B
Pause.bmp 246B
End.bmp 246B
Reverse.bmp 246B
pixel.bmp 58B
Project1.cfg 745B
poptest.cfg 745B
Project1.cfg 745B
Shellink.cfg 745B
Project1.cfg 745B
Project2.cfg 745B
Project1.cfg 745B
dcCaDemo.cfg 454B
Ddgpaint.cfg 422B
RefList.cfg 386B
Reflist2.cfg 386B
WordCont.cfg 386B
Olecont.cfg 386B
Olecont.cfg 386B
Pages.cfg 386B
Fraction.cfg 386B
Project1.cfg 386B
BMP2Glyph.cfg 386B
Project1.cfg 386B
Split2.cfg 386B
DockTest.cfg 386B
QLibSpeed.cfg 386B
LibSpeed.cfg 386B
IbxMon.cfg 386B
CoolDemo.cfg 386B
MyDlg.cfg 386B
MTGraph.cfg 386B
MdEdit3.cfg 386B
BmpViewer.cfg 386B
WizardUI.cfg 386B
NonAware.cfg 386B
DbEvts.cfg 386B
CustHint.cfg 386B
ShCut.cfg 386B
Project1.cfg 386B
QMbParade.cfg 386B
Odmenu.cfg 386B
TicTacToe.cfg 386B
UpdSql2.cfg 386B
RWBlocks.cfg 386B
MethodInfo.cfg 358B
FileOfRec.cfg 358B
ClassInfo.cfg 358B
Envlope.cfg 354B
MakeFont.cfg 354B
MOVE_M.CUR 766B
dcCalend.d16 413B
dcCalend.d32 476B
PERSONS.DAT 56B
bdesdd.DBF 119KB
animals.DBF 681B
bdesdd.DBT 462KB
animals.DBT 113KB
dock.dck 50B
CaptionButton.dcr 708B
AdoMain.dcu 91KB
dcCalend.dcu 44KB
frmAdminToolU.dcu 44KB
ScreenSlideShow.dcu 23KB
COP_SORT.dcu 23KB
main.dcu 22KB
MainFrm.dcu 19KB
editor.dcu 18KB
RichForm.dcu 18KB
MainFrm.dcu 17KB
UFMain.dcu 17KB
Pars_3.dcu 17KB
MainFrm.dcu 14KB
U_BigFloat.dcu 13KB
DbEvtsF.dcu 13KB
RecError.dcu 13KB
CustomDrawTreeView.dcu 13KB
Unit1.dcu 13KB
共 1005 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
- loarding20132014-10-15可惜没有书啊~
- 花生2017-04-30资料很好谢谢!
- 「已注销」2018-03-12摊破铁屑无觅处, 得来全不费工夫
woshipachong
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功