3

この関数を追加したいデータモジュール (TfDB) があります。

 Function GetZone(zone :string):string;

実行しようとすると、このエラーが発生します... 外部宣言の前方に満足していません: TfDB.GetZone

unit MyDataModule;

interface

uses
  System.SysUtils, System.Classes, Data.DB, Data.Win.ADODB;

type
  TfDB = class(TDataModule)
    dbconnection: TADOConnection;
  private
    { Private declarations }
  public
          Function GetZone(zone :string):string;
  end;

var
  fDB: TfDB;

implementation

{%CLASSGROUP 'System.Classes.TPersistent'}

{$R *.dfm}

  Function GetZone(zone:string):string;
  begin
  if zone = 'FLayout1' then
        result := '1';
  if zone = 'FLayout2' then
      result := '2';
  if zone = 'FLayout3' then
      result := '3';
  if zone = 'FLayout4' then
      result := '4' ;
  if zone = 'FBoneYard' then
      result := 'BoneYard';
  if zone = 'FShop' then
      result := 'shop';
  if zone = 'FMisc' then
      result := 'Misc' ;
  end;

end.
4

1 に答える 1

5

実装セクションでは、関数をクラスのメソッドとして宣言する必要があります。

function TfDB.GetZone(zone:string):string;
begin
  ....
end;

宣言は次のようになります。

function GetZone(zone:string):string;
begin
  ....
end;

そして、それはクラスのメソッドではなくスタンドアロン関数を定義します。

于 2013-01-20T11:56:12.770 に答える