如何捕捉 TOLEContainer 外部编辑器关闭的时刻?

发布于 2024-09-03 03:05:43 字数 285 浏览 9 评论 0原文

Borland Developer Studio 2006,Delphi:

我有一个带有AllowInPlace=False 的TOLEContainer 对象。当外部编辑器关闭并更改我的 OLE 对象时,我必须在 TOLeContainer 内对这个 OLE 对象执行一些操作。

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

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

你能建议一些方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安人多梦 2024-09-10 03:05:43

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

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;

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;
热情消退 2024-09-10 03:05:43

OLE 对象调用 OnShowWindow 方法IOleClientSite 接口(由TOleContainer 实现)。 fShow 参数指示对象的窗口是否正在打开或关闭。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文