中国开发网: 论坛: 程序员情感CBD: 贴子 678258
UnKnow365
【技术贴】里面是内存表的实现,如何给内存表记录排序呢?
unit Unit1;

interface

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

type
TForm1 = class(TForm)
btn1: TButton;
DataSource1: TDataSource;
dbgrd1: TDBGrid;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function CreateTableInMemory(const AFieldDefs:TFieldDefs):TDataSet;
var
TempTable:TClientDataSet;
begin
TempTable:=nil;
Result:=nil;
if AFieldDefs<>nil then
begin
try
TempTable:=TClientDataSet.Create(Application);
TempTable.FieldDefs.Assign(AFieldDefs);
TempTable.CreateDataSet;
Result:=(TempTable as TDataSet);
Except
if TempTable<>nil then
TempTable.Free;
Result:=nil;
raise;
end;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
ADataSet:TDataSet;
begin
ADataSet:=TDataSet.Create(Self);
with ADataSet.FieldDefs do
begin
Add('Name',ftString,30,False);
Add('Value',ftInteger,0,False);
end;
with DataSource1 do
begin
DataSet:=CreateTableInMemory(ADataSet.FieldDefs);
DataSet.Open;
DataSet.Append;
DataSet.FieldByName('Name').AsString:='Woody';
DataSet.FieldByName('Value').AsInteger:=9527;
DataSet.Post;
end;
ADataSet.Free;
end;

end.
日出东海落西山,愁也一天,喜也一天;遇事不钻牛角尖,人也舒坦,心也舒坦。

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录