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.
时间: 2024-08-04 14:08:12

TClientDataSet的 AddIndex的相关文章

TClientDataSet的 fastscript封装

// 陈新光 2017-2-10// TClientDataSet's fastscript unit fs_ClientDataSet; interface {$i fs.inc} uses SysUtils, Classes, fs_iinterpreter, fs_itools, fs_ievents, DB, fs_iclassesrtti, Variants, DBClient {$IFDEF Delphi16} , System.Types, Controls {$ENDIF} ;

TClientDataSet使用要点

TClientDataSet控件继承自TDataSet,其数据存储文件格式扩展名为 .cds,是基于文件型数据存储和操作的控件.该控件封装了对数据进行操作处理的接口和功能,而本身并不依赖上述几种数据库驱动程序,基本上能满足单机"瘦"数据库应用程序的需要. 一.TClientDataSet的基本属性和方法介绍 1).FieldDefs: 字段定义列表属性 开发者可通过单击属性编辑器中该属性编辑按钮,或在该控件上单击右键选择弹出菜单中的"Fields Editor"菜单

DELPHI使用TClientDataSet时不携带MIDAS.DLL的方法

DELPHI使用TClientDataSet时不携带MIDAS.DLL的方法 转载自地址:http://www.cnblogs.com/mikemao/archive/2011/12/19/2293664.html TClientDataSet小家碧玉,恐怕人人都喜欢使用.但是,都知道娶TClientDataSet是有代价的,因为你同时也得面对丈母娘MIDAS.DLL.           能不能使用TClientDataSet又不用MIDAS.DLL呢?           很简单,就是use

Delphi TClientDataSet的使用

1.TClientDataSet的基本属性和方法介绍 1).FieldDefs: 字段定义列表属性 开发者可通过单击属性编辑器中该属性编辑按钮,或在该控件上单击右键选择弹出菜单中的"Fields Editor"菜单进行字段编辑.设置完此属性后,实际上就相当于定义了表的结构:如果想装入已有的数据表的结构和数据,可通过单击右键选择弹出菜单中的"Assign Local Data"菜单,从弹出对话框中选取当前窗体中已与数据库连接好的数据集控件名称即可(当前窗体中必须已放置

TClientDataSet的基本属性和方法介绍

原文来自:http://www.delphitop.com/html/kongjian/2079.html TClientDataSet控件继承自TDataSet,其数据存储文件格式扩展名为 .cds,是基于文件型数据存储和操作的控件.该控件封装了对数据进行操作处理的接口和功能,而本身并不依赖上述几种数据库驱动程序,基本上能满足单机"瘦"数据库应用程序的需要. 1.TClientDataSet的基本属性和方法介绍 1).FieldDefs: 字段定义列表属性 开发者可通过单击属性编辑器

[转载] 学习TClientDataset的使用

[转载] 学习TClientDataset的使用 http://blog.csdn.net/onebigday/article/details/6275550 这个控件好像很好用,以前都是用TSimpledataset,现在突然想用一下它.要用它,好像比TSimpleDataset多几个控件,我是加了以下几个控件,TSQLConnection,TSQLQuery,TDataSetProvider,TClientDataset,TDataSource,TDBGrid.这几个控件中,TDBGrid的

TClientDataSet 介绍

一.  ClientDataSet初认识: 1. 从类的继承关系上来看,是TDataSet这个抽象类的子类,所以我们可以在TDataSet这个抽象层次上对其进行我们熟 悉的操作,比如导航.排序.过滤.编辑. 2.要注意的是,TClientDataSet使用了一种全新的技术,它将所有的数据均放在内存中,所以 TClientDataSet是个只存在内存中的“虚拟表”,因此对数据库的操 作是非常快的.在PIII 850,512MB的机器上对十万条记录进行建索引的操作,花费的时间少于半分钟.与一般的数据

使用 TClientDataSet(1)

本例效果图: 代码文件: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, Grids, DBGrids, DB, DBClient, StdCtrls, ExtCtrls; type   TForm1 = class(TForm)     Panel1: TPanel;     Button1: TButton;  

delphi开发学习四:TClientDataSet与TDataSetProvider控件使用实例

1.TClientDataSet控件 通过TClientDataSet控件可以建立瘦客户端的应用程序,且数据执行效率较高,但它不能和数据库自动连接,程序中必须制定它如何获取数据.一般情况下,TClientDataSet 控件获取数据的方式主要有 3 种:从本地文件中获取.从本地的另外一个数据集对象中获取以及通过 IAppServer 接口来获取. 2.TDataSetProvider 控件TDataSetProvider 控件基于数据集为应用程序中的其他控件提供数据, 并将对数据的更新传回数据集