stream := tfilestream.create(filename, fmcreate);
sourcebuffer := stralloc(1024);
writefilebegin(stream, dataset);
with dataset do
begin
disablecontrols;
bkmark := getbookmark;
first;
{write a title row}
writerowstart(stream, true);
for i := 0 to fieldcount-1 do
writedata(stream, nil, fields[i].displaylabel);
{write the end of row}
writerowend(stream, true);
while (not eof) do
begin
writerowstart(stream, false);
for i := 0 to fieldcount-1 do
writedata(stream, fields[i], getfieldstr(fields[i]));
{write the end of row}
writerowend(stream, false);
next;
end;
gotobookmark(bkmark);
enablecontrols;
end;
writefileend(stream);
stream.free;
strdispose(sourcebuffer);
end;
end.
生成xml文件。
我使用下面的转换方法:
i . xml文件的根名与表名相同(本例就是country)。
ii. 每条来自于表的记录由<record></record>标记区分。
iii. 每个来自于表的数据由其字段名标记加以区分。
- <country>
- <records>
<name>argentina</name>
<capital>buenos aires</capital>
<continent>south america</continent>
<area>2777815</area>
<population>32300003</population>
</records>
.
.
.
</country>
建立一个新的应用程序。放置一个button和table构件于主窗体上。设置表属性如下:
databasename : dbdemos
name : table1
tablename : country (remove the extention ".db")
active : true
选择 project/import type library。将会弹出 "import type library" 对话框。从列表中选择 "microsoft xml,version
2.0(version 2.0)" 然后点击 "create unit" 按钮。将会有一个 msxml_tlb 单元加入你的工程.请将 msxml_tlb 加入你要引用的单元的接口部分。然后在变量部分声明如下变量:
datalist : tstringlist;
doc : ixmldomdocument;
root,child,child1 : ixmldomelement;