DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

CheckInternetConnection

Checks if a computer is connected to the internet by trying to resolve the name of the web host specified by AHost.

function CheckInternetConnection(AHost: PAnsiChar): Boolean;
var
  PHE: PHostEnt;
  GInitData: TWSAData;
begin
  WinSock.WSAStartup($101, GInitData);
  PHE := WinSock.GetHostByName(AHost);
  WinSock.WSACleanup;
  Result := (PHE <> nil);
end;

WBGetOpticalZoomRange

Gets the range of available optical zoom values, in precentage terms, for the document displayed in the given web browser control. If zoom range cannot be determined the range 0..0 is returned.

function WBGetOpticalZoomRange(WB: SHDocVw.TWebbrowser): TRange;
const
  OLECMDID_OPTICAL_GETZOOMRANGE = $00000040;
var
  InParam, OutParam: OleVariant;
begin
  OutParam := Variants.Null;
  if WBInvokeCmd(
    WB,
    False,
    OLECMDID_OPTICAL_GETZOOMRANGE,
    SHDocVw.OLECMDEXECOPT_DODEFAULT,
    InParam,
    OutParam
  ) then
    Result := Range(
      SysUtils.LongRec(Cardinal(OutParam)).Lo,
      SysUtils.LongRec(Cardinal(OutParam)).Hi
    )
  else
    Result := Range(0, 0);
end;

WBSetOpticalZoom

Sets the given optical zoom value for the current document in web browser control WB to the percentage value ZoomPercent. Returns the zoom value actually set or -1 on failure.

function WBSetOpticalZoom(WB: SHDocVw.TWebbrowser; ZoomPercent: Cardinal):
  Integer;
const
  OLECMDID_OPTICAL_ZOOM = $0000003F;
var
  InParam, OutParam: OleVariant;
begin
  InParam := ZoomPercent;
  OutParam := Variants.Null;
  if WBInvokeCmd(
    WB,
    False,
    OLECMDID_OPTICAL_ZOOM,
    SHDocVw.OLECMDEXECOPT_DODEFAULT,
    InParam,
    OutParam
  ) and (Variants.VarType(OutParam) = varInteger) then
    Result := OutParam
  else
    Result := -1;
end;

View the whole database.

Go to the DelphiDabbler website.