You are not logged in.
I get this error when the IList<TOrm> is zero referenced after using CreateAndFillPrepare.
// TOrmArticles is the same as IList<TArticle>
function TDHSSyncRepository.GetAllArticles(var aArts: TOrmArticles):TSyncRepoError;
var
ormArt: TOrmArticle;
i: integer;
begin
result := srNotFound;
i := 0;
// result := Collections.NewList<TOrmArticle>; //Tested doing this call outside/inside this function but same result.
ormArt := TOrmArticle.CreateAndFillPrepare(FRestOrm,'',[]);
while ormArt.FillOne do begin
aArts.Add(ormArt);
end;
result := srSuccess;
end;When aArts no longer used I get the error.
What's wrong here?
Delphi-11, WIN10
Offline
FillOne is ... filling one ormArt instance... (as its name states) ![]()
So you are adding the very same TOrmArticle instance several times to the list.
Therefore, when you free the list you free the instance more than once. ![]()
So create a new TOrmArticle instance each time, or - even better - use the IList<> generics methods of FRestOrm. ![]()
Offline
Beutifull! Thanks!
This is the result:
function TDHSSyncRepository.GetAllArticles(var aArts: TOrmArticles):TSyncRepoError;
var
ormArt: TOrmArticle;
begin
result := srNotFound;
FRestOrm.RetrieveIList(TOrmArticle, aArts);
if aArts.Count < 1 then
exit;
result := srSuccess;
end;Delphi-11, WIN10
Offline