我想使用带有自定义记录的TFPGLIST。我花了很长时间才能从互联网上获得必要的暗示来完成此小片段:
program Project1;
{$mode delphi}{$H+}
uses
fgl;
type
TSomeRecord = record
feld_1: Byte;
class operator Equal(Left, Right : TSomeRecord) Result : Boolean;
end;
class operator TSomeRecord.Equal (Left, Right: TSomeRecord) Result: Boolean;
begin
Result := Left.feld_1 = Right.feld_1;
end;
type
TypedList = TFPGList<TSomeRecord>;
var
x : TypedList;
begin
end.
您可以看到,问题是将平等运算符指定为记录。此外,这似乎仅在Delphi模式中。
假设我想在delphi模式中编写此程序,而是在OBJFPC模式中:正确的语法是什么是将平等运算符指定为记录?有可能吗?
我的FPC版本是3.0.4
(* Please try the following compiled with Lazarus 2.06, FPC 3.04: *)
unit..
..
{$IFDEF fpc} {$MODESWITCH AdvancedRecords+} {$ENDIF}
..
interface
..
type
TSomeRecord = record
feld_1: Byte;
class operator = (Left, Right : TSomeRecord): Boolean;
end;
..
implementation
..
class operator TSomeRecord .= (Left, Right : TSomeRecord): Boolean;
begin
Result:=Left.feld_1 = Right.feld_1;
end;
..