- This topic has 1 reply, 2 voices, and was last updated 10 months, 2 weeks ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- You must be logged in to reply to this topic.
Hi,
In my application I have the following code:
Requirement := TPMRequirement.Create;
try
Requirement.PMItem := Orm.FromDataset<TPMItem>(FItemTable, True, True);
Requirement.RequirementItem := Orm.FromDataset<TPMRequirementItem>(FDetailTable, True, True);
…
Because the constructor of the TPMRequirement instanciates both PMItem and RequirementItem the PMItem and RequirementItem should be freed before getting the value from the ORM else you will have a memory leak. To accomplish this I have added the following code:
procedure TPMRequirement.SetPMItem(const Value: TPMItem);
begin
FPMItem.Free;
FPMItem := Value;
end;
After adding this code I got a Invalid Pointer Exception but I don’t understand why. I have tested similar code without kbmmw/orm and it just works fine. If I free the both items before the ORM code is called it works fine, but that solution is a bit uggly.
Any suggestions/best practice?
Well… one thing might be that the initial free is running on a bad pointer.
But it would be helpful to see how the definition of TPMItem and TPMRequirementItem actually is.
/Kim