Welcome, Guest
Username: Password: Remember me
General discussions, feature requests for CodeTyphon Project and discussions that don't fit in any of the other specific CodeTyphon forum categories.
  • Page:
  • 1

TOPIC:

TFPList sorting not working for me 8 years 11 months ago #7464

  • gustavo tolson
  • gustavo tolson's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Dear all,
I have succesfully used this TList sorting construct in Delphi 7 under Windows XP but cannot get it to work in Typhon with Ubuntu 14.04. The construct I'm using is (from the Free Pascal forum) below but it generates the following error:

popan_u07.pas(386,29) Error: Identifier not found "SortLorenzByValue".

Could someone please post a working example?
Best regards,
Gustavo


uses ...math;

type
TLorenz = class
a,b,c:string;
v:integer;
end;

function SortLorenzByValue(Item1: Pointer, Item2: Pointer):Integer;
begin
Result:=CompareValue(Item1,Item2);
end;

procedure RunMe;
var
aList:TList;
begin
aList:=TList.Create;
try
for i:=0 to 9 do
begin
aLorenz:=TLorenz.Create;
aLorenz.a:='Hello World';
aLorenz.v:=Random;
aList.Add(aLorenz);
end;
aList.Sort(@SortLorenzByValue);
finally
for i:=0 to aList.Count-1 do
TLorenz(aList).Free; //TList.Free deletes the references but does not free it
aList.Free;
end;
end;

Please Log in or Create an account to join the conversation.

Last edit: by gustavo tolson.

TFPList sorting not working for me 8 years 11 months ago #7470

  • Tony_O_Gallos
  • Tony_O_Gallos's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Ελεύθερο λογισμικό ή θάνατος
  • Posts: 84
  • Thank you received: 23
Hi uk301,
nothing can work in the piece of code you post.

SortLorenzByValue is missing some parts in its definition (type conversion..).
You don't use the index [ i ] to free the elements of the list.

Below a full example + the source fully commented (easier with syntax colors ;))

Have fun !

Warning: Spoiler!

Please Log in or Create an account to join the conversation.

TFPList sorting not working for me 8 years 11 months ago #7471

  • gustavo tolson
  • gustavo tolson's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Many thanks for your prompt reply. I regret the omissions in my previously posted code but I copied it verbatim from the source you eloquently quote. Thanks to your post I have found my mistake.
Cheerio.

Please Log in or Create an account to join the conversation.

Last edit: by gustavo tolson.
  • Page:
  • 1