Dave Sellers wrote:
> I'm using TObjectList.Sort successfully but, I suspect, not particularly
> elegantly. In fact, I have a suspicion I'm doing something dumb..
> 
> It seems that my callback function has to be in the implementation 
> section (with no declaration) or the compiler complains.

No, the function can be declared anywhere you want. But it has to be a 
standalone function, not a method. It's a rather unfortunate requirement 
of the TList class and its descendants. I have a sample program that 
demonstrates how to get around the problem, but it's at home, and I'd 
prefer not to rewrite it here. I'll post it when I get home this evening.

> function MyFancySort(item1, item2 : Pointer) : integer
> var
> /    /obj1, obj2 : TMyObject;
> begin
> //now provided I have set the parent property to Self when creating the 
> TMyObjects and adding them to the list, I can access stuff on the form thus:
>    obj1 := TMyObject(item1);
>    obj2 := TMyObject(item2);
>    if obj1.Parent.HolyGrail.SomeFunction(obj1.ID) > 
> obj2.Parent.HolyGrail.SomeFunction(obj2.ID) then
>       bla bla you get the picture
> end;

With my code, that would be simplified to this:

function TMyForm.MyFancySort(Item1, Item2: Pointer): Integer;
var
   obj1, obj2: TMyObject;
begin
   obj1 := Item1;
   obj2 := Item2;
   if HolyGrail.SomeFunction(obj1.ID) > HolyGrail.SomeFunction(obj2.ID) then
end;

> Apart from the question of technique above, when I run this it is 
> surprisingly slow.  Is there any way of knowing the progress of a Sort ?

Nope. It doesn't provide any feedback. You could copy the sorting 
routine from Classes.pas and insert your own hooks to know the progress.

-- 
Rob


-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to