Ver Mensaje Individual
  #2  
Antiguo 20-03-2012
prietor prietor is offline
Registrado
NULL
 
Registrado: mar 2012
Posts: 2
Reputación: 0
prietor Va por buen camino
Thumbs up

Después de mucho buscar, he encontrado un workaround relativamente limpio basado en controlar el destroy y create del handler de la ventana del TOleControl embebido para cambiarlo de Parent a nivel de handler de Windows. Al parecer la VCL no está diseñada para tratar correctamente el ciclo de destroy-create con dockables. Es un error de diseño de la VCL...

La solución más sencilla pasa por tocar el wrapper TLB tras importar el ActiveX. Para mi caso concreto, que utilizo un TSftTree embebido en un TForm dockable:

Código Delphi [-]
...
TSftTree = class(TOleControl)
  private
    ...
    ActualHandle: HWND;
  protected
    ...
    procedure DestroyWnd; override;
    procedure CreateWnd; override;
 public
...
implementation
uses ComObj, Controls, Forms;
...
procedure TSftTree.DestroyWnd;
begin
  if (csDestroying in ComponentState) then
    inherited//TOleControl:estroyWnd();
  else
  begin
    //Parent to the Application window which is 0x0 in size
    windows.SetParent(WindowHandle,Forms.Application.Handle);
    //save the WindowHandle
    ActualHandle := WindowHandle;
    //set it to 0 so Createwnd will be called again...
    WindowHandle := 0;
  end;
end;

procedure TSftTree.CreateWnd;
begin
  if (ActualHandle <> 0) then
  begin
    if (IsWindow(ActualHandle)) then
    begin
      WindowHandle := ActualHandle;
      ActualHandle := 0;
      windows.SetParent( WindowHandle, TWinControl(Self).Parent.Handle );
      //Force a resize on the client window
      MoveWindow( WindowHandle, 0, 0, TWinControl(Self).Parent.Width,TWinControl(Self).Parent.Height,true );
      //quick exit because there is NO need to create the window
      exit;
    end
  end;
  inherited;
end;
...

Un saludo!
Responder Con Cita