您好,在DLL中应该怎样操作数据库 ?需要注意哪些地方 ? 谢谢(20分)

  • 主题发起人 主题发起人 驿路的梦
  • 开始时间 开始时间
驿

驿路的梦

Unregistered / Unconfirmed
GUEST, unregistred user!
如题:),谢谢您
 
学习,我也在写一个数据库开发平台,把所有客户端、服务端放在dll里面,只留一个
exe调用 他们。
 
楼上,您好,您怎么作的能大概说一下思路吗? 我还一点不懂,谢谢您
 
如果你用 ADO,那么要在单元初始化部分调用 CoInitialize

 
我在
Begin
CoInitialize(Nil) ;
end .

编译提示: [Error] DLLDB.dpr(56): Undeclared identifier: 'CoInitialize'
为什么 ? 还应该注意什么 ?

谢谢
 
1. uses Windows
2. 不要在 begin 里面,在单元的 initialization 部分,要是没有看到这个单词,
添加一个。
 
平台主要针对c/s 结构,
客户端:
一个大厅(exe主要负责掉用dll中的窗体);
一堆分类过的dll,比如仓库管理一个dll,销售一个dll,
每个dll都包含一堆窗体,里面也可以有数据模块(dm),
这样做比较容易管理,调试,比如 几个人都在作仓库,但是
不同的模块,如果采用exe 就很麻烦,但是采用dll 方式比较方便,
大家可以个人搞个人的form就行啦,至于其他的跟exe 开发一样的。
服务端:
一个或几个com+服务。
 
谢谢,谢谢beta 和 人在昆明 .

还是不对 :

Dll 部分:

uses
ShareMem,
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
DB,
ADODB;
{$R *.res}

const
DbConnectionString = 'Provider=SQLOLEDB.1;Persist Security Info=False;'
+ 'User ID=sa;Initial Catalog=DBK;Data Source=MyPc ';

function Count(TableName: string): Integer; stdcall;
begin
with TADOQuery.Create(nil) do
begin
try
begin
ConnectionString := DbConnectionString;
Sql.Text := 'select count(*) from ' + TableName;
Open;
Result := RecordCount;
end;
finally
Free;
end;
end;
end;

Exports

Count ;

initialization
CoInitialize(Nil) ;
begin
end.

编译提示:
[Error] DLLDB.dpr(54): 'BEGIN' expected but 'INITIALIZATION' found


望大家指导,谢谢
 
INITIALIZATION 部分放在 begin end. 后面试一试?
 
谢谢您:),编译通过了,待会儿重启一下试试看效果:),DLL中操作数据库还有其他要
注意的地方吗 ? 谢谢您 。

您能否帮我看看
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1564741
还有其他几个贴子 :),添麻烦了,谢谢您
 
呵呵,你这种玩法会把自己搞死的,还是写com+ 接口吧。
 
beta : 您好,很遗憾没有通过 。代码如下 :
------------------------------------------------------
DLL :
library DLLDB;
uses
ShareMem,
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
DB,
ADODB;
{$R *.res}

const
DbConnectionString = 'Provider=SQLOLEDB.1;Persist Security Info=False;'
+ 'User ID=sa;Initial Catalog=Sms_Ga;Data Source=FRESHMAN ';

function Count(TableName: string): Integer; stdcall;
begin
with TADOQuery.Create(nil) do
begin
try
begin
ConnectionString := DbConnectionString;
Sql.Text := 'select count(*) from ' + TableName;
Open;
Result := RecordCount;
end;
finally
Free;
end;
end;
end;

Exports

Count ;
begin
end.
initialization
CoInitialize(Nil) ;
------------------------------------------------------
调用:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
function Count(TableName: string): Integer; stdcall;external 'F:/changshiF/DLL/DLL_数据库/DLLDB.dll' ;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Count('reguser'))) ;
end;

提示还是 :[Error] DLLDB.dpr(56): Undeclared identifier: 'CoInitialize' 为什么呢?
我重启了几次了 ,难道在DLL中不能操作数据库 ? 不是呀 ? 该怎么作 ?


人在昆明 : 您好,Com 我还没有学 ,现在想学在DLL中操作数据库还有其他,你觉得为何
这样做会“把自己搞死” ? 望指导
 
你这样做只是为了返回一个 Integer;呵呵!
以后有更复杂的需求你还不被搞死掉!
 
我只是为了想知道能否在DLL中操作数据库 ?

如果可以返回RecordCount ,那我像也可以Insert,Update 等

是不是 ?

程序哪儿错了 ?

谢谢
 
当然可以,CoInitialize定义在ComObj还是Activex单元.
另外你可以在调用DLL函数的线程中调用这个函数.
 
xeen : 您好,就我上边的代码,您觉得哪儿错了? 谢谢
 
uses 加上ComObj和Activex?
 
我试试 :) 谢谢您
 
还是不行,错误提示一样

怎么办 ?
 

Similar threads

S
回复
0
查看
751
SUNSTONE的Delphi笔记
S
S
回复
0
查看
758
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部