Any object constructor nulls all data fields — undocumented wrong behavior lazarus / 62-General ---------------------------------------------------------------------- Avinash · 2024-02-01 10:52 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$MODE TP}type  PObject = ^TObject;  TObject = object    Value: Integer;    constructor Init;  end;   constructor TObject.Init;  begin  end; var  B: TObject;begin  B.Value := 12345;  WriteLn(B.Value);  {Output: 12345}  B.Init;  WriteLn(B.Value);  {Output: 0}  {In Turbo Pascal output "12345"}end. In Turbo Pascal, calling a constructor by itself does not destroy the object's fields. This allows, for example, by calling an empty constructor to change the VMT-link of an object instance. This method, unlike direct assignment, is more organic: it is compatible between different «bitnesses» and the location of the VMT link (which in general may not be at the beginning of the data). In FPC it turns out that calling an empty constructor leads to the inevitable destruction of all data fields. Thus, to replace the VMT link without destroying the data, only direct assignment remains. ---------------------------------------------------------------------- Thaddy · 2024-02-01 12:18 I am not so sure if TurboPascal's behavior is documented. At least there is nothing in my official paper books. So if it is by accident, undefined behavior, implementation detail, even a bug report won't bring you much further. I am pretty sure it is implementation detail and not documented. As such it is not wrong. Plz show me otherwise referring to official Borland documentation. (You can't!) More in general, TP mode behavior in FreePascal is more in line with what you would expect for init constructors; I am not even sure the behavior that you describe is consistent over different versions of TurboPascal. Or better: I would have known about that behavior... (which I am able to test when needed, I have 1.0, 3.0, 5.5 and 7.0, some versions with books and floppies)