hvlstud2@sci.kun.nl (Margo Pulles) (02/08/91)
Bug in TP 5.5? This is Version 2.00 of my question. This time a more enhanced specification. When I use Turbo Pascal 5.5, I have the following problem : I can declare an OBJECT x on the following way : TYPE x = OBJECT { . . . } CONSTRUCTOR Init(Name : PathStr); { Use Dos PathStr } { . . . } END; VAR y : x; I first called the method Init this way : WITH y DO BEGIN Init(LocalName); { . . . } END; But that didn't work. (It compiled well). When I looked at it using Turbo Debugger 1.5, I saw that Name contained rubbish after the call. (Inside the method Init). But when I called Init using y.Init(LocalName); everything was allright. You have to know that x is declared in an unit wich is in the overlay section. Did anybody have this problem before, is it bad programming, or contains TP 5.5 a bug? I'm waiting fo your answers. Gert van het Slot (e-mail : fcc@chem.ruu.nl) when can't mail to this adress try e-mail hvlstud2@sci.kun.nl
Bob_Slomcenski.WBST129@xerox.com (02/09/91)
Gert, I think you may have uncovered a true bug. I can find nothing in the Turbo manual that explicitly prohibits the "WITH y" form. However, it appears to me that the problem lies in de-referencing the variable "y" before the object has been initialized. According to the Turbo 5.5 OOP manual (Instance Initialization, page 79): If an object contains virtual methods, then instances of that object type must be initialized through a constructor call before any call to a virtual method. Your example does not indicate if the object contains any virtual methods. If it does, perhaps the problem is that the WITH construct attempts to open the scope of "y" before a virtual method table (VMT) has been established. That is, using "WITH y" allows access to any field or method defined in the object, but before calling its constructor this access is invalid. I am not familiar with Turbo's internal representation of the WITH construct, but this does appear to be an inconsistency in the behavior that I would expect. Did you try the following: WITH y DO BEGIN y.Init(.....); { note explicit use of "y" } {...} END; Bob.