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.  This had me 
scratching my head for a while because within that function I need to 
access objects, functions and procedures of the form which owns the list 
I'm trying to sort.  I have got round this by giving the object in my 
list a Parent property of type of the form.

This might be easier to explain with some code fragments:

type
TMyForm = class;//forward declaration
TMyObject = class
private
public
/    /ID : integer;
   Parent : TMyForm;
end;

TMyForm = class(TForm)
   bla
   HolyGrail : TMystery;
private
   bla
   bla
public
   MyObjectList : TObjectList;
   bla
end;

implementation


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;

It works but it aint pretty - surely there's an easier way of getting at 
stuff on the form?  If I try to declare the callback function anywhere 
where it would 'naturally' get at stuff on the form the compiler 
complains that a 'variable required'. 

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 ?

Thanks for any suggestions...
Dave





-----------------------------------------------------
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