then calling FItemClass.new calls the constructor of TOne, not the Constructor of TTwo. In version 4 this worked as expected. If there is a workaround, I need it urgently otherwise I’m going to have to go back to using version 4.
Sorry for the delay in replying, I was on holiday.
I don’t think it changes anything as I’m pretty sure I tried that, but after the holiday, I’m no longer sure so I’ll set up a test to see if that fixes it. It definitely worked without it being virtual and overridden in version 4.
I don’t think virtual/override of something changes the fact that the FItemClass.new should have created an object of the proper class and didn’t. FWIW.
unit issue54664test;
interface
uses
System.Linq, System.Collections.Generic;
type
ConsoleApp = public class
public
class method Main(args: array of string): Integer;
end;
TOne = class
constructor ; virtual;empty;
end;
TOneClass = class of TOne;
TTwo = class(TOne)
constructor ; override;empty;
end;
TThree = class(TOne)
constructor ; override; empty;
end;
implementation
class method ConsoleApp.Main(args: array of string): Integer;
begin
var FItemClass : TOneClass;
FItemClass := TTwo;
var x := new FItemClass();
Console.WriteLine(x);
Console.WriteLine(x.GetType);
end;
end.
Which gives:
issue54664test.TTwo
issue54664test.TTwo
Without the virtual/override i get:
issue54664test.TOne
Sorry for the delay, I’ve been busy on another project.
I used your project and took away the constructor in class TTwo. This shows up the error. If my class doesn’t do anything additional in the overridden constructor, I shouldn’t need to have it there should I ?
I think though that it shouldn’t need to be virtual/overridden anyway as it should construct a class of the type held by the class variable.
Ah. The automatically added constructors should be override if the parent’s were override too. Logged as bugs://55494. Every class has constructors in Oxygene. Else you cannot instantiate them. If you don’t add them it adds them for you, now those should probably be override automatically.