How to catch a moment when the external editor of TOLEContainer has been closed?

你。 提交于 2020-01-22 02:03:52

问题


Borland Developer Studio 2006, Delphi:

I have a TOLEContainer object with AllowInPlace=False. When the external editor is closed and changed my OLE object I have to do something with this OLE object inside TOLeContainer.

The problem is I can't catch a moment when the external editor is closed. OnDeactivate event is not working.

Probably I should change the source code of TOLEContainer adding this event myself, but I don't know where is the best place for it.

Can you advice some method?


回答1:


A simple example which does not need modifying the VCL sources;

uses
  .., activex;

type
  TForm1 = class(TForm, IAdviseSink)
    ..
    Button1: TButton;
    OleContainer1: TOleContainer;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    Connection: Longint;
    procedure CloseConnection;
    procedure OnDataChange(const formatetc: TFormatEtc; const stgmed: TStgMedium);
      stdcall;
    procedure OnViewChange(dwAspect: Longint; lindex: Longint);
      stdcall;
    procedure OnRename(const mk: IMoniker); stdcall;
    procedure OnSave; stdcall;
    procedure OnClose; stdcall;
  public
  end;

implementation

procedure TForm1.OnDataChange(const formatetc: TFormatEtc;
  const stgmed: TStgMedium);
begin
end;

procedure TForm1.OnRename(const mk: IMoniker);
begin
end;

procedure TForm1.OnSave;
begin
end;

procedure TForm1.OnViewChange(dwAspect, lindex: Integer);
begin
end;

procedure TForm1.OnClose;
begin
  ShowMessage('not editing anymore!');
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  if OleContainer1.InsertObjectDialog then begin
    CloseConnection;
    OleContainer1.OleObjectInterface.Advise(IAdviseSink(Self), Connection);
  end;
end;

procedure TForm1.CloseConnection;
begin
  if Connection <> 0 then
    if OleContainer1.OleObjectInterface.Unadvise(Connection) = S_OK then
      Connection := 0;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  CloseConnection;
end;



回答2:


The OLE object calls OnShowWindow method of the IOleClientSite interface (implemented by TOleContainer). The fShow parameter indicates whether the object's window is being opened or closed.



来源:https://stackoverflow.com/questions/2880090/how-to-catch-a-moment-when-the-external-editor-of-tolecontainer-has-been-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!