<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">The compare function is declared right
inside the class<br>
<br>
{ TFPGList }<br>
<br>
generic TFPGList<T> = class(TFPSList)<br>
private<br>
type<br>
TCompareFunc = function(const Item1, Item2: T): Integer;<br>
<br>
<br>
"T" is from the generic, so if you specialized with string, then T
is string.<br>
<br>
It is a function, not a method (i.e. not part of a class)<br>
<br>
<br>
On 21/10/2024 00:17, ppadilcdx--- via fpc-pascal wrote:<br>
</div>
<blockquote type="cite"
cite="mid:5999F427-AFEF-4E49-98F4-64674D7B100E@gmail.com">
<pre wrap="" class="moz-quote-pre">Just tried to compile a short program with that definition of compare: TCompareFunc, and that is the wrong type for TFPGList<String> in my program (yes there is a better class for strings but I just wanted a quick example program to compile). FPC error message says it wants:
function(const ShortString;const ShortString):LongInt,
so only two non-pointer input parameters. Must be another definition somewhere.</pre>
</blockquote>
<span style="white-space: pre-wrap">
</span>
<blockquote type="cite"
cite="mid:5999F427-AFEF-4E49-98F4-64674D7B100E@gmail.com">
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">
type TFPSListCompareFunc = function(
Key1: Pointer;
Key2: Pointer
):Integer of object;
Two questions.
1) Should TCompareFunc in TFPGList.Sort be one of the above types, or is there another definition somewhere?
2) What is an “Integer of object” in TFPSListCompareFunc? (I expect it to be a typo but then I’m fairly new to free pascal so I might have missed the memo.)
</pre>
</blockquote>
</blockquote>
<br>
Of object belongs to the function (the entire function declaration
before), not just the "integer".<br>
So that function must be a method of a class.<br>
</body>
</html>