2004. október 26., kedd

How to determine the TImage graphic type at runtime


Problem/Question/Abstract:

Can someone tell me how I get to know the TImage graphic type at runtime? When I know the graphic type, I can choose different ways to save the image.picture to a blob field.

Answer:

Use RTTI like this:

if (Image.Picture.Graphic <> nil) then
begin
  if (Image.Picture.Graphic is TBitmap) then
    {... it's a bitmap ...}
  else if (Image.Picture.Graphic is TIcon) then
    {... it's an icon ...}
  else if (Image.Picture.Graphic is TMetaFile) then
    {... it's a meta file ...}
  else if (Image.Picture.Graphic is TJPEGImage) then
    {... it's a JPEG ...}
  else {... etc.}
end;

Nincsenek megjegyzések:

Megjegyzés küldése