zoukankan      html  css  js  c++  java
  • TClientDataSet的 AddIndex

    unit Unit2;
    
    interface
    
    uses
      SysUtils, Classes, DB, DBClient;
    
    type
      TDataModule2 = class(TDataModule)
        ClientDataSet1: TClientDataSet;
        DataSource1: TDataSource;
        procedure DataModuleCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      DataModule2: TDataModule2;
    
    implementation
    
    uses
      Dialogs;
    
    {$R *.dfm}
    
    procedure TDataModule2.DataModuleCreate(Sender: TObject);
    begin
      with DataModule2.ClientDataSet1 do
      begin
        FileName := 'test.cds';
        with TStringField.Create(DataModule2.ClientDataSet1) do
        begin
          FieldName := 'test';
          Name := 'ClientDataSet1test';
          DataSet := DataModule2.ClientDataSet1;
        end;
        CreateDataSet;
        with IndexDefs.AddIndexDef do //或者在设计时
        begin
          Name := 'Indextest';
          Fields := 'test';
          Options := [ixDescending];
        end;
    //    AddIndex('IndexTest', 'test', []); 不能用这个,否则下面一句 报 

    ---------------------------
    Project1
    ---------------------------
    ClientDataSet1: Index 'Indextest' not found.
    ---------------------------
    确定
    ---------------------------

        IndexName := 'Indextest';
    
        if FileExists('test.cds') then
          LoadFromFile('test.cds')
      end;
    end;
    
    end.
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, DBClient, Grids, DBGrids;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        DBGrid1: TDBGrid;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    uses
      Unit2;
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with DataModule2.ClientDataSet1 do
      begin
        Append;
        FieldByName('test').AsString := 'test1';
        Post;
      end;
    end;
    
    end.
    program Project1;
    
    uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {DataModule2: TDataModule};
    
    {$R *.res}
    
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TDataModule2, DataModule2);
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
  • 相关阅读:
    HDU_1016——素环问题DFS
    什么是REST?以及RESTful的实现
    WebApi系列~基于RESTful标准的Web Api
    理解RESTful架构
    国内技术管理人员批阅google的“春运交通图”项目
    项目质量量化考核建议
    设计模式在交易系统中的应用
    修改Chrome临时文件位置
    百度员工离职总结:如何做个好员工?
    Firebird数据库系统的开发团队
  • 原文地址:https://www.cnblogs.com/CodeGear/p/4311948.html
Copyright © 2011-2022 走看看