[Lazarus] Specialize for Object
Sven Barth
pascaldragon at googlemail.com
Tue Jun 9 11:24:17 CEST 2015
Am 09.06.2015 11:12 schrieb "aradeonas" <aradeonas at operamail.com>:
>
> Hi,
>
>>
>> TTestObject = object
>> i: integer;
>> end;
>>
>> TTestObjectList = specialize TFPGList<TTestObject>;
>
>
> When I try to compile this code compiler said :
>
>>
>> Error: Operator is not overloaded: "TTestObject" = "TTestObject"
>
>
> I dont even know what is this mean!
TFPGList<> requires an = operator for the type you want to specialize with.
While you could declare a global operator overload for TTestObject this
won't help as it needs to be a local one. Only records with modeswitch
advancedrecords support this currently, thus you should adjust your code
like this:
=== code begin ===
{$modeswitch advancedrecords} // this needs to be after the $mode, but
before the uses section
type
TTestObject = record
i: integer;
class operator = (const aLeft, aRight: TTestObject): Boolean;
end;
TTestObjectList = specialize TFPGList<TTestObject>;
// ...
class operator TTestObject.=(const aLeft, aRight: TTestObject): Boolean;
begin
// whatever you need for equality
end;
=== code end ===
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150609/ce316c01/attachment-0003.html>
More information about the Lazarus
mailing list