// Form
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 24
Top = 72
Width = 505
Height = 233
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DBNavigator1: TDBNavigator
Left = 144
Top = 24
Width = 232
Height = 25
DataSource = DataSource1
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast, nbInsert, nbEdit, nbPost, nbCancel]
TabOrder = 1
end
object DataSource1: TDataSource
Left = 256
Top = 160
end
end
// Unit
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DBTables, DB, DBiTypes, ExtCtrls, DBCtrls, Grids, DBGrids;
type
TMemTable = class(TTable)
private
FieldDescs: PFLDDesc;
NumberOfFields: Integer;
MemTableName: array [0..79] of Char;
protected
function CreateHandle: HDBICur; override;
public
constructor CreateLike(
GivenTable: TTable; NewName: string; AOwner: TComponent);
destructor Destroy; override;
end;
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
MemTable: TMemTable;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
constructor TMemTable.CreateLike(
GivenTable: TTable; NewName: string; AOwner: TComponent);
var
CursorProperties: CURProps;
begin
inherited Create(AOwner);
StrPCopy(MemTableName, 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 TMemTable.Destroy;
begin
if FieldDescs <> nil then
FreeMem(FieldDescs, NumberOfFields * SizeOf(FLDDesc));
inherited;
end;
function TMemTable.CreateHandle: HDBICur;
begin
Check(DbiCreateInMemTable(
DBHandle, MemTableName, NumberOfFields, FieldDescs, Result));
end;
procedure TForm1.FormCreate(Sender: TObject);
var
ATable: TTable;
I: Integer;
begin
ATable := TTable.Create(Self);
ATable.DatabaseName := 'DBDEMOS';
ATable.TableName := 'CUSTOMER.DB';
ATable.Open;
MemTable := TMemTable.CreateLike(ATable, 'MyInMem', Self);
DataSource1.DataSet := MemTable;
MemTable.Open;
while not ATable.Eof do
begin
MemTable.Append;
for I := 0 to MemTable.NumberOfFields - 1 do
MemTable.Fields.Value := ATable.Fields.Value;
ATable.Next;
end;
MemTable.First;
ATable.Close;
ATable.Free;
end;
end.