Delphi 动态创建类

探讨了在Delphi环境下,如何利用System.Rtti库进行动态类创建,并提及了遇到的private成员无法通过RTTI获取的问题,参考了相关Delphi反射技术文章。
摘要由CSDN通过智能技术生成

昨天在看 Java Web 开发时有看到servlet 通过反射动态创建类,想到Delphi中能否实现。

 环境 Win10 x64 , Delphi 10.4  需引用 System.Rtti ;

发现 private 下的 function GetXY:Integer  没有获取到,why? Rtti设计就这样?

unit untTest;

interface

uses
  Classes,SysUtils,Dialogs;

type
  TTestClass = class(TPersistent)  //需继承TPersistent
    private
      FX:Integer;
      FY:Integer;
      FStr : string;
      function GetXY:Integer;
    public
      function DoAdd(x,y: Integer):Integer;
      procedure ShowMsgBox;

      property X: Integer read FX write FX;
      property Y: Integer read FY write FY;
      property STR: string read FStr write FStr;
      property XAY: Integer read GetXY;
  end;



implementation

{ TTestClass }

function TTestClass.DoAdd(x, y: Integer): Integer;
begin
  Result := x+y;
end;

function TTe
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值