delphi - 在 Delphi 中为 TObject 分配属性

标签 delphi

是否可以在 Delphi 中将属性分配给 TObject?所以我以后可以用它做点什么?

例如,我正在创建一个菜单,我希望菜单中的一个项目具有 isActive 属性,以便稍后检查它的样式。

这可能吗?

类似于:

Object.setAttribute('isActive', true);

最佳答案

Delphi 知道可以用来向现有类添加功能的类助手。 你可以尝试例如:

TObjectHelper = class helper for TObject
private
  function GetMyProp: string;
  procedure SetMyProp(const Value: string);
public
  property myprop:string read GetMyProp write SetMyProp;
end;

请注意,我发现子类化是一种更合乎逻辑的方法。

关于delphi - 在 Delphi 中为 TObject 分配属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55793555/

相关文章:

Delphi 网络共享与多个网络适配器

delphi - 如何设置结果值?

string - 如何在字符串中存储和加载键值对列表?

delphi - 如何用Delphi控制相机

Delphi - 备忘录右键单击获取行号

delphi - 使用带有泛型列表的 Rtti 调用 GetEnumerator 发生访问冲突

德尔福GetClass

delphi - Apache 2.2模块

mysql - Zeoslib : How to tell when query execution is complete?

Delphi:TJvChangeNotify/TShellChangeNotifier - 文件名