In one file, I have a baseclass with a ID-property:
type TBase = class(TObject) private FID: integer; public property ID: integer read FID write SetID; end;
In a second file, I have another class, descending from TBase. By accident, or ignorance or what ever, a new property/field with the same name as an exsisting property/field was made.
type TSub = class(TBase) private FID: Longword; public property ID: Longword read FID write FID; end;
The second ID-fields is of course renamed, but why does the compiler allow this?
When accessing ID in code – which ID-field is used?
Delphi allows this to ‘hide’ your old properties and introduce properties with the same name that operate differently. I’ve used this for example to create my own typesafe TList descendants for a specific class or record:
Ofcourse, with Delphi 2009 and generics, it’s a lot easier now.
Which ID you are accessing depends on the place you are calling ID from.