如何进行三层开发(100分)

  • 主题发起人 主题发起人 鸡毛一地
  • 开始时间 开始时间

鸡毛一地

Unregistered / Unconfirmed
GUEST, unregistred user!
如何进行三层开发
 
楼主的问题太大了```建议先找本书啃
 
delphi下面有demo,clent-----com+----------database
 
有100分喔,要来说一下才行.
这是我的新号希望得到楼主的支持
 
三层数据库包括(客户端,数据库服务器,应用服务器)
由于三层开发技术比较多,在这里只简单介绍一下基于MTS/Dcom的数据库技术
 
启动delphi
file/new/other 打开new对话框,激活muliter选项卡,用remote data module wizard 创建远程数据库模块,另外一个是支持MTS技术的.
-点击DataSnap,拉一个TDcomconntection组件放窗体From1上,设置computer,connected,loginprompt,server,servrguid等属性
具体自己看着就会了,也不难~~~~~
由于时间有限,姑且说到这吧,大富翁对这个有专题的.
 
请问客户端如何访问数据库呢?
 
建议你读李维的关于三层开发的书: DELPHI5分布式多层应用系统篇
 
http://www.delphifans.com/SoftView/SoftView_2108.html
是三層架構的
最好的辦法是要有系統的學習。
 
好像我还没分呢~~~~
我可以给你简单的例子做参考
在数据模块中,设置连接(这里主要是连接,其它的放在应用服务器上,这样,要维护就可以直接在应用服务器上.
 
首先建立远程数据模块`~~
 
引用的窗体单元代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
private
{ Private declarations }
public
{ Public declarations }
procedure addmessage(s:string);
end;

var
Form1: TForm1;
implementation
uses Unit2, Project1_TLB;
{$R *.dfm}
procedure Tform1.addmessage(s:string);
begin
form1.Memo1.Lines.Add(s);
end.
 
远程数据库模块代码:
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, Provider, DB, DBTables;
type
TDcom = class(TRemoteDataModule, IDcom)
Database1: TDatabase;
Query1: TQuery;
DataSetProvider1: TDataSetProvider;
procedure RemoteDataModuleCreate(Sender: TObject);
procedure DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
public
{ Public declarations }
end;

implementation
uses Unit1;
{$R *.DFM}
class procedure TDcom.UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;

procedure TDcom.RemoteDataModuleCreate(Sender: TObject);
begin
with database1do
begin
databasename:='dbdemos';
connected:=true;
end;
with
query1do
begin
databasename:='dbdemos';
close;
sql.clear;
sql.add('select * from animals');
open;
end;
datasetprovider1.dataset:=query1;
end;

procedure TDcom.DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
var s:string;
begin
s:=datetimetostr(now)+':数据已经发送到客户端';
form1.addmessage(s);
end;

initialization
TComponentFactory.Create(ComServer, TDcom,
Class_Dcom, ciMultiInstance, tmApartment);
end.
 
可以更进一步,随便你要发多少信息都可以设置的.
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, Provider, DB, DBTables;
type
TDcom = class(TRemoteDataModule, IDcom)
Database1: TDatabase;
Query1: TQuery;
DataSetProvider1: TDataSetProvider;
procedure RemoteDataModuleCreate(Sender: TObject);
procedure DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
procedure DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
public
{ Public declarations }
end;

implementation
uses Unit1;
{$R *.DFM}
class procedure TDcom.UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;

procedure TDcom.RemoteDataModuleCreate(Sender: TObject);
begin
with database1do
begin
databasename:='dbdemos';
connected:=true;
end;
with
query1do
begin
databasename:='dbdemos';
close;
sql.clear;
sql.add('select * from animals');
open;
end;
datasetprovider1.dataset:=query1;
end;

procedure TDcom.DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
var s:string;
begin
s:=datetimetostr(now)+':数据已经发送到客户端';
form1.addmessage(s);
end;

procedure TDcom.DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
var s:string;
begin
s:=datetimetostr(now)+':数据准备完成';
form1.addmessage(s);
end;

initialization
TComponentFactory.Create(ComServer, TDcom,
Class_Dcom, ciMultiInstance, tmApartment);
end.
 
创建客户端程序
新建一个delphi工程
组件的话,看代码就知道要用哪些了.
 
数据单元DM上三个组件 Tdatasource,Tclientdataset,Tdcomconnection.
客户端一个Tdbgrid等.
 
属性设置:
Tclientdataset:
remoteserver:dcomconnection1
providername:datasetprovider1
active:true
Tdatasource
dataset:clientdataset1
Tdcomconnection
computer:(本机名)
servername:(远程服务器)
connected:true;
其它的自己看着办吧!!!!
 
注意要先连接再设当前数据集为true
 
我们有一个通用的分布式开发中间件,大家感兴趣可以下载测试一下
例程下载www.szmax.net/webpush-8.htm
 
后退
顶部