再帮我看看包的问题! 老提示访问内存出错!

kl2000 2004-05-05 01:36:50
unit CommInterface;
//以下是用来测试的代码,可能写得有点乱,望谅解
//这是我定义的接口
interface

uses
Windows, Messages, SysUtils,Classes,ADODB;
type
IMYCommInterFace = interface(IDispatch)
['{768A344C-0331-41A4-87F3-8C2676A982A2}']
function GetAdoCnn: TADOConnection; stdcall;
function GetAdoQuery: TADOQuery; stdcall;
function ExcuteCommand(sSql: String): Boolean; stdcall;
end;
implementation
end.
//以下是接口的实现
unit OperationData;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ADODB,CommInterface;

type
TMYGolbData = class(TComponent,IMYCommInterFace)
private
FAdoCnn: TADOConnection;
FAdoQuery: TADOQuery;
public
function GetAdoCnn: TADOConnection; stdcall;
function GetAdoQuery: TADOQuery; stdcall;
function ExcuteCommand(sSQl: String): Boolean; stdcall;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;

implementation

uses Math, StrUtils, DB;
{ TGolbData }

constructor TMYGolbData.Create(AOwner: TComponent);
begin
inherited;
FAdoCnn := TADOConnection.Create(nil);
FAdoQuery := TADOQuery.Create(nil);
end;


destructor TMYGolbData.Destroy;
begin
FreeAndNil(FAdoQuery);
FreeAndNil(FAdoCnn);
inherited;
end;

function TMYGolbData.ExcuteCommand(sSql: String): Boolean;
begin
FAdoQuery.Connection := GetAdoCnn;
with FAdoQuery do
begin
Close;
SQL.Text := sSQl;
Open;
end;
end;

function TMYGolbData.GetAdoCnn: TADOConnection;
begin
Result := FAdoCnn;
end;

function TMYGolbData.GetAdoQuery: TADOQuery;
begin
Result := FAdoQuery;
end;

initialization
RegisterClass(TMYGolbData);

finalization
UnRegisterClass(TMYGolbData);

end.
//下面则是加载包和调用接口
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, StdCtrls, Buttons,OperationData, ADODB,
CommInterface;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
DataOp: TMYGolbData;
FICommInterFace: IMYCommInterFace;
HPbl:THandle;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

HPbl := LoadPackage('PackOperationData.bpl');
if HPbl1 <> 0 then
DataOp := TMYGolbData(TComponentClass(FindClass('TMYGolbData'))).Create(nil);

FICommInterFace := DataOp as IMYCommInterFace ;
FICommInterFace.GetAdoCnn.ConnectionString := 'Provider=SQLOLEDB.1;Integrated Security=SSPI;' +
'Persist Security Info=False;Initial Catalog=TEST;Data Source=KK2000';
FICommInterFace.GetAdoCnn.Open;

DataSource1.DataSet := FICommInterFace.GetAdoQuery;
FICommInterFace.ExcuteCommand('select * from Node')

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DataOp.Free;
UnloadPackage(HPbl1);
end;

end.
...全文
31 15 点赞 打赏 收藏 举报
写回复
15 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kl2000 2004-05-11
UP !!!
  • 打赏
  • 举报
回复
kl2000 2004-05-10
UP! 我顶得好累啊!
  • 打赏
  • 举报
回复
kl2000 2004-05-10
UP !
  • 打赏
  • 举报
回复
maskmaxmax 2004-05-08
再up
  • 打赏
  • 举报
回复
kl2000 2004-05-08
再 UP!
  • 打赏
  • 举报
回复
newfang 2004-05-08
up
  • 打赏
  • 举报
回复
kl2000 2004-05-08
不管怎样都好! 帮忙 UP 一下!
  • 打赏
  • 举报
回复
viaboy 2004-05-07
你调用的包是用DELPHI写的吗?你写的接口中的方法和变量是不是和包里的一样。
  • 打赏
  • 举报
回复
zhlwyy 2004-05-07
学习!
  • 打赏
  • 举报
回复
kl2000 2004-05-07
再顶!
  • 打赏
  • 举报
回复
kl2000 2004-05-07
大伙们明天应该上班了吧! UP!
  • 打赏
  • 举报
回复
kl2000 2004-05-07
楼上的大哥哥: 你没有看我贴出来的代码吗??
  • 打赏
  • 举报
回复
kl2000 2004-05-06
UP!
  • 打赏
  • 举报
回复
qizhanfeng 2004-05-06
学习
up
  • 打赏
  • 举报
回复
kl2000 2004-05-05
呵!·忘记说了.
接口是定义在包:PackInterface.bpl
接口的实现定义在包: PackOperationData.bpl
调用包是Exe.

OK! 等待你的回答!
  • 打赏
  • 举报
回复
相关推荐
发帖
Delphi
加入

4969

社区成员

Delphi 开发及应用
申请成为版主
帖子事件
创建了帖子
2004-05-05 01:36
社区公告
暂无公告