Hello

Hello,

Do you know why the "defaut" keyword of a class property is sometime defined also as an attribute ?

Vcl.Buttons.TBaseNavigator.Flat

[Default(False)]
property Flat: Boolean read FFlat write SetFlat default False;

hum...perhaps for string or single types...but I don't see any uses case...but now System.Classes use the huge System.Rtti unit :/

Comments

  1. It seems like work has been started to replace(?) the default keywords with attributes?

    In theory, and this is very theoretical, an attribute could produce an object instance, and not just simple types values like the default keyword.

    Then again - It uses DefaultAttribute from System.Classes, which holds a ... variant.
    /facepalm (I am not a fan of variants).

    ReplyDelete
  2. Paul TOTH then you need to browse the VCL sources for where the `DefaultAttribute` and `TDefaultAttributeBase` actually being queried and processed.

    ReplyDelete
  3. Jeroen Wiert Pluimers I greped "[Default", it is used in Data.* DataSnap.* Vcl.DB* but each time for boolean on integer value that is already defined with a default keyword.

    It's seems that like TComponent.BeginInvoke() it has been added and never used anywhere.

    I'd like that one new release will shrink the exe size instead of adding garbage each time.

    I've just discovered that FMX.Text uses TRegEx to find CR/LF in the text...System.RegularExpressionsAPI is only 128Kb after all

    RegularExpression is a powerfull tool, but not necessary to split some text (also used in TPlatformCocoa.DialogOpenFiles to split the filter string)

    ReplyDelete
  4. default keyword only works for very few types:

    [Default('Hello world')] // <- works
    property Foobar: string read fFoobar write fFoobar default 'Hello world'; // <- does not work because E2146

    Probably their internal coding guidelines say always add both if possible. Anyway even if they don't use it themselves this might be handy for third party component developers.

    ReplyDelete
  5. Paul TOTH I agree. That's the drawback of losing so many senior team members in R&D.

    ReplyDelete
  6. Stefan Glienke I prefer an extra "Hello world" in some DFM than extra Kb in all projects. And it is possible to use "stored" to check for non trivial default values.

    ReplyDelete
  7. Paul TOTH BeginInvoke is part of the APL. It is not unusual that a library provides functionality that is not used by itself. That doesn't mean that it is not used by other developers in their applications.

    docwiki.embarcadero.com - Using the Asynchronous Programming Library - RAD Studio

    ReplyDelete
  8. Uwe Raabe If that works as well as the PPL does I would not touch it with a 10 foot pole ;)

    ReplyDelete
  9. Uwe Raabe Okay, but why is it tied to TComponent ?

    ReplyDelete
  10. Paul TOTH Why not? Would you prefer it in TObject?

    ReplyDelete
  11. Actually BeginInvoke is a bit more than the sparse documentation tells. For example for TWinControls components it makes sure the passed callback is executed in the thread the control was created in (mostly the ui mainthread).

    In C# (where this obviously was cop.. inspired by) the BeginInvoke is on the Control class.

    However in Delphi TComponent is the base class that both UI frameworks share so it makes sense to put it there.

    ReplyDelete

Post a Comment