2

Getting this error while I am trying to run /compile/build a Proiject

       Incompatible Types : “TBitmap” and “TObject”

The cursor is pointing to Bitmap := FSectionList.BackgroundBitmap

Kindly help me figure it out. Struck here like a ambulance in heavy traffic

Here is the part of the code:-

procedure ThtmlViewer.DoBackground1(ACanvas: TCanvas; ATop, AWidth, AHeight, FullHeight: integer);
var
  ARect: TRect;
  Bitmap, Mask: TBitmap;
  PRec: PtPositionRec;
  BW, BH, X, Y, X2, Y2, IW, IH, XOff, YOff: integer;
  Fixed: boolean;

begin
ARect := Rect(0, 0, AWidth, AHeight);
Bitmap := FSectionList.BackgroundBitmap;    
if FSectionList.ShowImages and Assigned(Bitmap) then
  begin
  Mask := FSectionList.BackgroundMask;
  BW := Bitmap.Width;
  BH := Bitmap.Height;
  PRec := FSectionList.BackgroundPRec;
  Fixed := PRec[1].Fixed;
  if Fixed then
    begin  {fixed background}
    XOff := 0;
    YOff := 0;
    IW := AWidth;
    IH := AHeight;
    end
  else
    begin   {scrolling background}
    XOff := 0;
    YOff := ATop;
    IW := AWidth;
    IH := FullHeight;
    end;
  CalcBckgrndLoctionAndTilng(PRec, ARect, XOff, YOff, IW, IH, BW, BH, X, Y, X2, Y2);

  DrwBckgrnd(ACanvas, ARect, X, Y, X2, Y2, Bitmap, Mask, BW, BH, PaintPanel.Color);
  end
else
  begin  {no background image, show color only}
  DrwBckgrnd(ACanvas, ARect, 0,0,0,0, Nil, Nil, 0, 0, PaintPanel.Color);
  end;
end;

Thanks and Regards Vas

1
  • What's FSectionList? It looks like FSectionList.BackgroundBitmap is a TObject, for some reason..
    – Blorgbeard
    Aug 13, 2009 at 20:33

2 Answers 2

6

I'm only guessing, but from the error message and the name of FSectionList, it's some kind of List which holds generic TObject instances and BackgroundBitmap is one of them.

You would need to cast it back as a TBitmap:

Bitmap := FSectionList.BackgroundBitmap as TBitMap;
1
  • Hey Francois!It worked at least the above error is gone and some new errors propped up(though at unrelated places, will have to check them). Thank you very much! Vas
    – vas
    Aug 13, 2009 at 21:00
1

It looks like there's some confusion for the compiler between the TBitmap defined in Windows.pas and the TBitmap class defined in Graphics.pas. It seems to think you're trying to assign a Graphics.TBitmap to a Windows.TBitmap.

You can fix it by changing the declaration of Bitmap to either Windows.TBitmap or Graphics.TBitmap. You didn't include any info on FSectionList, but what's causing the problem is probably the line


var
  Bitmap, Mask: TBitmap;

Change that to one of the following:


  Bitmap, Mask: Graphics.TBitmap;

or

  Bitmap, Mask: Windows: TBitmap;

I can't tell you which to use, because I don't know what FSectionList is holding there; adding one of them and then trying to compile should decide for you. I'd suspect you'll need Windows, though, based on the error message.

2
  • We can conclude that Bitmap is supposed to be a Graphics.TBitmap based on how it's used. Windows.TBitmap has no member named Height. Also, hardly anyone actually uses the Windows record anyway. Another way to solve this is to use the Graphics unit after the Windows unit. Aug 13, 2009 at 20:43
  • Hey Ken! Thanks for the reply! The error was pointing to (11th line) Bitmap := FSectionList.BackgroundBitmap; When I tried "Bitmap, Mask: Windows.TBitmap;"...It was showing a few NEW errors. "Constant or type identifier expected" "," or ":" expected but ";" found When I tried "Bitmap, Mask: Graphics.TBitmap;"...It was showing the same OLD error. -Vas
    – vas
    Aug 13, 2009 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.