freepascal - 在其他单元重新声明类型助手,Free Pascal 编译失败
问题描述
我有这个单位
unit helper;
interface
{$MODE OBJFPC}
{$MODESWITCH TYPEHELPERS}
{$H+}
uses
sysutils;
type
THelloWorldHelper = type helper(TStringHelper) for string
public
function world() : string;
end;
implementation
function THelloWorldHelper.world() : string;
begin
result := self + ' world';
end;
end.
和其他重新声明此类型助手的单元
unit helperalias;
interface
{$MODE OBJFPC}
{$MODESWITCH TYPEHELPERS}
{$H+}
uses
helper;
type
THelloWorldHelper = helper.THelloWorldHelper;
implementation
end.
和程序如下
program helloworld;
{$MODE OBJFPC}
{$MODESWITCH TYPEHELPERS}
{$H+}
uses
helperalias;
var hello : string;
world :string;
begin
hello:='hello';
world := hello.world();
writeln(world);
end.
当我跑
fpc helloworld.pas
它拒绝用 message 编译Error: Objective-C categories and Object Pascal class helpers cannot be used as types
。
如果在 中helloword.pas
,我将helperalias
unit替换为helper
,它可以工作。
我读到了助手限制。
为什么禁止重新声明类型助手?
解决方案
推荐阅读
- python - Python Treemap 自定义比例色标
- unix - 如何使用 awk 计算多列(按行)的最大值和最小值
- javascript - TypeError:无法读取未定义的属性“地图”。反应
- android - 如何将 viewModel 范围限定为与 NavHost 无关的 Dialog Composable Function
- flutter - Hive Flutter 的权限和路径
- centos - 无法访问 CPanel
- arrays - jq:错误(在
:11625): 无法遍历字符串 ("true") JQ 命令行 - indy - TIdNTLMAuthentication 与 TIdHTTP 以外的其他内容
- sql - 从字符串列中提取总小时数的 SQL 解决方案
- javascript - 在 React.js 中执行 GET 请求