小弟现在 在做一个软件,情况如下:这个软件有6 个界面,一个主界面,有6个按钮可以进行调用,6个窗口(就是界面)。数据库也建好,6个窗口,也建了6个表。
现在的问题是:我要把这6个界面,和这个数据库,6个表连接起来。用的是ABSolute DB,ABSTable 怎么样才能把这6 个界面和数据库,表连接起来?
用到的有 data module
希望步骤详细些,说的清楚些,谢谢!
小弟新手,请大家不吝赐教,小弟全天等侯你们的佳音!
现在的问题是:我要把这6个界面,和这个数据库,6个表连接起来。用的是ABSolute DB,ABSTable 怎么样才能把这6 个界面和数据库,表连接起来?
用到的有 data module
希望步骤详细些,说的清楚些,谢谢!
小弟新手,请大家不吝赐教,小弟全天等侯你们的佳音!
解决方案 »
- 求fastreport3
- Form1.Image1.Canvas.TextOut怎么不好使了?
- 急用!!大家帮帮忙!!!
- 急急急!!如何打包?在线等
- There is no overloaded version of 'IntToStr' that can be called with these arguments是什么意思啊
- delphi7的quickrep控件那去了?
- 什么是TNotifyEvent和TIndexEvent?
- 关于ADO的问题
- TDBEdit控件怎么只能显示数据库内容,而不能更新数据库呢???
- 大家关心的问题,欢迎热烈讨论
- Delphi新手
- 用过easygrid的高手请进,小弟遇到个小为题
untDM.pasunit untDM;interfaceuses
SysUtils, Classes, untIntf, DB, ABSMain;type
TDM = class(TDataModule, IDMSearch)
DS: TDataSource;
DB: TABSDatabase;
Qry: TABSQuery;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
function Search(ACode: integer): TDataSource;
end;var
DM: TDM;implementation{$R *.dfm}procedure TDM.DataModuleCreate(Sender: TObject);
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
DB.DatabaseFileName := ExtractFilePath(ParamStr(0)) + 'Demo.ABS';
DB.Open;
end;procedure TDM.DataModuleDestroy(Sender: TObject);
begin
DB.Close;
end;function TDM.Search(ACode: integer): TDataSource;
begin
with Qry do
begin
Close;
if ACode = -1 then
SQL.Text := 'select * from [DemoTable]'
else
SQL.Text := Format('select * from [DemoTable] where [Code]=%d', [ACode]);
Open;
Result := DS;
end;
end;initialization
RegisterClass(TDM);finalization
UnRegisterClass(TDM);end.untDM.dfmobject DM: TDM
OldCreateOrder = False
OnCreate = DataModuleCreate
OnDestroy = DataModuleDestroy
Height = 175
Width = 215
object DS: TDataSource
DataSet = Qry
Left = 16
Top = 112
end
object DB: TABSDatabase
CurrentVersion = '5.11 '
DatabaseName = 'Demo'
Exclusive = False
MaxConnections = 500
MultiUser = False
SessionName = 'Default'
Left = 16
Top = 8
end
object Qry: TABSQuery
CurrentVersion = '5.11 '
DatabaseName = 'Demo'
InMemory = False
ReadOnly = False
Left = 16
Top = 64
end
endDBM.dpkpackage DBM;{$R *.res}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$IMPLICITBUILD ON}requires
rtl,
vcl,
dbrtl,
dclAbsDBd10;contains
untDM in 'untDM.pas' {DM: TDataModule},
untIntf in '..\intf\untIntf.pas';end.EXE 代码[dai ma]:frmMain.pasunit frmMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,untIntf, StdCtrls, ExtCtrls, Grids, DBGrids, DB;type
TFormMain = class(TForm)
DBGrid1: TDBGrid;
Panel1: TPanel;
LabeledEdit1: TLabeledEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
bplHandle: Cardinal;
DM: IDMSearch;
end;var
FormMain: TFormMain;implementation{$R *.dfm}procedure TFormMain.Button1Click(Sender: TObject);
var
ds: TDataSource;
begin
ds:=DM.Search(StrToIntDef(LabeledEdit1.Text, -1));
DBGrid1.DataSource := ds;
end;procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
DM := nil;
// UnloadPackage(bplHandle);
end;procedure TFormMain.FormCreate(Sender: TObject);
var
c: TClass;
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
bplHandle := LoadPackage('DBM.bpl');
c:= GetClass('TDM');
if c <> nil then
DM := TComponentClass(c).Create(Application) as IDMSearch;
end;end.frmMain.dfmobject FormMain: TFormMain
Left = 0
Top = 0
Caption = 'FormMain'
ClientHeight = 237
ClientWidth = 246
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 246
Height = 184
Align = alClient
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object Panel1: TPanel
Left = 0
Top = 184
Width = 246
Height = 53
Align = alBottom
BevelInner = bvRaised
BevelOuter = bvLowered
TabOrder = 1
object LabeledEdit1: TLabeledEdit
Left = 8
Top = 20
Width = 146
Height = 21
EditLabel.Width = 25
EditLabel.Height = 13
EditLabel.Caption = 'Code'
TabOrder = 0
end
object Button1: TButton
Left = 160
Top = 16
Width = 75
Height = 25
Caption = #26597#35810
TabOrder = 1
OnClick = Button1Click
end
end
endProject1.dprprogram Project1;uses
Forms,
frmMain in 'frmMain.pas' {FormMain},
untIntf in '..\intf\untIntf.pas';{$R *.res}begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TFormMain, FormMain);
Application.Run;
end.通用接口[jie kou]单元[dan yuan]代码[dai ma]:untIntf.pasunit untIntf;interfaceuses
Classes, SysUtils, DB;type
IDMSearch = interface
['{494B4378-A373-4BAD-95D6-49CC12F76ADF}']
function Search(ACode: Integer): TDataSource;
end;implementationend.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,untIntf, StdCtrls, ExtCtrls, Grids, DBGrids, DB;type
TFormMain = class(TForm)
DBGrid1: TDBGrid;
Panel1: TPanel;
LabeledEdit1: TLabeledEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
bplHandle: Cardinal;
DM: IDMSearch;
end;var
FormMain: TFormMain;implementation{$R *.dfm}procedure TFormMain.Button1Click(Sender: TObject);
var
ds: TDataSource;
begin
ds:=DM.Search(StrToIntDef(LabeledEdit1.Text, -1));
DBGrid1.DataSource := ds;
end;procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
DM := nil;
// UnloadPackage(bplHandle);
end;procedure TFormMain.FormCreate(Sender: TObject);
var
c: TClass;
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
bplHandle := LoadPackage('DBM.bpl');
c:= GetClass('TDM');
if c <> nil then
DM := TComponentClass(c).Create(Application) as IDMSearch;
end;end.frmMain.dfmobject FormMain: TFormMain
Left = 0
Top = 0
Caption = 'FormMain'
ClientHeight = 237
ClientWidth = 246
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 246
Height = 184
Align = alClient
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object Panel1: TPanel
Left = 0
Top = 184
Width = 246
Height = 53
Align = alBottom
BevelInner = bvRaised
BevelOuter = bvLowered
TabOrder = 1
object LabeledEdit1: TLabeledEdit
Left = 8
Top = 20
Width = 146
Height = 21
EditLabel.Width = 25
EditLabel.Height = 13
EditLabel.Caption = 'Code'
TabOrder = 0
end
object Button1: TButton
Left = 160
Top = 16
Width = 75
Height = 25
Caption = #26597#35810
TabOrder = 1
OnClick = Button1Click
end
end
endProject1.dprprogram Project1;uses
Forms,
frmMain in 'frmMain.pas' {FormMain},
untIntf in '..\intf\untIntf.pas';{$R *.res}begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TFormMain, FormMain);
Application.Run;
end.通用接口[jie kou]单元[dan yuan]代码[dai ma]:untIntf.pasunit untIntf;interfaceuses
Classes, SysUtils, DB;type
IDMSearch = interface
['{494B4378-A373-4BAD-95D6-49CC12F76ADF}']
function Search(ACode: Integer): TDataSource;
end;implementationend.
如果与ado思路类似,应该:
db连所有的dataset(table),再连对应的datasource,再连各个dbgrid/dbedit之类的界面了
1. 先要安装ABSolute DB的ODBC驱动
2. 在ODBC驱动的安装文件中找找,看有没它的参考文档,进去看看相应的连接字符串的格式就OK了