Am 11.05.2011 14:30, schrieb Marcos Douglas:
On Wed, May 11, 2011 at 3:51 AM, Mattias Gaertner
<[email protected]>  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

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to