博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用 TClientDataSet 创建 XML 文件的过程 - 回复"丁永其"的问题
阅读量:6150 次
发布时间:2019-06-21

本文共 2878 字,大约阅读时间需要 9 分钟。

  hot3.png

问题来源:

本例效果图:
26153037_lQ1d.gif

代码文件:

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, DB, DBClient;type  TForm1 = class(TForm)    ClientDataSet1: TClientDataSet;    Button1: TButton;    Button2: TButton;    Button3: TButton;    Button4: TButton;    Memo1: TMemo;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);    procedure Button4Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}uses XMLDoc; {为了使用 FormatXMLData 函数}procedure TForm1.Button1Click(Sender: TObject);begin  ClientDataSet1.FieldDefs.Clear;  with ClientDataSet1.FieldDefs.AddFieldDef do  begin    Name := 'Name';    DataType := ftString;    Size := 10;  end;  with ClientDataSet1.FieldDefs.AddFieldDef do  begin    Name := 'Age';    DataType := ftInteger;  end;  ClientDataSet1.CreateDataSet;//  ClientDataSet1.LogChanges := False;  ClientDataSet1.Open;end;procedure TForm1.Button2Click(Sender: TObject);begin  ClientDataSet1.Append;  ClientDataSet1.Fields[0].Value := '张三';  ClientDataSet1.Fields[1].Value := 11;  ClientDataSet1.Append;  ClientDataSet1.Fields[0].Value := '李四';  ClientDataSet1.Fields[1].Value := 22;end;procedure TForm1.Button3Click(Sender: TObject);begin  Memo1.Clear;  Memo1.Text := FormatXMLData(ClientDataSet1.XMLData);end;procedure TForm1.Button4Click(Sender: TObject);begin  ClientDataSet1.SaveToFile('c:\temp\MyXml.xml', dfXML);  {如果要存得格式漂亮就用下面这句:}  Memo1.Lines.SaveToFile('c:\temp\MyXml2.xml');end;end.
窗体文件:

object Form1: TForm1  Left = 0  Top = 0  Caption = #20381#27425#28857#20987#25353#38062  ClientHeight = 211  ClientWidth = 445  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poDesktopCenter  PixelsPerInch = 96  TextHeight = 13  object Button1: TButton    Left = 358    Top = 21    Width = 75    Height = 25    Caption = #21019#24314    TabOrder = 0    OnClick = Button1Click  end  object Button2: TButton    Left = 358    Top = 64    Width = 75    Height = 25    Caption = #28155#21152    TabOrder = 1    OnClick = Button2Click  end  object Button3: TButton    Left = 358    Top = 108    Width = 75    Height = 25    Caption = #26597#30475    TabOrder = 2    OnClick = Button3Click  end  object Button4: TButton    Left = 358    Top = 152    Width = 75    Height = 25    Caption = #20445#23384    TabOrder = 3    OnClick = Button4Click  end  object Memo1: TMemo    Left = 0    Top = 0    Width = 345    Height = 211    Align = alLeft    Lines.Strings = (      'Memo1')    ScrollBars = ssBoth    TabOrder = 4  end  object ClientDataSet1: TClientDataSet    Aggregates = <>    Params = <>    Left = 168    Top = 8  endend
打开一看, 发现程序很不严谨, 但能说明问题了, 不在修改了.

转载于:https://my.oschina.net/hermer/blog/319231

你可能感兴趣的文章
pip安装Mysql-python报错EnvironmentError: mysql_config not found
查看>>
http协议组成(请求状态码)
查看>>
怎样成为一个高手观后感
查看>>
[转]VC预处理指令与宏定义的妙用
查看>>
JQuery radio单选框应用
查看>>
MySql操作
查看>>
python 解析 XML文件
查看>>
MySQL 文件导入出错
查看>>
java相关
查看>>
由一个异常开始思考springmvc参数解析
查看>>
向上扩展型SSD 将可满足向外扩展需求
查看>>
虚机不能启动的特例思考
查看>>
SQL Server编程系列(1):SMO介绍
查看>>
在VMware网络测试“专用VLAN”功能
查看>>
使用Formik轻松开发更高质量的React表单(三)<Formik />解析
查看>>
也问腾讯:你把用户放在什么位置?
查看>>
CSS Sprites 样式生成工具(bg2css)
查看>>
[转]如何重构代码--重构计划
查看>>
类中如何对list泛型做访问器??
查看>>
C++解析XML--使用CMarkup类解析XML
查看>>