請問我在聲明:function setlayeredwindowattributes (hwnd:hwnd;crkey:longint;balpha:byte;
    dwflags:longint):longint;stdcall;external user32;
出現錯誤提示:[Error] Ptimer.pas(15): Field definition not allowed after methods or properties
不知為何,大家可否幫忙解答一下,先謝過大家了。

解决方案 »

  1.   

    函数定义必须在字段定义后.
    例如:
    Type
      TFrm = class(TForm)
        Fa:integer;
        Fb:string;
        procedure P1;
        //Fb:string;如果出现在这儿就是错的.
        function F1(AA:string):integer;
      private
      end;
      

  2.   

    interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls,MENUS;type
      TForm1 = class(TForm)
        Image1: TImage;
        Button1: TButton;
        Timer1: TTimer;    procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        function setlayeredwindowattributes (hwnd:hwnd;crkey:longint;balpha:byte;
        dwflags:longint):longint;stdcall;external user32
      private
        { Private declarations }
        procedure wmnchittest(var msg:twmnchittest);message wm_nchittest;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    但還是報錯
      

  3.   

    On Windows: The following declaration imports a function from user32.dll (part of the Windows API).function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer;   stdcall; external 'user32.dll' name 'MessageBoxA';The function's original name is MessageBoxA, but it is imported as MessageBox.Instead of a name, you can use a number to identify the routine you want to import:external stringConstant index integerConstant;where integerConstant is the routine's index in the export table.
      

  4.   

    你是想调用DLL函数吧,我想这个函数你不能定义在类里面,把它放在类外面试试interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls,MENUS;type
      TForm1 = class(TForm)
        Image1: TImage;
        Button1: TButton;
        Timer1: TTimer;    procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);  private
        { Private declarations }
        procedure wmnchittest(var msg:twmnchittest);message wm_nchittest;
      public
        { Public declarations }
      end;      function setlayeredwindowattributes (hwnd:hwnd;crkey:longint;balpha:byte;
        dwflags:longint):longint;stdcall;external user32
    var
      Form1: TForm1;
      

  5.   

    On Windows: The following declaration imports a function from user32.dll (part of the Windows API).function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer;   stdcall; external 'user32.dll' name 'MessageBoxA';The function's original name is MessageBoxA, but it is imported as MessageBox.Instead of a name, you can use a number to identify the routine you want to import:external stringConstant index integerConstant;where integerConstant is the routine's index in the export table.
      

  6.   

    thank,你們太熱心了,我好愛你們喲!