在Delphi中嵌套属性 [英] Nested Attributes in Delphi
本文介绍了在Delphi中嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有在Delphi中使用嵌套属性的方法吗?目前我使用德尔福XE。
Is there a way to use nested attributes in Delphi? At the moment I'm using Delphi XE.
例如:
TCompoundAttribute = class (TCustomAttribute)
public
constructor Create (A1, A2 : TCustomAttribute)
end;
和使用将是
[ TCompoundAttribute (TSomeAttribute ('foo'), TOtherAttribute ('bar')) ]
目前,这导致了一个内部错误。这将是一个很好的功能属性上创建一些布尔前pressions。
At the moment this leads to an internal error. This would be a nice feature to create some boolean expressions on attributes.
推荐答案
我觉得你的意思是创建方法的默认属性。
I think you mean default attributes of create method.
像这样的东西应该工作:
Something like this should be working:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFoo = class
private
FA1: string;
FA2: string;
{ Private declarations }
public
procedure Show;
constructor Create (a1: string = 'foo'; a2: string = 'bar');
end;
var
o : Tfoo;
implementation
{$R *.dfm}
procedure Tfoo.show;
begin
ShowMessage(FA1 + ' ' + FA2);
end;
constructor Tfoo.create (a1: string = 'foo'; a2: string = 'bar');
begin
FA1 := a1;
FA2 := a2;
end;
begin
o := Tfoo.create;
o.show; //will show 'foo bar'
o.Free;
o := Tfoo.create('123');
o.show; //will show '123 bar'
o.Free;
o := Tfoo.create('123', '456');
o.show; //will show '123 456'
o.Free;
//etc..
end.
这篇关于在Delphi中嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文