Recent

Author Topic: DBGrid1 destroy and create it again?  (Read 11499 times)

teos

  • Full Member
  • ***
  • Posts: 161
Re: DBGrid1 destroy and create it again?
« Reply #15 on: August 22, 2012, 01:25:35 pm »
That I tried some time ago.

I now am about to try:

  with TDBGrid.Create(Self) do
  begin
    // Set properties of the grid
    DataSource := xxxxx; // Connect the source to the grid
  end;

I hope this will work.

Thanks.

That does not work when you need dbGrid1. You can set the name but the object is only re-created if you use dbgrid1 := TDBGRid.Create();

With TDBGrid.Create do only creates a new, kind of unidentified dBGrid. This call will give acces violations if you address dbgrid1 in code.

Quote
The part that I don't understand is why Destroy itself does not check if nil.
Destroy is a virtual method overridden in a lot of objects while free can not be overridden. So the question "why Destroy itself does not check if nil" has to be asked to a lot of developers. On the other hand there is only one version of Free and that is documented to check if not nil before calling destroy.
I don't know if you have already written a class destructor but if you did, please look it up and verify if you have made a check on self being nil before doing the job. I guess that will answer your question.
Quote
Also, how does Free protect its members, or anything if it destroys if not nil?
I don't understand that question. What members of Free? What is anything? What protection? Are you afraid for your personal safety when Free destroys? It sounds very philosophical and probably belongs to another forum %)

I don't think Destroy has to check again for not nil -> that is allready taken care of in the Free.

The destructor is THE place where to do cleaning up if needed. If in a container, again not by destroying objects but by calling Free.

 

TinyPortal © 2005-2018