delphicustom-controlsdelphi-7tlist

Delphi 7 TListSortCompare that can access object properties


I'm writing a custom component that owns a Tlist of records . the problem is : how the TListSortCompare function -used to sort the list's records- can access component's fields ? the compiler refuses object method as a list compareator , and in the component's unit there is no instance created yet to access .

Thanks Wael


Solution

  • The compare function can't be a non-static class method, it has to be either a standalone function or a static class method, which means it has no Self parameter to directly access any component object, it only knows about the 2 input parameters that point to the records being compared.

    So, the only ways for you to indirectly access the component object inside your compare function is if you either: