RRUZ / vcl-styles-utils

Extend and improve the Delphi VCL Styles
https://theroadtodelphi.wordpress.com/
331 stars 114 forks source link

Delphi 10.4 v1compatibility undeclared identifier #267

Closed Soiware closed 4 years ago

Soiware commented 4 years ago

Running the demo project "Vcl Styles Utils TTaskDialog (Demo App)", these compiler issues are rised in unit Vcl.Styles.UxTheme:

[dcc32 Error] Vcl.Styles.UxTheme.pas(4548): E2003 Undeclared identifier: 'v1compatibility' [dcc32 Error] Vcl.Styles.UxTheme.pas(4563): E2250 There is no overloaded version of 'InterceptCreate' that can be called with these arguments

I tryed assigning 0 to default parameter value instead of v1compatibility:

function InterceptCreateOrdinal(const Module: string; MethodName: Integer; const InterceptProc: Pointer;
  ForceLoadModule: Boolean = True; Options: Byte =  v1compatibility): Pointer;

And removed options here:

  Result := DDetours.InterceptCreate(pOrgPointer, InterceptProc, Options);

Just to test other issues. So it compiles.

And then these new isssues arises in unit Vcl.Styles.Hooks:

[dcc32 Error] Vcl.Styles.Hooks.pas(849): E2003 Undeclared identifier: 'BeginHooks' [dcc32 Error] Vcl.Styles.Hooks.pas(871): E2003 Undeclared identifier: 'EndHooks'

Maybe something missinsg in my installation? I've downloaded the code both for vcl-styles-utils-master.zip and DDetours-master.zip Many thanks

rickard67 commented 4 years ago

If you use Detours version 2.2 - try the following changes:

Vcl.Styles.UxThemes

function InterceptCreateOrdinal(const Module: string; MethodName: Integer; const InterceptProc: Pointer;
  ForceLoadModule: Boolean = True; const Options: TInterceptOptions = DefaultInterceptOptions): Pointer;
var
  pOrgPointer: Pointer;
  LModule: THandle;
begin
  Result := nil;
  LModule := GetModuleHandle(PChar(Module));
  if (LModule = 0) and ForceLoadModule then
    LModule := LoadLibrary(PChar(Module));

  if LModule <> 0 then
  begin
    pOrgPointer := GetProcAddress(LModule, PChar(MethodName));
    if Assigned(pOrgPointer) then
      DDetours.InterceptCreate(pOrgPointer, InterceptProc, Result, nil, Options);
  end;
end;

Vcl.Styles.Hooks

Replace all BeginHooks..EndHooks and BeginUnHooks..EndUnHooks with:

var
  hnd: THandle;

hnd := BeginTransaction();

...

EndTransaction(hnd);

/Rickard

Soiware commented 4 years ago

Yes it works!. In finalization section I've this code in Vcl.Styles.Hooks:

finalization

  BeginUnHooks;  // <----------- Compiler error message
  InterceptRemove(@Trampoline_user32_GetSysColor);
  InterceptRemove(@Trampoline_user32_GetSysColorBrush);
  InterceptRemove(@Trampoline_user32_FillRect);
  InterceptRemove(@Trampoline_user32_DrawEdge);
  InterceptRemove(@Trampoline_user32_DrawFrameControl);
  InterceptRemove(@Trampoline_user32_LoadIconW);

{$IFDEF HOOK_UXTHEME}
  if TOSVersion.Check(6) then
    InterceptRemove(@Trampoline_user32_LoadImageW);
{$ENDIF HOOK_UXTHEME}
  InterceptRemove(@Trampoline_SetStyle);

{$IFDEF HOOK_TDateTimePicker}
  {$IF CompilerVersion>=29}
  InterceptRemove(@Trampoline_SetWindowTheme);
  {$IFEND CompilerVersion}
{$ENDIF HOOK_TDateTimePicker}

  EndUnHooks; // <----------- Compiler error message
  VCLStylesBrush.Free;
  VCLStylesLock.Free;
  VCLStylesLock := nil;

I tryed to fix with

var
  hnd: THandle;

hnd := BeginTransaction();

...

EndTransaction(hnd);

It compiles and I can run demos.