送分!!!简单DLL调用 ( 积分: 50 )

H

hunzean

Unregistered / Unconfirmed
GUEST, unregistred user!
我调用DLL的源码如下:
unit UntMain;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function GetRecordCount:integer;cdecl
external
'testdll.dll';//这句出错
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := inttostr(GetRecordCount);
end;

end.
编译时无法通过。
[Error] Field definition not allowed after methods or properties
请问各位是什么问题?
 
我调用DLL的源码如下:
unit UntMain;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function GetRecordCount:integer;cdecl
external
'testdll.dll';//这句出错
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := inttostr(GetRecordCount);
end;

end.
编译时无法通过。
[Error] Field definition not allowed after methods or properties
请问各位是什么问题?
 
function GetRecordCount:integer;cdecl
external 'testdll.dll';
//多了个;external后只要加空格就可;
 
function GetRecordCount:integer;cdecl
external 'testdll.dll';
这样也不行,错误信息一样
 
public
{ Public declarations }
end;

function GetRecordCount:integer;cdecl
external
'testdll.dll';//这句出错
var
Form1: TForm1;
 
将Function 提前放到,TYPE下(PRIVate之前);
如果有定义单元,则要在第一个USES子句加上;
 
function GetRecordCount:integer;cdecl
external
'testdll.dll';
不能作为Form1的函数,单独放到 Var 之前就可以
 
通常是建立一个单元如 DLLFUN.pas,将所有的过程或函数集中;
unit DLLFUN;

interface
//uses DLLDef;//如果有共用结构定义
function GetRecordCount:integer;cdecl
external 'testdll.dll';
implementation

end.
只要在调用单元的interface之uses子句中加上DLLFUN就行了;
cdecl是用来调用C,VC等其他系统编译成的DLL;
 
没有仔细看呢。
 
把function函数放在implementation前面
 
外部函数不是类里面的方法(Method),所以通常应该将外部函数声名放在Class外。可以试一下将其声名成类方法(Class Method)试试看,即 Class function GetRecordCount:integer;cdecl
external
'testdll.dll';
 
应该将Function 提前放到,TYPE下(PRIVate之前);
试试吧
 
把那两行换一下,就可以了:
……
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function GetRecordCount:integer;cdecl
external
'testdll.dll';//这句出错
end;

var
Form1: TForm1;
……
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
703
import
I
I
回复
0
查看
715
import
I
I
回复
0
查看
611
import
I
I
回复
0
查看
615
import
I
I
回复
0
查看
496
import
I
顶部