Ok, so I have a base class that we will call TFruit. From this there are various descendants, such as TApple, TOrangeand so on. I need to save the properties of the descendant classes to a file.
To create the correct class when loading data, each class must have IDwhich I write to the file before writing the actual data. Currently, I have come up with the following method:
type
TFruit = class
const ID = 0;
end;
TApple = class(TFruit)
const ID = 1;
end;
TOrange = class(TFruit)
const ID = 2;
end;
Checking this, I found out that I need to be very careful what class I declare. If I use this:
var Fruit: TFruit;
Fruit := TOrange.Create;
... then Fruit.IDwill return zero . However, declaring Fruithow TOrangewill produce the expected result Fruit.ID = 2(does anyone know why?)
, , ? ( , ).