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

liyi212 2013-11-27 04:12:49
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
不知道哪的问题。

...全文
373 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyi212 2013-11-28
  • 打赏
  • 举报
回复
已解决,是最后一个写成end;。第一次接触delphi感觉好不灵活啊!!
hsfzxjy 2013-11-27
  • 打赏
  • 举报
回复
养成良好的代码习惯:一个begin一个缩进,一个end少一个缩进。匹不匹配自然就看出来了,这种问题要自己解决。
sololie 2013-11-27
  • 打赏
  • 举报
回复
你把完整的这个.pas文件的代码全部贴上来,或者自己ctrl+d代码格式化一下,就看到哪里错了,你这个提示64行自己也可以检查下
liyi212 2013-11-27
  • 打赏
  • 举报
回复
引用 2 楼 sololie 的回复:
谁让你不装个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;
老大,你的跟我的没区别啊。 我是新手,今天才开始接触。呵呵,不知道cnpack这个东东。 问题还是没解决哦!
sololie 2013-11-27
  • 打赏
  • 举报
回复
谁让你不装个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;
liyi212 2013-11-27
  • 打赏
  • 举报
回复
怎么没人呢,急 额 !

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧