急盼高手! 怎样对建立在内存中的临时表进行操作?(50分)

  • 主题发起人 主题发起人 liuaono1
  • 开始时间 开始时间
L

liuaono1

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大虾指点:
1.怎样在内存中建立一个临时表?
2.怎样对建立在内存中的临时表进行插入、修改操作?
(本人特菜,还望大虾赐一实例!)

本人已在“ 数据库 - 文件型 ”上以同类标题发布
请答出高手在那再去拿另 100 大洋!

 
下载rxlib 2.75,其中有一控件Tmemorytable对内存的数据加以操作,就象真正的table 一样 可创建table,insert,post 等操作。
 
// 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.
 
去“ 数据库 - 文件型 ”取分喽
 
可以对数组进行类似临时表的操作,
再把数组转化为正常表。
 
可以用Rx的控件RxMemoryData很容易用的:

procedure TForm1.Button1Click(Sender: TObject);
begin
RxMemoryData1.LoadFromDataSet(Table1,0,lmCopy);
//RxMemoryData1.
end;
 
如果是在本地建内存表意义不大,一般都建在服务器端,
而在服务器端建又与选的数据库有关,不同的数据库其建法不一样


 
接受答案了.
 
后退
顶部