You are not logged in.
Pages: 1
Ab, I am working with TDynArray with Delphi 7.
Everything is OK, but now I need to change the way to find items in the list.
TEspecie = record
EspecieID: Integer;
Nome: string;
.. some other fields..
end;
When I am building the list, I need to search for the 'Nome' field. After, I will need to search by the 'EspecieID' field.
How to change Find() / FindAndFill() to work like this?
Thank you in advance.
Offline
Thank you.
Another question: just to sort a already existing array, how to do? If I try to init a TDynArray to a existing array, I can't sort. This code gives me an AV when call AList.Sort.
var
Especies: TEspecieArray;
begin
Especies := GetAllEspecies;
AList.Init(TypeInfo(TEspecieArray), Especies);
AList.Compare := MyCompareItem;
AList.Sort;
end;
My workaround is create a new array, call AList.AddArray() and then Sort. There are a better approach?
function SortEspecies: TEspecieArray;
var
SortedEspecies: TEspecieArray;
Especies: TEspecieArray;
begin
Especies := GetAllEspecies;
AList.Init(TypeInfo(TEspecieArray), SortedEspecies);
AList.AddArray(Especies);
AList.Compare := MyCompareItem;
ALista.Sort;
Result := SortedEspecies;
end;
Offline
AList.Init(TypeInfo(TEspecieArray), Especies);
AList.Compare := MyCompareItem;
AList.Sort;
should work directly.
I tried to reproduce the issue - see http://synopse.info/fossil/info/b72e1534e4
But no problem occurred.
What is the exact issue on your side in the Sort method?
How is your MyCompareItem() function implementation?
Offline
This is weird. I tried again and it worked now.
Thank you again.
Offline
Pages: 1