delphi – 在TWinControl类上添加属性
我想将已发布的属性添加到TWinControl中.
有没有必要重新编译基本源代码? 如果没有,有一些方法重新编译基本源代码没有太多麻烦? 请咨询…… 编辑新思路的原因 好吧,我正在考虑做什么我试图从System.pas覆盖_GetMem类 我现在需要的是理解这个内存分配如何工作InstanceSize来覆盖它. 有人有想法在对象中添加新空间吗?我需要覆盖哪种方法?跳线我知道怎么做. 再来一次. 编辑=进化 我认为我注射了记忆. 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的类助手 但是,当您从外部世界挂钩到TWinControl时,您将不得不以自己的方式进行流式传输,但这也许是可能的. –jeroen (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |