On 10.01.2012 20:12, waldo kitty wrote:
On 1/10/2012 05:39, Sven Barth wrote:
// -1 if aLeft < aRight
// 0 if aLeft = aRight
// 1 if aLeft > aRight
begin
// compare the two items and return the correct value
end;
// somewhere else:
aList.Sort(@SatDataCompare);
What I wrote here might not be perfect, but it should give you a start.
i've been working with what you sent and have run into a problem i don't
understand or how to find and fix...
Error: Operator is not overloaded
You’re trying to use an overloaded operator when it is not overloaded
for this type.
i don't know what this is pointing to because it is evidently not in my
sources but in a unit i'm loading... the actual compiler message is
(750,50) Error: Operator is not overloaded
satsort.pas(434) Fatal: There were 1 errors compiling module, stopping
satsort.pas(0) Fatal: Compilation aborted
Oh damn it, I forgot about that.
Is it possible for you to update to version 2.6? The problem is the
following: the list I mentioned to you uses a equality operator ("=") of
two values of the type you specialize with. Thus you need an overloaded
operator in case of records. But you can't use a global overloaded
operator (which you could do in FPC 2.4.5), as the specialization will
only see those types, functions and operators that were visible when the
generic (the TFPGList) was declared. So you'll need to use advanced
records for that (which are only available from 2.6.0 on).
Here is what you would do if you'd use 2.6.0:
// at the top of your unit/program:
{$mode objfpc} // or whatever mode you use
{$modeswitch advancedrecords} // you don't need this in mode Delphi only
// the declaration of your record (for sake of an example I'll reuse
your three_line_data record)
type
three_line_data = record
satname : sat_name;
satdata : two_line;
// now comes the important part
class operator = (aLeft, aRight: three_line_data)
Result: Boolean; // You need the "Result" only if you're not using mode
Delphi or ObjFPC
end;
// later in your program file or in the implementation section of your unit:
class operator three_line_data.= (aLeft, aRight: three_line_data)
Result: Boolean;
begin
Result := aLeft.satname = aRight.satname; // I don't know whether
this is your real comparison for equality, but it's just an example
end;
Now you should be able to successfully specialize the TFPGList.
If you can't update to 2.6.0:
1. I'd like to know why :)
2. You can then use the TList which is based on pointers (and requires a
bit manual housekeeping, but I can help you here as well if you want)
i don't know if this is because i wrote an IsSameStr function because i
could not find an IsSame one... i actually have two... one checks if two
string vars have the same string and the other checks if two double vars
have the same double... IsSameStr is boolean for true or false but
IsSameReal returns an integer of -1 (var1 < var2), 0 (var1 = var2) or 1
(var1 > var2)...
The IsSame was merely a placeholder for a function that compares your
two satellites records (and that you already seem to have created ;) )
Regards,
Sven
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal