----------------------------------------------------------
我的程序1,可以运行
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ConnFilesM(pw,user,db,computer:string) stdcall;external 'bin\ConnDBDll.dll';var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ConnFilesM('a','a','a','a');
end;end.
--------------------------------------------------------------------------------------------------------------------
把程序1改为多线程后,得程序2
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TConnDbThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Threads: TConnDbThread;
public
{ Public declarations }
end;
procedure ConnFilesM(pw,user,db,computer:string) stdcall;external 'bin\ConnDBDll.dll';var
Form1: TForm1;implementation{$R *.dfm}procedure TConnDbThread.Execute;
begin
ConnFilesM('a','a','a','a');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Threads:=TConnDbThread.Create(false);
end;end.
----------------------------------------------------------编译程序2时
提示:
project ***.exe raised exception class Eolesyserror with message"尚未调用coinitialize.",process stopped,use step or run to continue.这是为什么啊?尚未调用coinitialize说的是什么啊?
我的程序1,可以运行
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ConnFilesM(pw,user,db,computer:string) stdcall;external 'bin\ConnDBDll.dll';var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ConnFilesM('a','a','a','a');
end;end.
--------------------------------------------------------------------------------------------------------------------
把程序1改为多线程后,得程序2
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TConnDbThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Threads: TConnDbThread;
public
{ Public declarations }
end;
procedure ConnFilesM(pw,user,db,computer:string) stdcall;external 'bin\ConnDBDll.dll';var
Form1: TForm1;implementation{$R *.dfm}procedure TConnDbThread.Execute;
begin
ConnFilesM('a','a','a','a');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Threads:=TConnDbThread.Create(false);
end;end.
----------------------------------------------------------编译程序2时
提示:
project ***.exe raised exception class Eolesyserror with message"尚未调用coinitialize.",process stopped,use step or run to continue.这是为什么啊?尚未调用coinitialize说的是什么啊?
解决方案 »
- 等待所有线程结束
- Adotable连Excel,怎样控制选择每行每列数据?
- 请教DBCHART功能实现问题。。。
- 应用程序导致数据库查询变慢
- 关于grid的问题
- 怎样用“代码”把字符串型数组变量填写在在DBGrid/StringGrid中?
- ★★★Oracle BLOB字段的读问题★★★
- 哪里有DirectDraw的学习资料
- 我发的帖子找不到了,大家在帮帮我!
- 请问高手,在delphi中怎样控制其他窗体中的控件?比如,我想在主窗体中放上一个“关于我们”的按钮,点击他出来一个showmodal对话框,在对话框返回时我需要控制主窗体中的一个控件。这怎么实现。谢谢!
- 我使用showmodal时候出现的错误!
- 动态加载DLL时出现如下错误
估计你调用的Dll中有Com对象。
coinitialize(nil);
-------------------------------------------------------
library ConnDBDll;{ **}
uses
SysUtils,
Classes,
adodb,
Forms,ComObj;{$R *.res} Function GetSQLServerName:Variant;stdcall;
var
SQLServer: Variant;//uses comobj;
ServerList: Variant;
begin
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
Result:=ServerList;
end; procedure ConnFilesM(pw,user,db,computer:string) stdcall;
var connection:tadoconnection;
connstr:string;
begin
try
connection:=tadoconnection.Create(nil);
connstr:= 'Provider=SQLOLEDB.1;Password='+pw+';Persist Security Info=True;User ID='+user+';Initial Catalog='+db+';Data Source='+computer;
connection.ConnectionString:=connstr;
connection.LoginPrompt:=false;
connection.Connected:=true;
with Application do //uses Forms
begin
NormalizeTopMosts;
MessageBox('连接数据库成功!', '系统提示',0);
RestoreTopMosts;
end;
except
with Application do
begin
NormalizeTopMosts;
MessageBox('连接数据库失败!', '系统提示',0);
RestoreTopMosts;
end;
end;
end;
exports ConnFilesM,GetSQLServerName;
begin
end.
initialization
coinitialize(nil);
finalization
CoUninitialize;
只是DLL改成如下:
library ConnDBDll;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
adodb,
Forms,ComObj;{$R *.res} Function GetSQLServerName:Variant;stdcall;
var
SQLServer: Variant;//uses comobj;
ServerList: Variant;
begin
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
Result:=ServerList;
end; Function ConnFilesM(pw,user,db,computer:string):boolean; stdcall;
var connection:tadoconnection;
connstr:string;
begin
try
connection:=tadoconnection.Create(nil);
connstr:= 'Provider=SQLOLEDB.1;Password='+pw+';Persist Security Info=True;User ID='+user+';Initial Catalog='+db+';Data Source='+computer;
connection.ConnectionString:=connstr;
connection.LoginPrompt:=false;
connection.Connected:=true;
result := true;
with Application do //uses Forms
begin
NormalizeTopMosts;
MessageBox('连接数据库成功!', '系统提示',0);
RestoreTopMosts;
end;
except
result := false;
with Application do
begin
NormalizeTopMosts;
MessageBox('连接数据库失败!', '系统提示',0);
RestoreTopMosts;
end;
end;
end;
exports ConnFilesM,GetSQLServerName;
beginend.