Problem when deleting from memory a Tobjectlist<Tlabel>

Asked

Viewed 336 times

0

I’m having a problem clearing a Tobjectlist< Tlabel from memory, specifically the Objectlist of the type Tlabel. I created two Objectlist, added an item and tried to clear them from memory: Excerpt from the code:

  tolRectMenuItemProntuario := TObjectList<TRectangle>.Create;
  tlLabelDadosPaciente := TObjectList<TLabel>.Create();
  tlLabelDadosPaciente.Add(lbTituloConvenio);
  tolRectMenuItemProntuario.Add(rtMenuItemAnamnese);      
  tolRectMenuItemProntuario:= nil;
  tolRectMenuItemProntuario.DisposeOf;
  tlLabelDadosPaciente := nil;
  tlLabelDadosPaciente.DisposeOf;

However when deleting try to delete tlLabelDadosPatient, the Tobjectlist< Tlabel>, the error system:

"Project Appsigmedoffline.exe Raised Exception class Einvalidpointer with message 'Invalid Pointer Operation'."

Is there a different way to delete a Tobjectlist< Tlabel>, because I am using the same way the two Objectlist, but only the Tlabel of the error.

  • It would be nice to add a minimal and complete example so that someone can reproduce what you are finding...

1 answer

0

You are assigning nil for the variable before executing the DisposeOf. You would have to do this assignment only after performing the memory release method. Still, I think you should call the method .Free instead of Dispose. And also, when creating TObjectList pass false as parameter. If done so, TObjectList will not destroy the objects when it itself is destroyed. Pass true only if you create the objects at runtime and/or want the list to destroy them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.