(轉)TComboBox patch for Delphi 7

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   ar   for   art   

unit D7ComboBoxStringsGetPatch; // The patch fixes TCustomComboBoxStrings.Get method for empty string item in Delphi 7. interface {$IF RTLVersion <> 15.0}‘This patch is intended for Delphi 7 only‘;{$IFEND} implementation uses  Windows, SysUtils, StdCtrls; resourcestring  RsPatchingFailed = ‘TCustomComboBoxStrings.Get patching failed.‘; type  TPatchResult = (prNotNeeded, prOk, prError); function PatchCode(RoutineStartAddr: Pointer; PatchOffset: Cardinal; OriginalCode: Pointer;  OriginalCodeLen: Cardinal; PatchedCode: Pointer; PatchedCodeLen: Cardinal): TPatchResult;const  JmpOpCode = $25FF;type  PPackageThunk = ^TPackageThunk;  TPackageThunk = packed record    JmpInstruction: Word;    JmpAddress: PPointer;  end;var  CodeStart: Pointer;  BytesWritten: DWORD;begin  if FindClassHInstance(System.TObject) <> HInstance then    with PPackageThunk(RoutineStartAddr)^ do      if JmpInstruction = JmpOpCode then        RoutineStartAddr := JmpAddress^      else      begin        Result := prError;        Exit;      end;  CodeStart := Pointer(LongWord(RoutineStartAddr) + PatchOffset);  if CompareMem(CodeStart, OriginalCode, OriginalCodeLen) then  begin    if WriteProcessMemory(GetCurrentProcess, CodeStart, PatchedCode, PatchedCodeLen, BytesWritten) and      (BytesWritten = PatchedCodeLen) then    begin      FlushInstructionCache(GetCurrentProcess, CodeStart, PatchedCodeLen);      Result := prOk;    end    else      Result := prError;  end  else    Result := prNotNeeded;end; type  TCustomComboBoxStringsHack = class(TCustomComboBoxStrings); function AddrOfTCustomComboBoxStringsGet: Pointer;begin  Result := @TCustomComboBoxStringsHack.Get;end; procedure PatchTCustomComboBoxStringsGet;const  OriginalCode: Cardinal  = $74FFF883; // CMP EAX, -1 | JZ  +$26  PatchedCode: Cardinal   = $7E00F883; // CMP EAX,  0 | JLE +$26  PatchOffset             = $1F;  // for DEBUG DCU by Pavel Rogulin  OriginalCodeD: Cardinal = $FFF07D83;  PatchedCodeD: Cardinal  = $00F07D83;  PatchOffsetD            = $2E;var  PatchResult: TPatchResult;begin  PatchResult := PatchCode(AddrOfTCustomComboBoxStringsGet, PatchOffset, @OriginalCode, SizeOf(OriginalCode),    @PatchedCode, SizeOf(PatchedCode));  if PatchResult = prNotNeeded then    PatchResult := PatchCode(AddrOfTCustomComboBoxStringsGet, PatchOffsetD, @OriginalCodeD, SizeOf(OriginalCodeD),      @PatchedCodeD, SizeOf(PatchedCodeD));  case PatchResult of    prError:      begin        if IsConsole then          WriteLn(ErrOutput, RsPatchingFailed)        else          MessageBox(0, PChar(RsPatchingFailed), nil, MB_OK or MB_ICONSTOP or MB_TASKMODAL);        RunError(1);      end;  end;end; initialization  PatchTCustomComboBoxStringsGet; end.

 

官方BUG解決地址:

http://cc.embarcadero.com/item/18872

(轉)TComboBox patch for Delphi 7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.