|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
edit1.create
I went and looked at the assembly code for this - you are right - this
will not cause an exception (I even tried it). The main reason it works is that Delphi does not need a valid object pointer to call .Free - it is not a virtual method. If Free were a virtual method, then a valid object pointer would be required to call free. Doug Totoliciu Denis Dan wrote: When I have posted that the following lines: > := Nil; Free(); > do not raise an exception, I didn't have Delphi at hand; but I knew that inside TFree() it is written something like this: > procedure TFree(); begin if Self <Nil then Self.Destroy; end; > The call to Free() through (that is Nil) goes K because: 1. Free() is not a virtual method; and as we all know, the binding is done at compile time. That means there is no need to access a VMT. 2. Every method of a class has a hidden parameter; and that parameter is Self. When calling Free, there is no need that is different then Nil as (named Self inside the method Free()) is passed as parameter. > Free() would raise an error when points to a zone of memory that is not allowed to be accessed. > |
![]() |
| Viewing: Web Development Archives > Mailing Lists > Delphi > edit1.create |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|