加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 在TWinControl类上添加属性

发布时间:2020-12-15 09:42:25 所属栏目:大数据 来源:网络整理
导读:我想将已发布的属性添加到TWinControl中. 有没有必要重新编译基本源代码? 如果没有,有一些方法重新编译基本源代码没有太多麻烦? 请咨询…… 编辑新思路的原因 好吧,我正在考虑做什么我试图从System.pas覆盖_GetMem类 继承自TWinControl. 为什么?因为我会
我想将已发布的属性添加到TWinControl中.
有没有必要重新编译基本源代码?

如果没有,有一些方法重新编译基本源代码没有太多麻烦?

请咨询……

编辑新思路的原因

好吧,我正在考虑做什么我试图从System.pas覆盖_GetMem类
继承自TWinControl.
为什么?因为我会为对象分配一些额外的空间足够一个整数.
为什么是整数?因为这样我可以添加任何指向对象的指针.
所以在TWinControl的辅助类上,我可以创建一个Get a Set函数来访问这个内存空间.
好不是吗?这该怎么做 ?
重写GetMem过程我可以使用在FastCode上使用的相同策略,创建一个跳转到新过程.

我现在需要的是理解这个内存分配如何工作InstanceSize来覆盖它.
总之,我正在研究Delphi如何做到这一点…而在DFM上添加它我将以同样的方式,我将创建一个跳线到文件管理器.

有人有想法在对象中添加新空间吗?我需要覆盖哪种方法?跳线我知道怎么做.

再来一次.

编辑=进化

我认为我注射了记忆.
我需要做更多的测试.
我刚刚做到了,我现在不关心优化,如果有人想测试它,这里就是代码.
只需将该单元添加为项目的第一个单元即可.

unit uMemInjection;


interface

uses
  Controls;

type
  THelperWinControl = class Helper for TWinControl
  private
    function RfInstanceSize: Longint;
    function GetInteger: Integer;
    procedure SetInteger(const Value: Integer);
  public
    property RfInteger: Integer read GetInteger write SetInteger;
  end;

implementation

uses
  Windows;

procedure SInstanceSize;
asm
  call TWinControl.InstanceSize
end;

function THelperWinControl.GetInteger: Integer;
begin
  Result := Integer(PInteger(Integer(Self) + (Self.InstanceSize - SizeOf(Integer)))^);
end;

function THelperWinControl.RfInstanceSize: Longint;
begin
  Result := PInteger(Integer(Self) + vmtInstanceSize)^;
  Result := Result + SizeOf(Integer);
end;

/////////////////////////////////////////////// FastCode ///////////////////////////////////////////////
type
  PJump = ^TJump;
  TJump = packed record
    OpCode: Byte;
    Distance: Pointer;
  end;

function FastcodeGetAddress(AStub: Pointer): Pointer;
begin
  if PBYTE(AStub)^ = $E8 then
  begin
    Inc(Integer(AStub));
    Result := Pointer(Integer(AStub) + SizeOf(Pointer) + PInteger(AStub)^);
  end
  else
    Result := nil;
end;

procedure FastcodeAddressPatch(const ASource,ADestination: Pointer);
const
  Size = SizeOf(TJump);
var
  NewJump: PJump;
  OldProtect: Cardinal;
begin
  if VirtualProtect(ASource,Size,PAGE_EXECUTE_READWRITE,OldProtect) then
  begin
    NewJump := PJump(ASource);
    NewJump.OpCode := $E9;
    NewJump.Distance := Pointer(Integer(ADestination) - Integer(ASource) - 5);

    FlushInstructionCache(GetCurrentProcess,ASource,SizeOf(TJump));
    VirtualProtect(ASource,OldProtect,@OldProtect);
  end;
end;

/////////////////////////////////////////////// FastCode /////////////////////////////////////////////// 


{ THelperWinControl }
procedure THelperWinControl.SetInteger(const Value: Integer);
begin
  PInteger(Integer(Self) + (Self.InstanceSize - SizeOf(Integer)))^ := Value;
end;

initialization
  FastcodeAddressPatch(FastcodeGetAddress(@SInstanceSize),@TWinControl.RfInstanceSize);


end.

解决方法

感谢 Smasher,我记得Delphi团队如何使用类帮助程序和设计器技巧为Delphi 2007添加属性,而不会破坏与Delphi 2006的二进制兼容性.

关于如何执行此操作,请参阅0700到Hallvard Vassbotn.

我认为它解决了大部分问题,如果不是全部的话.

在文章中寻找这些东西:

> TCustomFormHelper = TCustomForm的类助手
> FPixelsPerInch存储黑客攻击
>注入设计时属性
>定义流媒体属性

但是,当您从外部世界挂钩到TWinControl时,您将不得不以自己的方式进行流式传输,但这也许是可能的.

–jeroen

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读