eta
eta

Reputation: 27

Default property for class in delphi 7

I'd like to ask on how to set default property in a delphi 7 class? So it can be accesed by just writing >> class := '..'; << that's if the default property set to text. so we dont have to write class.text := '..';

Upvotes: 1

Views: 3328

Answers (3)

Stijn Sanders
Stijn Sanders

Reputation: 36850

I think what you're looking for is a custom Variant type: http://docwiki.embarcadero.com/VCL/en/Variants.TCustomVariantType

Upvotes: 0

Toon Krijthe
Toon Krijthe

Reputation: 53476

You can't do that because it leads to ambiguous situation.

For example, you have a class:

type
  TMyClass = class
  public
    property MyProperty: TMyClass read FMyProperty; default;
  end;
var
  a, b : TMyClass;

begin
  // ...
  a := b; // Do we assign to a or to MyProperty
  // ...
end;

It could have worked for other (basic) types but its still confusing. Besides, its just a few extra characters to type.

Upvotes: 1

RobS
RobS

Reputation: 3857

I'm afraid you can't. A class can have an array default property or an ordinal-type default property but not a string.

Upvotes: 0

Related Questions