【发布时间】:2016-06-17 06:13:00
【问题描述】:
如何在 Delphi 10.1 Berlin 中访问私有方法 TStreamReader.FillBuffer,我们在 10.1 之前使用类助手完成了它 - 但建议的解决方案不起作用:
uses System.Rtti;
procedure TForm1.FormCreate(Sender: TObject);
begin
Assert(Assigned(TRttiContext.Create.GetType(TStreamReader).GetMethod('FillBuffer')),
'Failed');
end;
它失败只是因为 GetMethod 返回 NIL。任何想法为什么会失败?
编辑: 我确实想知道为什么会失败
【问题讨论】:
-
它可能会失败,因为它没有在启用扩展 RTTI 的情况下编译。
-
你在这里看到@LURD 的回答了吗:stackoverflow.com/questions/36716363/…
-
@Rudy:我尝试在我的 unit1.pas 中添加 {$METHODINFO ON} 但我认为这应该在 system.classes 中完成(其中声明了 TStreamReader)。
-
@MartynA:
TMethod(P).Code := @TStreamReader.FillBuffer确实有效,谢谢,请添加为答案 -
很高兴它起作用了,但我认为如果您添加自己的答案会更好,因为我不知道您最终使用了什么代码。
标签: delphi delphi-10.1-berlin class-helpers