读书人

delphi调用DLL提示异常[Error] Unit1.

发布时间: 2013-11-29 13:49:33 作者: rapoo

delphi调用DLL提示错误[Error] Unit1.pas(81): Declaration expected but end of file found
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

//开始调用TCP.DLL

procedure TForm1.Button1Click(Sender: TObject);
type
TIntFunc=function(i:integer):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;

begin
Th:=LoadLibrary('ZLDS200_TCP_DLL.dll'); {装载DLL}
if Th>0 then
begin
try
Tp:=GetProcAddress(Th,PChar('ZLDS200Connect'));
if Tp<>nil then
begin
Tf:=TIntFunc(Tp);
IntToStr(Tf(620)); {调用ZLDS200Connect函数}
end
else
ShowMessage('ZLDS200Connect函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end;
end
else
ShowMessage('ZLDS200_TCP_DLL.dll没有找到');
end;
好像是begin和end不匹配。
[Error] Unit1.pas(64): Declaration expected but end of file found
不知道哪的问题。

delphi,DLL
[解决办法]
谁让你不装个cnpack帮你检查拼写错误,为这种拼写错误的无效问题困扰实在是浪费时间好无意义


procedure TForm1.Button1Click(Sender: TObject);
type
TIntFunc = function(i: integer): integer; stdcall;
var
Th: Thandle;
Tf: TIntFunc;
Tp: TFarProc;
begin
Th := LoadLibrary('ZLDS200_TCP_DLL.dll'); {装载DLL}
if Th > 0 then
begin
try
Tp := GetProcAddress(Th, PChar('ZLDS200Connect'));
if Tp <> nil then
begin
Tf := TIntFunc(Tp);
IntToStr(Tf(620)); {调用ZLDS200Connect函数}
end
else
ShowMessage('ZLDS200Connect函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end;
end
else
ShowMessage('ZLDS200_TCP_DLL.dll没有找到');
end;

[解决办法]
你把完整的这个.pas文件的代码全部贴上来,或者自己ctrl+d代码格式化一下,就看到哪里错了,你这个提示64行自己也可以检查下
[解决办法]
养成良好的代码习惯:一个begin一个缩进,一个end少一个缩进。匹不匹配自然就看出来了,这种问题要自己解决。

读书人网 >.NET

热点推荐