当TOLEContainer的外部编辑器已关闭时,如何抓住时机? [英] How to catch a moment when the external editor of TOLEContainer has been closed?

查看:200
本文介绍了当TOLEContainer的外部编辑器已关闭时,如何抓住时机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有AllowInPlace = False的TOLEContainer对象,Borland Developer Studio 2006,Delphi:



当外部编辑器关闭并更改我的OLE对象时,我必须在TOLeContainer内的这个OLE对象上执行某些操作。



当外部编辑器关闭时,问题是我无法捕捉到。 OnDeactivate事件不起作用。



我可能应该更改自己添加此事件的TOLEContainer的源代码,但我不知道它的最佳位置在哪里。 / p>

你能建议一些方法吗?

解决方案

一个简单的例子,不需要修改VCL源;

 使用
..,activex;

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

实现

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

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

程序TForm1.OnSave;
begin
end;

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

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


程序TForm1.Button1Click(发件人:TObject);
begin
如果OleContainer1.InsertObjectDialog然后开始
CloseConnection;
OleContainer1.OleObjectInterface.Advise(IAdviseSink(Self),Connection);
结束
结束

程序TForm1.CloseConnection;
begin
如果Connection<> 0然后
如果OleContainer1.OleObjectInterface.Unadvise(Connection)= S_OK然后
连接:= 0;
结束

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


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?

解决方案

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;

这篇关于当TOLEContainer的外部编辑器已关闭时,如何抓住时机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆