dlL文件为:library DBConndll;{ 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,
Forms,
Classes,
Registry,
inifiles,
windows,
DataSet in 'pas单元\DataSet.pas' {frmDataSet};{$R *.res}
var
DLLapp: Tapplication;procedure DBSet(App: Tapplication); stdcall;
begin
DLLapp:=application;
application:= App try
frmDataSet := tfrmDataSet.Create(application);
frmDataSet.ShowModal;
finally
frmDataSet.Free;
end;
application:=DLLapp;end;exports
DBSet;
begin
end.调用方代码为:
type
TDset=procedure(App:Tapplicaton);stdcall; {放在type TForm1 = class(TForm)上面了.}procedure TForm1.Button1Click(Sender: TObject);
var
Hinst: Thandle;
Tempstr: string;
Dset:TDset;
begin Hinst := loadlibrary(Pchar('DBConndll.dll')); //Load一个Dll,按文件名找。
try
if Hinst > 0 then
begin
Dset := Getprocaddress(Hinst,Pchar('DBSet'));
Dset(applicaton);
end
else
showmessage('DBConndll.dll没找到');
finally
FreeLibrary(Hinst);
end;运行会出错.
project DBconn.exe raised exception class EOLesysError with message '尚未调用
CoInitialize.',process stopped.user step or Run to comtinue;
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,
Forms,
Classes,
Registry,
inifiles,
windows,
DataSet in 'pas单元\DataSet.pas' {frmDataSet};{$R *.res}
var
DLLapp: Tapplication;procedure DBSet(App: Tapplication); stdcall;
begin
DLLapp:=application;
application:= App try
frmDataSet := tfrmDataSet.Create(application);
frmDataSet.ShowModal;
finally
frmDataSet.Free;
end;
application:=DLLapp;end;exports
DBSet;
begin
end.调用方代码为:
type
TDset=procedure(App:Tapplicaton);stdcall; {放在type TForm1 = class(TForm)上面了.}procedure TForm1.Button1Click(Sender: TObject);
var
Hinst: Thandle;
Tempstr: string;
Dset:TDset;
begin Hinst := loadlibrary(Pchar('DBConndll.dll')); //Load一个Dll,按文件名找。
try
if Hinst > 0 then
begin
Dset := Getprocaddress(Hinst,Pchar('DBSet'));
Dset(applicaton);
end
else
showmessage('DBConndll.dll没找到');
finally
FreeLibrary(Hinst);
end;运行会出错.
project DBconn.exe raised exception class EOLesysError with message '尚未调用
CoInitialize.',process stopped.user step or Run to comtinue;
解决方案 »
- 请教 windows 2000 下DCOM 连接服务器出现问题
- Excel曲线图坐标问题,高人请进,解决即给分
- 如何显示所有的windows 服务,并清除掉不用的服务。谢谢
- 谁有AliasEditor这个控件?????
- 写字板中如何在状态栏中显示当前所在的行以及总字节数
- 求救!!!!如何用delphi创建快捷方式和在“开始”中添加菜单
- Rave报表对象对应着那些类,怎样获得Rave报表对象中的组件并对他们编程?
- 在query中用sql语句,除了加减乘除和sum,avg,count等函数外,有无办法使用sqr,sqrt,乘方等运算。(实在没有时间去编解析字符串的工作),请
- 《程序员》更名《蓝领》
- zswang(伴水)(需要充充电)请进
- 急!每打印一页就下偏2CM,打N篇就下偏N*2CM
- 以前用ADO的时候有查询字段,现在用odac的查询控件,那里可以设置查询字段啊??????请各位老大指点
procedure DBSet(); stdcall;
begin
try
frmDataSet := tfrmDataSet.Create(nil);//这里完全可以不指定属主
frmDataSet.ShowModal;
finally
frmDataSet.Free;
end;
end;
project DBconn.exe raised exception class EOLesysError with message '尚未调用
CoInitialize.',process stopped.user step or Run to comtinue;
这个是什么错误,为什么会出现这个错误?弄明白了,以后碰到这样的问题就能知道了.就不用再烦大家了.
frmDataSet主要功能是设置数据库连接 代码如下.
unit DataSet;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB, ADODB, Registry, inifiles;type
TfrmDataSet = class(TForm)
GroupBox1: TGroupBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Edit_ServerName: TEdit;
Label1: TLabel;
Edit_LoginName: TEdit;
Edit_LoginPW: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Label4: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
ADOConnection_Server: TADOConnection;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure RadioButton1Click(Sender: TObject);
private
strDBName: string;
Application_name: string;
{ Private declarations }
public
//function GetDBprivde(App: TApplication): Pchar;
{ Public declarations }
end;var
frmDataSet: TfrmDataSet;implementation{$R *.dfm}procedure TfrmDataSet.BitBtn3Click(Sender: TObject);
begin
self.ADOConnection_Server.Connected:=false;
//CloseWindow(Application.Handle);
Application.Terminate;
end;procedure TfrmDataSet.BitBtn1Click(Sender: TObject);
begin
strDBName := Trim(Edit1.Text);
screen.Cursor := crHourGlass;
try
ADOConnection_Server.Connected := False;
if self.RadioButton2.Checked then
ADOConnection_Server.ConnectionString := 'Provider=SQLOLEDB.1;' +
'Persist Security Info=False;' +
'User ID=' + Trim(Edit_LoginName.Text) +
';Password=' + Trim(Edit_LoginPW.Text) +
';Initial Catalog=' + strDBName +
';Data Source=' + Trim(Edit_ServerName.Text) + ''
else
ADOConnection_Server.ConnectionString := 'Provider=SQLOLEDB.1;' +
'Integrated Security=SSPI;' +
'Persist Security Info=False;' +
'User ID=sa;' +
'Initial Catalog=' + strDBName +
';Data Source=' + Trim(Edit_ServerName.Text) + '';
ADOConnection_Server.Connected := True;
MessageBox(Handle, '数据库连接成功!', '系统提示', 0);
except
MessageBox(Handle, '数据库连接失败!', '系统提示', 0);
end;
screen.Cursor := crDefault;
end;procedure TfrmDataSet.FormShow(Sender: TObject);
var
Reg: TRegistry;
strComputerName: pChar;
lLen: DWORD;
begin with Tinifile.Create(Extractfilepath(application.exename)+'DBCon.ini') do
begin
Application_name := ReadString('Application', 'exename', '');
free;
end;
if Application_name = '' then
begin
application.MessageBox('DBCon.ini文件没找到,或配置不正确', '提示', 48);
exit;
end; Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER; //判断该注册表项是否存在
if (Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\' + Application_name, false)) = false then
if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion', True) then
begin
//不存在 则新建注册表项
Reg.CreateKey(Application_name);
Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\' + Application_name, True);
lLen := 255;
GetMem(strComputerName, 255);
GetComputerName(strComputerName, lLen);
Reg.WriteString('ServerName', strPas(strComputerName)); //初始化 [数据服务器名] 项的值
Reg.WriteString('constype', 'userpsw'); //保存设置
Reg.WriteString('LoginName', 'sa'); //初始化 [登录用户名] 项的值
Reg.WriteString('LoginPW', ''); //初始化 [登录口令] 项的值
Reg.WriteString('DataBaseName', ''); //数据库名
FreeMem(strComputerName);
end;
//读取 ServerName 项的值 并显示
Edit_ServerName.Text := Trim(Reg.ReadString('ServerName'));
if Trim(Reg.ReadString('constype')) <> 'userpsw' then
begin
RadioButton1.Checked := true;
Edit_LoginName.Enabled := false;
Edit_LoginPW.Enabled := false;
end;
//读取 LoginName 项的值 并显示
Edit_LoginName.Text := Trim(Reg.ReadString('LoginName'));
//读取 LoginPW 项的值 并显示
Edit_LoginPW.Text := Trim(Reg.ReadString('LoginPW'));
//读取 LoginPW 项的值 并显示
Edit1.Text := Trim(Reg.ReadString('DataBaseName'));
Reg.CloseKey;
finally
Reg.Free;
end;
end;procedure TfrmDataSet.BitBtn2Click(Sender: TObject);
var
Reg: TRegistry;
SetBool: Boolean;
begin
strDBName := Trim(Edit1.Text);
try
ADOConnection_Server.Connected := False;
if self.RadioButton2.Checked then
ADOConnection_Server.ConnectionString := 'Provider=SQLOLEDB.1;' +
'Persist Security Info=False;' +
'User ID=' + Trim(Edit_LoginName.Text) +
';Password=' + Trim(Edit_LoginPW.Text) +
';Initial Catalog=' + strDBName +
';Data Source=' + Trim(Edit_ServerName.Text) + ''
else
ADOConnection_Server.ConnectionString := 'Provider=SQLOLEDB.1;' +
'Integrated Security=SSPI;' +
'Persist Security Info=False;' +
'User ID=sa;' +
'Initial Catalog=' + strDBName +
';Data Source=' + Trim(Edit_ServerName.Text) + '';
ADOConnection_Server.Connected := True;
MessageBox(Handle, '数据库连接成功!', '系统提示', 0);
SetBool := True;
except
MessageBox(Handle, '数据库连接失败!', '系统提示', 0);
SetBool := False;
end;
if not SetBool then exit;
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER; //判断该注册表项是否存在
if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\' + Application_name, True) then
begin
Reg.WriteString('ServerName', Trim(Edit_ServerName.Text)); //保存设置
if RadioButton1.Checked then
Reg.WriteString('constype', 'SSPI') //保存设置
else
Reg.WriteString('constype', 'userpsw'); //保存设置
Reg.WriteString('LoginName', Trim(Edit_LoginName.Text));
Reg.WriteString('LoginPW', Trim(Edit_LoginPW.Text));
Reg.WriteString('DataBaseName', Trim(Edit1.Text)); //数据库名
Reg.CloseKey;
end;
finally
inherited;
end;
Reg.Free;
self.ADOConnection_Server.Connected:=false;
//MessageBox(Handle,'数据库连接成功,请重新启动主系统!','系统提示',0);
Close;
end;procedure TfrmDataSet.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
//Ctrl + A 修改数据库登录名
if (ssCtrl in Shift) and (Key = Ord('A')) then
self.Edit_LoginName.Enabled := True;
end;procedure TfrmDataSet.RadioButton1Click(Sender: TObject);
begin
Edit_LoginName.Enabled := RadioButton2.Checked;
Edit_LoginPW.Enabled := RadioButton2.Checked;
end;end.