library Native;uses
SysUtils,
Classes,
M0001 in 'M0001.pas' {FrmNative};Exports NativeShow;
{$R *.res}
beginend.unit m0001;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, DB, ADODB;type
TFrmNative = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
butsearchcode: TButton;
butsearchdesc: TButton;
EdSearchDesc: TEdit;
EditSearchCode: TEdit;
GroupBox3: TGroupBox;
DBGrid1: TDBGrid;
GroupBox4: TGroupBox;
butAddnew: TButton;
butEdit: TButton;
butDelete: TButton;
butRefresh: TButton;
butBrowse: TButton;
butQuit: TButton;
GroupBox5: TGroupBox;
Label3: TLabel;
Label4: TLabel;
EdEditCode: TEdit;
EdEditDesc: TEdit;
butUpdate: TButton;
butCancel: TButton;
ADOQuery1: TADOQuery;
DataSource1: TDataSource; private public
EditFlag:Boolean;
end;var
FrmNative: TFrmNative;Function NativeShow(DataConnect:String):WordBool;Export;
implementation{$R *.dfm}Function NativeShow(DataConnect:String):WordBool;
Begin
Result:=False;
ADOQuery1.ConnectionString:=DataConnect;
//DataConnect 相当于'Provider=SQLOLEDB.1;Password=test;Persist Security Info=True;User ID=test;Initial Catalog=test;Data Source=test'//我想通过调用函数传递数据库连接字符,但是编译时出错,不知如何解决
IF Application.FindComponent('FrmNative')=nil THEN
begin
FrmNative:=TFrmNative.Create(Application);
FrmNative.Show;
end
else
FrmNative.Show;end;end.
SysUtils,
Classes,
M0001 in 'M0001.pas' {FrmNative};Exports NativeShow;
{$R *.res}
beginend.unit m0001;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, DB, ADODB;type
TFrmNative = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
butsearchcode: TButton;
butsearchdesc: TButton;
EdSearchDesc: TEdit;
EditSearchCode: TEdit;
GroupBox3: TGroupBox;
DBGrid1: TDBGrid;
GroupBox4: TGroupBox;
butAddnew: TButton;
butEdit: TButton;
butDelete: TButton;
butRefresh: TButton;
butBrowse: TButton;
butQuit: TButton;
GroupBox5: TGroupBox;
Label3: TLabel;
Label4: TLabel;
EdEditCode: TEdit;
EdEditDesc: TEdit;
butUpdate: TButton;
butCancel: TButton;
ADOQuery1: TADOQuery;
DataSource1: TDataSource; private public
EditFlag:Boolean;
end;var
FrmNative: TFrmNative;Function NativeShow(DataConnect:String):WordBool;Export;
implementation{$R *.dfm}Function NativeShow(DataConnect:String):WordBool;
Begin
Result:=False;
ADOQuery1.ConnectionString:=DataConnect;
//DataConnect 相当于'Provider=SQLOLEDB.1;Password=test;Persist Security Info=True;User ID=test;Initial Catalog=test;Data Source=test'//我想通过调用函数传递数据库连接字符,但是编译时出错,不知如何解决
IF Application.FindComponent('FrmNative')=nil THEN
begin
FrmNative:=TFrmNative.Create(Application);
FrmNative.Show;
end
else
FrmNative.Show;end;end.
解决方案 »
- delphi7 要如何连接FOXPRO
- 在线程中更新窗体上的ListView控件上的内容,更新时如果不使用Synchronize(更新函数)就会抱错Code:1400,使用的话又会导致界面无响应
- 多线程访问数据库的问题,急救!!
- 如何发布程序,能直接浏览,急!在线!
- 一个好急的在程序中写存储过程的问题......^-^大家帮我.
- 急!悬赏解决DrawGrid问题!!!!!
- 如何在我的Delphi程序中加入一个ADO连接的功能?
- 我用的是Access数据库,现在记录有3000条,当form显示的时候打开数据库ADOQuery.Open但是要很久才能显示该form请问有什么办法解决,谢谢!!!
- 十万火急:动态联接库DLL疑难杂症-1
- 请各位大侠推荐几本学习Delphi的对初学者使用的好书,多谢了!!!
- 关于数据修改的问题(sql 2000+delphi 6.0)
- 如何定位数据指针,比如我新增一条记录,或者删除记录后,想定位指针大某个位置,ado的
你最好参考一下《Delphi 5开发人员指南》,了解一下Delphi中使用动态连接库的技巧和限制。在动态连接库中调用窗体,与在应用程序中调用窗体是不一样的!!!至少动态连接库中没有Application对象!!!
错误: function NativeShow(DataConnect:String):WordBool; Export;
正确: function NativeShow(DataConnect :PChar) :boolean; stdcall; export;
^^^^^ ^^^^^^^^^^^^^^^^^^
string 改 PChar 有必要, 因为这样才不要 borlndmm.dll
wordbool 没必要, boolean 返回是 integer, 就是非 0 就真
stdcall 重要!!! 不是 stdcall 的被认为是 __fastcall, 这个不能作 dll 导出, 问题是它也能正确执行, 但退出时才报错
function NativeShow(AppHandle :THandle; DataConnect :PChar) :boolean; stdcall; export;改实现
function NativeShow(AppHandle :THandle; DataConnect :PChar) :boolean; stdcall;
// 调用者要 Application.Handle 送到 AppHandle
begin
Application.Handle := AppHandle;
result := false;
// ADOQuery1.ConnectionString := DataConnect; 这是什么我始终不明白
if not Assigned(FrmNative) then // 利用那个全局变量
FrmNative := TFrmNative.Create(Application);
FrmNative.Show; // 没机会释放, 记得改 FrmNative的 OnClose 中加一句 Action := caFree;
end;
谢谢指点!但是我真正想知道的是如何通过function NativeShow(AppHandle :THandle; DataConnect :PChar) :boolean; 函数将DATACONNECT变量值传递到其它控件上.
if not Assigned(FrmNative) then
begin
FrmNative := TFrmNative.Create(Application);
FrmNative.XXXConnection.ConnectionString := DataConnect;
^^^^^^^^^, 建立好 Form 后, 里面变量谁你用(ps :[)
end