[Lazarus] Example requested for TList and Sort using data type of Object (or record).
Sven Barth
pascaldragon at googlemail.com
Wed May 11 14:35:16 CEST 2011
Am 11.05.2011 14:30, schrieb Marcos Douglas:
> On Wed, May 11, 2011 at 3:51 AM, Mattias Gaertner
> <nc-gaertnma at netcologne.de> wrote:
>>
>> function SortComponentsForName(Item1, Item2: Pointer): integer;
>> var
>> Comp1: TComponent absolute Item1;
>> Comp2: TComponent absolute Item2;
>> begin
>> Result:=CompareText(Comp1.Name,Comp2.Name);
>> end;
>
> I did not know about 'absolute' yet... what is the vantage?
> Can you give me a link about it, please?
See here (in the list point 6):
http://freepascal.org/docs-html/ref/refse20.html#x52-590004.2
It allows you to declare a variable that has the same location as
another variable or parameter (but it does not need to have the same
type). In the example written by Matthias Comp1 contains the value of
Item1 from the "begin" on. The other way to achive this is the following:
function SortComponentsForName(Item1, Item2: Pointer): Integer;
var
Comp1, Comp2: TComponent;
begin
Comp1 := TComponent(Item1);
Comp2 := TComponent(Item2);
Result := CompareText(Comp1.Name, Comp2.Name);
end;
Regards,
Sven
More information about the Lazarus
mailing list