一个DLL,请各位指点(50分)

  • 主题发起人 主题发起人 SamHunt
  • 开始时间 开始时间
S

SamHunt

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个DLL是关于数据库的,调用正常,但是调用程序关闭的时候就出现指针出错!
'Invalid pionter operation'

请各位指点一下?
//Dll Code

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
dxTL, dxDBCtrl, wwSpeedButton, wwDBNavigator, ExtCtrls, wwclearpanel,
dxCntner, dxDBTL, Db, ADODB, Grids, Wwdbigrd, Wwdbgrid, dxDBGrid,
ComCtrls;

type
TFJiLiang = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
dxDBGrid1: TdxDBGrid;
dxDBGrid1UnitID: TdxDBGridMaskColumn;
dxDBGrid1UnitName: TdxDBGridMaskColumn;
wwDBNavigator1: TwwDBNavigator;
wwDBNavigator1First: TwwNavButton;
wwDBNavigator1PriorPage: TwwNavButton;
wwDBNavigator1Prior: TwwNavButton;
wwDBNavigator1Next: TwwNavButton;
wwDBNavigator1NextPage: TwwNavButton;
wwDBNavigator1Last: TwwNavButton;
wwDBNavigator1Insert: TwwNavButton;
wwDBNavigator1Delete: TwwNavButton;
wwDBNavigator1Edit: TwwNavButton;
wwDBNavigator1Post: TwwNavButton;
wwDBNavigator1Cancel: TwwNavButton;
procedure dxDBGrid1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
FJiLiang: TFJiLiang;

Function UnitTable(Var AUnitName,AUnitID:String):WordBool;export;

implementation

{$R *.DFM}

procedure TFJiLiang.dxDBGrid1DblClick(Sender: TObject);
begin
ModalResult :=mrok;
end;

Function UnitTable(Var AUnitName,AUnitID:String):WordBool;export;
var
FJiLiang: TFJiLiang;
begin
Result:=false;
FJiLiang:=TFJiLiang.create(Application);
Try
if FJiLiang.ShowModal = mrok then
with FJiLiang do
begin
AUnitID:=dxDBGrid1.Items[dxDBGrid1.FocusedNode.Index].Strings[0];
AUnitName:=dxDBGrid1.Items[dxDBGrid1.FocusedNode.Index].Strings[1];
Result :=true;
end;
finally
FJiLiang.Free;
end;


end;



procedure TFJiLiang.FormCreate(Sender: TObject);
begin
ADOTable1.Active:=true;
end;

end.

//调用的程序编码
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
Function UnitTable(Var AUnitName,AUnitID:String):WordBool;far;External 'JiLianDanWei.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
TempA,TempB:string;
begin
TempA:='';
TempB:='';
if UnitTable(TempA,TempB) Then
Begin
button1.Caption:=TempA;
// Button2.Caption:=TempB;

end;

end;

end.
 
试试用PCHAR而不用STRING;或在USES中加SHAREMEM;
 
我试过了还是这样.
我怀疑是否关于ADO方面的问提?
但是调用DLL是没问提的,就是关闭调用的主程序时出现'该内存不能为'read'....'
 
我看可能是“Var AUnitName,AUnitID:String”的问题,Deplhi在写DLL的工程模板中就
提醒的不要用“String”做参数类型,要使用“PChar”或“ShortString”
 
把你的数据控件放到一个数据模板(Datamoudle)中,在开始调用DLL时创建,在退出时释放。
 
后退
顶部