DAX FAQs 1.0

by Conrad Herrmann
25 May 97
Updated 12 Feb 1998


Q: How do I obtain my control's site?

A: This function returns a pointer to a contained control's site.

function ClientSite( obj: IUnknown ): IOleClientSite;
var
  Site: IOleClientSite;
  OleObj: IOleObject;
begin
if (obj.QueryInterface( IOleObject, OleObj ) = S_OK) and
(OleObj.GetClientSite( Site ) = S_OK) then
  Result := Site
else
  Result := nil;
end; 

The obj parameter is your ActiveX Control. For example, you can call from

within a method of your control using the following code:

type TButtonX = class(TActiveXControl)
  ...
end;
...
procedure TButtonX.Click;
var 
  Site: IOleClientSite;
begin
  Site := ClientSite(Self);
end;

The site reference is the only means your control has for communicating with its container. By query-casting the site reference to other interfaces, your can gain access to extended container information. Some of the more interesting site interfaces: