Can you mark a Property as deprecated - like FPC allows?

Can you mark a Property as deprecated - like FPC allows?

I want to do this:

property SomeProp: string
read FSomeProp
write SetSomeProp; deprecated 'Use SomeOtherProp instead';

Free Pascal (FPC) allows this, but Delphi XE doesn't. Does later Delphi versions support this? Is there any work-around for Delphi XE?

Comments

  1. To make matters worse, it seems Delphi also doesn't support user defined compiler hints and warnings (like FPC allows). So for now the only work-around I could think of is doing the following:

    procedure TtiRealListItem.SetValue(const Value: Extended);
    var
    YouAreUsingADeprecatedProperty: string;
    begin
    { WARNING: You are using the deprecated ASomeValue property - use SomeValue instead. }
    FValue := Value;
    end;

    This will produce a compiler hint about an unused variable that looks like this:

    [DCC Hint] tiUtils.pas(4530): H2164 Variable 'YouAreUsingADeprecatedProperty' is declared but never used in 'TtiRealListItem.SetValue'

    Hopefully that will be enough incentive for a developer to see that he should update his code.

    All this just because "deprecated" isn't allowed on Properties - another big omission from Delphi.

    ReplyDelete
  2. Thanks Jeroen Wiert Pluimers, but in this case the property is not read-only. But I see that using a Setter method and placing deprecated there has a similar result to what I did.

    In my real-word code, the original read-write property had a spelling error, so I introduced another property with the correct spelling and wanted to mark the old one as deprecated. I didn't simply want to break (compiler error) everybody's existing code that uses my library. I wanted to give them a few months to update their code as and when they can.

    @EMBT:
    Bottom line, it seems EMBT is spending too much time and money buying other companies and products and introducing more junk into the Delphi product with not much gains. What they really should be doing is fixing the stuff that is already there - improve the IDE, improve the language. EMBT, please take some queues from the Free Pascal and Lazarus projects - they are (or already have) making your product obsolete and way out of date.

    ReplyDelete
  3. Graeme Geldenhuys you can emit warnings/errors:
    {$Message Warn 'Hello World'}
    docs.embarcadero.com - MESSAGE directive (Delphi)

    ReplyDelete
  4. Alexander Benikowski: Thanks for correcting me on that one.

    ReplyDelete
  5. Alexander Benikowski Makes no sense. The deprecated directive causes a compiler notification on the consumer side of a symbol.

    ReplyDelete
  6. Stefan Glienke didn't say it makes sense in this case. Just corrected the statement it does not exist in Delphi :P

    ReplyDelete

Post a Comment