我现在写了一个C语言的接口:
#ifdef MONTITOR_DLL_EXPORT
#define MONITOR_EXPORT __declspec(dllexport)
#else  
#define MONITOR_EXPORT __declspec(dllimport)
#endifextern "C"
{
  MONITOR_EXPORT int HelloWorld(int age);
}我的DLL名称是abc.dll我现在想在Delphi中调用这个接口,我先把DLL文件拷贝到Delphi的工程里面,然后申明如下:
type
  function HelloWorld(int age):integer;cdecl;external 'abc.dll';然后在
procedure TForm2.Button1Click(Sender: TObject);
var
t : integer;
m : integer;
begin
  t := 10;
  m := HelloWorld(t);
end;但是这样做报错了:[DCC Error] Unit1.pas(63): E2169 Field definition not allowed after methods or properties
请问是什么原因呢?

解决方案 »

  1.   

    function HelloWorld(age: integer):integer;cdecl;external 'abc.dll';
      

  2.   

    不好意思,刚才发帖的时候写错了,我在Delphi中的声明就是
    function HelloWorld(age: integer):integer;cdecl;external 'abc.dll';请问你的QQ,多少?我加你
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
        ExchangeIsTradeDay: TComboBox;
        StaticText1: TStaticText;
        StaticText2: TStaticText;
        IsTradeDayEdit: TEdit;
        ButtonIsTradeDay: TButton;
        StaticText3: TStaticText;
        Edit2: TEdit;
        StaticText4: TStaticText;
        ComboBox2: TComboBox;
        StaticText5: TStaticText;
        Edit3: TEdit;
        Button2: TButton;
        StaticText6: TStaticText;
        Edit4: TEdit;
        StaticText7: TStaticText;
        ComboBox3: TComboBox;
        StaticText8: TStaticText;
        Edit5: TEdit;
        Button3: TButton;
        StaticText9: TStaticText;
        Edit6: TEdit;
        StaticText10: TStaticText;
        Edit7: TEdit;
        StaticText11: TStaticText;
        StaticText12: TStaticText;
        ComboBox4: TComboBox;
        Button4: TButton;
        StaticText13: TStaticText;
        ListBox1: TListBox;
        StaticText14: TStaticText;
        ListBox2: TListBox;
        StaticText15: TStaticText;
        ListBox3: TListBox;
        StaticText16: TStaticText;
        ComboBox5: TComboBox;
        Button5: TButton;
        StaticText17: TStaticText;
        StaticText18: TStaticText;
        StaticText19: TStaticText;
        ListBox4: TListBox;
        ListBox5: TListBox;
        ListBox6: TListBox;
        StaticText20: TStaticText;
        ComboBox6: TComboBox;
        Button6: TButton;
        ListBox7: TListBox;
        ListBox8: TListBox;
        StaticText21: TStaticText;
        StaticText22: TStaticText;
        StaticText23: TStaticText;
        ListBox9: TListBox;
        StaticText24: TStaticText;
        function HelloWord(m: integer):integer;cdecl;external 'abc.dll'
        function CheckStringIsNumber(date: string):boolean;
        procedure ButtonIsTradeDayClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.dfm}function TForm2.CheckStringIsNumber(date: string):boolean;
    var
      I: integer;
    begin
        for I := 1 to length(date) do
        begin
           if(date[i] < '0') or (date[i] > '9') then
           begin
              Result := false;
              exit;
           end;
        end;
        Result := true;
    end;procedure TForm2.ButtonIsTradeDayClick(Sender: TObject);
    var
    Exchange : string;
    Date : string;
    temp : integer;
    begin
        Exchange := ExchangeIsTradeDay.Text;
        Date := IsTradeDayEdit.Text;
        if length(Date) <> 8 then
        begin
           showmessage('输入的日期不正确!');
           exit;
        end;
        if not CheckStringIsNumber(Date) then
        begin
           showmessage('输入的日期不正确!');
           exit;
        end;
        temp := HelloWord(100);end;end.
      

  4.   

    上面是全部的代码
    声明地方是:
    function HelloWord(m: integer):integer;cdecl;external 'abc.dll'
      

  5.   

    function HelloWord(m: integer):integer;cdecl;external 'abc.dll'var
      Form2: TForm2;声明不要放类里面。