Sign in Join

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

Mailing lists / fpc-pascal / 2015-10

Delphi-FPC difference in handling TList

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Bo Berglund

I am porting a Delphi class to FPC and I ran into a problem concerning TList:

FCommands.Sort(CommandCompare);

This generates an error:
Error: Wrong number of parameters specified for call to "CommandCompare"

This call works just fine in Delphi and I have no clue as to why it happens in FPC.

CommandCompare is a function that will compare two items based on the properties of the object so the sort will be based on object properties.
In this call to Sort the function is passed as a parameter rather than being called...

From Delphi help:

Delphi syntax:

procedure Sort(Compare: TListSortCompare);

Description

Call Sort to sort the items in the Items array. Compare is a comparison function that indicates how the items are to be ordered.

I tried to typecast the function but it does not change anything:

FCommands.Sort(TListSortCompare(CommandCompare));

What am I missing?

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund: I am porting a Delphi class to FPC and I ran into a problem concerning TList:…
Bo Berglund wrote 11 lines
I am porting a Delphi class to FPC and I ran into a problem concerning TList: FCommands.Sort(CommandCompare); This generates an error: Error: Wrong number of parameters specified for call to "CommandCompare" This call works just fine in Delphi and I have no clue as to why it happens in FPC.

If you are compiling in objfpc mode, try

  FCommands.Sort(@CommandCompare);

Michael.

Reply by email

Bo Berglund
to Bo Berglund: I am porting a Delphi class to FPC and I ran into a problem concerning TList:…

On Tue, 20 Oct 2015 08:31:57 +0200, Bo Berglund
wrote:

Thanks!

FCommands.Sort(@CommandCompare);

works fine, at least no longer any compile errors in this unit. Now in another unit and wound up with lots of Windows specific stuff I really do not need, so I am busy ifdefing away those...

Plus in that unit I need to add a TCP socket also.

Bo Berglund Developer in Sweden

Reply by email