码迷,mamicode.com
首页 > 其他好文 > 详细

TClientDataSet的 AddIndex

时间:2015-03-03 22:05:12      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

TClientDataSet的 AddIndex

标签:

原文地址:http://www.cnblogs.com/CodeGear/p/4311948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!