Delphi 助手作用域

Pau*_*aul 5 delphi helper delphi-xe5

我在 Delphi 中重新声明 helper 时遇到问题。

HelperDecl.pas

unit HelperDecl;

interface

type
  TCustomField = Word;

  TCustomFieldHelper = record helper for TCustomField
  public
    procedure SampleMethod();
  end;

implementation

procedure TCustomFieldHelper.SampleMethod();
begin
end;

end.
Run Code Online (Sandbox Code Playgroud)

ScopeTest.pas

unit ScopeTest;

interface

uses HelperDecl;

type
  rec = record
    art: TCustomField;
  end;

implementation

uses System.SysUtils;

procedure DoScopeTest();
var
  a: TCustomField;
  r: rec;
begin
  a := r.art;
  r.art.SampleMethod(); //Here has the compiler no problems
  a.SampleMethod(); //Undeclared identifier 'SampleMethod'
end;

end.
Run Code Online (Sandbox Code Playgroud)

但是我只为我的本地数据类型定义了一个助手(是的,它是从 Word 派生的)!中的助手SysUtils是 的助手Word,而不是我的自定义数据类型!放开我的数据类型!

当我uses System.SysUtils;在此之前移动时,uses HelperDecl;它会起作用。但我想有一个任意的单位使用顺序。

And*_*and 7

问题是TCustomFieldWord是相同的类型,并且不可能有两个相同类型的记录助手。

如果您改为TCustomField使用不同的类型,它将起作用:

type
  TCustomField = type Word;
Run Code Online (Sandbox Code Playgroud)