大佬教程收集整理的这篇文章主要介绍了Delphi属性需要一个常量参数吗?如果是这样,为什么?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
program AttributesTestProgram; {$APPTYPE CONSOLE} uses SysUtils,Classes,RTTI; type TDisplayTextAttribute = class(TCustomAttributE) private FDisplayText: String; public constructor Create(aDisplayText: String); property DisplayText: String read FDisplayText write FDisplayText; end; constructor TDisplayTextAttribute.Create(aDisplayText: String); begin FDisplayText := aDisplayText; end; function GetFirstName: String; begin Result := 'First Name'; end; type TCustomer = Class(TObject) private FFirstName: String; FLastName: String; FStreetAddress: String; FZIP: String; FState: String; FCity: String; FPhone: String; published [TDisplayTextAttribute(GetFirstName)] property FirstName: String read FFirstName write FFirstName; end; begin // Code that does the work removed for clarity.... Readln; end.
我很自然地想知道为什么这个错误无法编译:
[DCC Error] AttributesTestProgram.dpr(40): E2026 Constant expression expected
我认为它与属性必须在编译器时间绑定的想法有关,或者沿着那些行绑定.
因此,我的问题是这样的:
有没有办法在这里“击败系统”并获得属性中的那个点的运行时值?
您可以通过为属性提供无参数构造函数(或根本没有构造函数)并将DisplayText属性更改为接受字符串或可从中提取字符串的对象的方法来击败系统.
以上是大佬教程为你收集整理的Delphi属性需要一个常量参数吗?如果是这样,为什么?全部内容,希望文章能够帮你解决Delphi属性需要一个常量参数吗?如果是这样,为什么?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。