【发布时间】:2018-04-17 12:40:46
【问题描述】:
如果这段代码有什么问题,我只想在记录里面放一个程序:
unit unTEFTipos;
interface
type
TTEFPagamento = record
AcrescimoDesconto: Double;
TrocoSaque: Double;
procedure Clear;
end;
implementation
procedure TTEFPagamento.Clear;
begin
AcrescimoDesconto := 0;
TrocoSaque := 0;
end;
end.
但 Delphi 7 IDE 返回此错误:
Build
[Error] unTEFTipos.pas(10): 'END' expected but 'PROCEDURE' found
[Error] unTEFTipos.pas(11): 'IMPLEMENTATION' expected but ';' found
[Error] unTEFTipos.pas(13): '.' expected but 'IMPLEMENTATION' found
[Error] unTEFTipos.pas(10): Unsatisfied forward or external declaration: 'Clear'
[Fatal Error] GP.dpr(486): Could not compile used unit 'TEF\unTEFTipos.pas'
【问题讨论】:
-
Delphi 7 不允许记录方法,这种语法是在 D2006 中引入的。
-
虽然我在编辑后投票决定重新打开,但指出this question 可能是合适的,这就是答案。简而言之,您正在尝试使用 D7 中不存在的语言功能。如果您希望能够使用现代功能,请升级到现代版本的 Delphi。在 D7 中做你想做的唯一方法是使用类而不是记录。
-
在旧版本的 Delphi 中,如果要添加方法,则必须使用
object而不是record。