G
gdzscj
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个DLL程序发下,但在运行时出现内存错误的情况,请大家给我看看是什么问题?
library maildll;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
exports
codetogid;
begin
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB;
type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function codetogid(objects:string;code:string):integer;stdcall;
implementation
{$R *.dfm}
function codetogid(objects:string;code:string):integer;stdcall;
begin
form1.adoquery1.Close;
form1.adoquery1.SQL.Text:='select gid from '+objects+' where code='''+code+'''';
form1.adoquery1.Open;
if form1.adoquery1.RecordCount>0 then result:=form1.adoquery1.fieldbyname('gid').AsInteger else result:=0;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function codetogid(objects:string;code:string):integer;stdcall;external 'maildll.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=inttostr(codetogid('goods','03020060'));
end;
end.
library maildll;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
exports
codetogid;
begin
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB;
type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function codetogid(objects:string;code:string):integer;stdcall;
implementation
{$R *.dfm}
function codetogid(objects:string;code:string):integer;stdcall;
begin
form1.adoquery1.Close;
form1.adoquery1.SQL.Text:='select gid from '+objects+' where code='''+code+'''';
form1.adoquery1.Open;
if form1.adoquery1.RecordCount>0 then result:=form1.adoquery1.fieldbyname('gid').AsInteger else result:=0;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function codetogid(objects:string;code:string):integer;stdcall;external 'maildll.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=inttostr(codetogid('goods','03020060'));
end;
end.