zoukankan      html  css  js  c++  java
  • TClientDataSet的操作

    记性不好了,唉,这里写个被忘
    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, DBGrids, DB, DBClient, StdCtrls;

    type
      TForm1 
    = class(TForm)
        Button1: TButton;
        Button2: TButton;
        ClientDataSet1: TClientDataSet;
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      
    private
        
    { Private declarations }
      
    public
        
    { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ClientDataSet1.LoadFromFile(
    'E:\TEMP.XML');
    end;


    procedure TForm1.Button1Click(Sender: TObject);
    var  tempClientDataSet : TClientDataSet;
    begin
    tempClientDataSet :
    = TClientDataSet.Create(self);
    try    with tempClientDataSet do
      begin
            with FieldDefs.AddFieldDef 
    do
            begin
                   DataType :
    = ftInteger;
                   Name     :
    = 'Field1';
            end;
            with FieldDefs.AddFieldDef 
    do
            begin
                   DataType :
    = ftdatetime;
                   Name     :
    = 'Field2';
            end;
            createDataSet;
            appendRecord([
    3,now]);
            appendRecord([
    1,now]);
            appendRecord([
    2,now]);
            tempClientDataSet.AddIndex(
    'T1''Field1', []);
            tempClientDataSet.IndexName :
    = 'T1';
            first;
            
    while not EOF do
              begin
                  showmessage(intToStr(FieldByName(
    'Field1').AsInteger)+formatdatetime('yyyymmdd HH:NN:DD',FieldByName('Field2').AsDateTime ));
                  next;
              end;
            end;
            tempClientDataSet.SaveToFile(
    'E:\TEMP.XML');
      
    finally
      tempClientDataSet.Free;
    end;
    end;



    end.
  • 相关阅读:
    空悬指针、野指针、内存泄漏、内存溢出
    自定义消息的操作方法ON_MESSAGE(..)
    为什么static成员变量一定要在类外初始化?
    Ubuntu 系统目录结构
    Beyond Compare 4 30天评估期结束的解决办法
    C++ string 字符串 结尾 标志
    C语言——枚举类型用法
    结构体struct-联合体union-枚举enum
    网卡bood
    kvm 安装
  • 原文地址:https://www.cnblogs.com/enli/p/642359.html
Copyright © 2011-2022 走看看