Overriding a component method in Delphi 7?

Based on this answer, I am trying to override the OnShowWindow TOleContainer method in Delphi 7.

 unit MyOleContainer; interface uses Windows, OleCtnrs; type TOleContainer = class(OleCtnrs.TOleContainer) private function OnShowWindow(fShow: BOOL): HResult; stdcall; override; end; implementation function TOleContainer.OnShowWindow(fShow: BOOL): HResult; begin Result := S_OK; end; end. 

But this will not compile the following error: [Error] MyOleContainer.pas(11): Field definition not allowed after methods or properties Why?

Edit:

Could you explain how to "declare an implementation of IOleClientSite, inherit from TOleContainer and hide the OnShowWindow method [...] use TOleContainer as IOleClientSite"?

Edit2:

Is that what you meant?

 TMyContainer = class(TOleContainer, IOleClientSite) private FIOleClientSite: IOleClientSite; function SaveObject: HResult; stdcall; ... constructor TMyContainer.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.OleObjectInterface.GetClientSite(FIOleClientSite); end; function TMyContainer.SaveObject: HResult; begin Result := FIOleClientSite.SaveObject; end; ... 
+4
source share
1 answer

The error message is a little misleading. This basically means that the override keyword cannot appear after the stdcall keyword.

This is a little aloof, but if you redefine a method, you do not need and should not reset the calling convention. You cannot change the calling convention when overriding a method, so itโ€™s best not to repeat it.

However, when you fix this problem, your code will still not compile. And this is because the OnShowWindow function OnShowWindow not virtual. Therefore, you cannot redefine it.

I donโ€™t see how you can change the behavior of the IOleClientSite.OnShowWindow implementation without re-declaring and re-implementing the entire IOleClientSite implementation. And I donโ€™t think itโ€™s easy to do.

+5
source

All Articles