Discussion:
[fpc-pascal] Generic TFPGList<Record Type> gives me compiler error: Operator is not overloaded
Dennis Poon
2013-09-17 12:52:08 UTC
Permalink
I have this:
uses fgl;

Type
RScene=record
ID : Word;
Name, Category : String;
end;

TSceneList=specialize TFPGList<RScene>;


The error is: Operator is not overloaded: "RScene" = "RScene"


I suppose the generic thing does not know how to compare 2 records.
How do I solve that?

Dennis
Sven Barth
2013-09-17 13:23:01 UTC
Permalink
Post by Dennis Poon
uses fgl;
Type
RScene=record
ID : Word;
Name, Category : String;
end;
TSceneList=specialize TFPGList<RScene>;
The error is: Operator is not overloaded: "RScene" = "RScene"
I suppose the generic thing does not know how to compare 2 records.
How do I solve that?
Provide a "=" operator overload for the record:

=== code begin ===

uses fgl;

{$modeswitch advanced_records}

Type
RScene=record
ID : Word;
Name, Category : String;
class operator = (aLeft, aRight: RScene): Boolean;
end;

TSceneList=specialize TFPGList<RScene>;

class operator RScene.=(aLeft, aRight: RScene): Boolean;
begin
...
end;

=== code end ===

Regards,
Sven
Dennis Poon
2013-09-17 15:39:02 UTC
Permalink
Sven,

Thanks a lot. It worked.

Generics, advanced record, customized operator ... all these new
features are so cool.
I am impressed that Free Pascal has become so powerful.

Dennis


uses fgl;
Post by Dennis Poon
Type
RScene=record
ID : Word;
Name, Category : String;
end;
TSceneList=specialize TFPGList<RScene>;
The error is: Operator is not overloaded: "RScene" = "RScene"
I suppose the generic thing does not know how to compare 2 records.
How do I solve that?
Sven Barth
2013-09-17 17:43:53 UTC
Permalink
Post by Dennis Poon
Sven,
Thanks a lot. It worked.
Generics, advanced record, customized operator ... all these new
features are so cool.
I am impressed that Free Pascal has become so powerful.
At least generics and operator overloads aren't that new. What's new is
that generics contain less bugs (at least in 2.7.1 compared to earlier
versions) and that operators can be used inside records (together with
normal methods).

Regards,
Sven
leledumbo
2013-09-18 02:48:14 UTC
Permalink
Post by Sven Barth
and that operators can be used inside records
I just knew this one :)



--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Generic-TFPGList-Record-Type-gives-me-compiler-error-Operator-is-not-overloaded-tp5716520p5716541.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
Dennis Poon
2013-09-18 08:51:27 UTC
Permalink
Sven,
I am still using fpc 2.6.2.

May I know whether the generics bugs for 2.6.2 are catchable at compiler
times or I only get to find out at run time?

Dennis
Post by Sven Barth
Post by Dennis Poon
Sven,
Thanks a lot. It worked.
Generics, advanced record, customized operator ... all these new
features are so cool.
I am impressed that Free Pascal has become so powerful.
At least generics and operator overloads aren't that new. What's new
is that generics contain less bugs (at least in 2.7.1 compared to
earlier versions) and that operators can be used inside records
(together with normal methods).
Regards,
Sven
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3408 / Virus Database: 3222/6673 - Release Date: 09/17/13
Sven Barth
2013-09-18 09:27:52 UTC
Permalink
Post by Dennis Poon
Sven,
I am still using fpc 2.6.2.
May I know whether the generics bugs for 2.6.2 are catchable at compiler
times or I only get to find out at run time?
I'm currently not aware of any runtime bugs so all should be noticable
by the compiler complaining about your code :) (and these complains can
be very strange compile or link errors)

Regards,
Sven

Loading...