2010-05-21 1 views
1

Delphi :TOLEContainer의 외부 편집기가 닫힌 순간을 잡는 방법은 무엇입니까?

AllowInPlace = False 인 TOLEContainer 개체가 있습니다. 외부 편집기가 닫히고 내 OLE 개체를 변경할 때 TOLeContainer 내에서이 OLE 개체로 뭔가를해야합니다.

문제는 외부 편집기가 닫힌 순간을 잡을 수 없다는 것입니다. OnDeactivate 이벤트가 작동하지 않습니다.

아마도이 이벤트를 직접 추가하는 TOLEContainer의 소스 코드를 변경해야하지만 어디에서 가장 적합한 지 알 수 없습니다.

몇 가지 방법을 조언 해 줄 수 있습니까?

답변

2

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; 
1

IOleClientSite 인터페이스 (TOleContainer 구현)의 OLE 개체는 OnShowWindow 메서드를 호출합니다. fShow 매개 변수는 개체의 창을 열거 나 닫을 지 여부를 나타냅니다.

관련 문제