Thursday, 23 February 2017

Strict Private Problem with Code Completion

Some time ago I noticed something annoying in Delphi XE with 'Strict Private' and code completion.

Here is an example:

TMyClass = class(TObject)
strict private

public
    property Test: string read FTest write FTest;
end;

When I do CTRL + Shift + C to add the private member to the class it does the following:

TMyClass = class(TObject)
strict private

private
    FTest: string;

published

public
    property Test: string read FTest write FTest;
end;

It adds FTest to the private section of the class and also adds the published section, which is not what I want, but if I remove 'strict' it does not add the 'published' section. Because of this I develop my classes  as 'private' and then once I have added all the require properties then I add 'strict' if required. I am not sure if this behaviour is some setting somewhere that I am not aware of, or whether this is something that might have changed in more recent versions of Delphi. Is there a valid reason to have a 'published' section when there is a 'strict private' section?