[fpc-pascal] Find the nature of a pointer

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Fri Sep 1 19:54:53 CEST 2006


Hello,

I have a function that will receive a Handle. That handle could be a
pointer to a structure, or a object. Is there any safe way to discover
it's nature?

The following code will work when the Handle is an Object or nil, but
will crash the application when the Handle is a structure:

function TQtWidgetSet.IsValidGDIObject(const GDIObject: HGDIOBJ): Boolean;
var
  aObject: TObject;
begin
  Result := False;

  if GDIObject = 0 then Exit;

  aObject := TObject(GDIObject);

  if aObject is TObject then
  begin
    Result := (aObject is TQtFont) or (aObject is TQtBrush);
  end;
end;


thanks,
-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list