You are not logged in.
Pages: 1
I Have an an old sorted stringlist that that I need to replace with an IList:
The constructor looks like this:
constructor TCtrlV2List.create;
var
comparer : IComparer<TSQLLobUserControllv2>;
comparison : TComparison<TSQLLobUserControllv2>;
begin
inherited create;
comparison := function(const l,r : TSQLLobUserControllv2):integer
begin
if (l.LOBuffertNo = r.LOBuffertNo) and (l.PkgArticleNo = r.PkgArticleNo) and (l.UserID = r.UserID) then exit(0) // This item already exist in the list!
else if l.LOBufferNo > r.LOBufferNo then exit(-1)
else if (l.LOBufferNo = r.LOBufferNo) and (l.PkgArticleNo > r.PkgArticleNo) then exit(-1)
else if (l.LOBufferNo = r.LOBufferNo) and (l.PkgArticleNo = r.PkgArticleNo) and (l.UserID > r.UserID) then exit(-1)
else exit(1);
end;
comparer := TComparer<TSQLLobUserControllv2>.Construct(comparison);
inherited Create(comparer);
end;Now I wonder how I should do to accomplish this with an IList?
Last edited by larand54 (2026-03-03 08:18:11)
Delphi-11, WIN10 and Win11
Offline
What is wrong with IList.Sort() ?
You just have to define a local TDynArraySortCompare function.
function SortByLO(const a,b):integer
var l,r : TSQLLobUserControllv2;
begin
l := pointer(a);
r := pointer(b);
if (l.LOBuffertNo = r.LOBuffertNo) and (l.PkgArticleNo = r.PkgArticleNo) and (l.UserID = r.UserID) then exit(0) // This item already exist in the list!
else if l.LOBufferNo > r.LOBufferNo then exit(-1)
else if (l.LOBufferNo = r.LOBufferNo) and (l.PkgArticleNo > r.PkgArticleNo) then exit(-1)
else if (l.LOBufferNo = r.LOBufferNo) and (l.PkgArticleNo = r.PkgArticleNo) and (l.UserID > r.UserID) then exit(-1)
else exit(1);
end;and by the way your code seems incorrect, you are calling Create() twice.
Offline
Thank's a lot, I feel a bit stupid but I have to ask - How should I connect this function to the list?
And to the comment of the second call to create - I don't know why this extra call has been placed there, I think it should have replaced the first call to create.
It's been a long time since I wrote this code and it has been running 24h a day in several years without any problem that I have seen.
Delphi-11, WIN10 and Win11
Offline
Thank's a lot, I feel a bit stupid but I have to ask - How should I connect this function to the list?
Just read the comments carefully:
https://github.com/synopse/mORMot2/blob … s.pas#L173
https://github.com/synopse/mORMot2/blob … s.pas#L290
Last edited by zed (2026-03-03 11:01:24)
Offline
Thanks zed, but I think I solved it already. I wrote -
UctrlList.Sort(@SortByLO);and that seemed to work fine.
Delphi-11, WIN10 and Win11
Offline
Pages: 1