开发者

Default property for class in delphi 7

开发者 https://www.devze.com 2023-01-31 01:26 出处:网络
I\'d like to ask on how to se开发者_C百科t 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 do

I'd like to ask on how to se开发者_C百科t 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 := '..';


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号