Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-06

Specialize for Object

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

aradeonas

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!

Regards, Ara

http://www.fastmail.com - Access all of your messages and folders wherever you are -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150609/e773fe93/attachment.html>

Reply by email

Sven Barth
to aradeonas
"aradeonas" wrote 18 lines
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.freepascal.org/pipermail/lazarus/attachments/20150609/ce316c01/attachment.html>

Reply by email

aradeonas
to Sven Barth

Thank you but I cant understand,can you explain more? This problem also happen for record but not classes. I am searching for easiest way to make list of records or objects.

Regards, Ara

http://www.fastmail.com - Access all of your messages and folders wherever you are -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150609/c83acfff/attachment.html>

Reply by email

Sven Barth
to aradeonas
"aradeonas" wrote
Thank you but I cant understand,can you explain more? This problem also happen for record but not classes. I am searching for easiest way to make list of records or objects.

Records and objects don't have an = operator defined, while for classes it is defined as pointer comparison.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150609/37030435/attachment.html>

Reply by email

Graeme Geldenhuys
to Sven Barth: TFPGList requires an = operator for the type you want to specialize with. While you could…
Sven Barth wrote
TTestObject = record i: integer; class operator = (const aLeft, aRight: TTestObject): Boolean; end;

[rant]

And this is where I think the new "advanced records" in an abomination of the Object Pascal language. It's almost as if the following is now true:

advanced records = objects = class

"class operator" normally tells me it is related to a Class type (because of the "class" keyword), but in the above code it is a record type. But a record with methods, which is just unnecessary duplication of the Object data type.

Talk about messing with a beautiful "what used to be" clear language syntax. Just because Delphi deprecated the Object type, and then reinvented it by messing with the Record type - why did Free Pascal have to follow that mess.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email