Borland Developer Studio 2006,德尔福:
我有一个带有AllowInPlace=False 的TOLEContainer 对象。当外部编辑器关闭并更改我的 OLE 对象时,我必须在 TOLeContainer 内对这个 OLE 对象执行一些操作。
问题是当外部编辑器关闭时我无法捕捉到任何时刻。 OnDeactivate 事件不起作用。
也许我应该自己更改 TOLEContainer 的源代码添加此事件,但我不知道它的最佳位置在哪里。
你能建议一些方法吗?
一个简单的例子,不需要修改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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)