On 21 Mar 2001, at 18:20, Maurice Lombardi wrote:
Prof. A Olowofoyeku (The African Chief) wrote:
On 21 Mar 2001, at 16:15, Maurice Lombardi wrote:
Yes, it does - but I am not sure which destructor you would be calling after such an assignment. Remember that instances of classes are pointers to the objects - so in the assignment, what you are moving around are pointers, and there may be gotchas there.
But as far as I remember delphi knows the actual type of an object at run time from the address of the VMT (there is one VMT for each defined object type) which he recovers at a fixed displacement from the address given by the object pointer.
Well, the example code causes an exception at the point where you call "h1.free" (if you do the assignment "h1 := h2"). This happens both under Delphi and Virtual Pascal (which is Delphi-compatible). So there is obviously an issue there.
yes but that's because in this code you do two free's. After the assignment h1 and h2 point to the same location. You then can do only one free (h1.free or h2.free), in any order. The exception arises only on the second free because the second pointer points then to nowhere.
You are right of course. But that is still one of the "gotchas" that one needs to bear in mind, although it is a different one from the one that I had in mind at the time. And furthermore you cannot then be sure that there are no memory leaks - you have constructed two objects and allocated memory and resources for both of them, and you are only freeing one of them. That sounds like a memory leak to me, unless I am missing something.
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Author of Chief's Installer Pro for Win32 Email: African_Chief@bigfoot.com http://www.bigfoot.com/~african_chief/