我可以解决内存表的问题,不过我要求有150分(开个玩笑)。
下面我帖代码:
unit MemTable;
//////////////////////////////////////////////////
//
// 创建一个内存表的实例
//
// 使用方法:Create(GivenTable: TTable; //要仿照创建的表,内存表将使用该表的定义
// NewName: String; //内存表的名称
// AOwner: TComponent) //所有者
//
////////////////////////////////////////////////////
interface
uses Classes,SysUtils,DBTables,DB,DBiTypes,DbiProcs;
type
TInMemoryTable=Class(TTable)
private
FieldDescs
FLDDesc;
NumberOfFields:Integer;
InMemoryTableName:array[0..79] of char;
protected
Function CreateHandle:HDBICur;override;
public
Constructor CreateLike(GivenTable:TTable;NewName:String;AOwner:TComponent);
Destructor Destroy;override;
end;
implementation
{ TInMemoryTable }
function TInMemoryTable.CreateHandle: HDBICur;
begin
check(DbiCreateInMemTable(DBHandle,InMemorytableName,NumberOfFields,FieldDescs,Result));
end;
constructor TInMemoryTable.CreateLike(GivenTable: TTable; NewName: String;
AOwner: TComponent);
var
CursorProperties:CURProps;
begin
inherited Create(AOwner);
StrPCopy(InMemoryTableName,NewName);
check(DbiGetCursorProps(Giventable.Handle,CursorProperties));
NumberOfFields:=CursorProperties.iFields;
FieldDescs:=nil;
try
FieldDescs:=Allocmem(NumberOfFields*sizeof(FLDDesc));
except
raise Exception.Create('Not enough memory.');
end;
check(DbiGetFieldDescs(GivenTable.handle,FieldDescs));
end;
destructor TInMemoryTable.Destroy;
begin
if FieldDescs<>nil then
FreeMem(FieldDescs,NumberOfFields*Sizeof(FLDDesc));
inherited Destroy;
end;
end.