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
精彩评论