tags:

views:

178

answers:

2

Hello! 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  A: 

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.

Ken White
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.
Rob Kennedy
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 ";" foundWhen I tried "Bitmap, Mask: Graphics.TBitmap;"...It was showing the same OLD error.-Vas
vas
+5  A: 

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;
François
Nice catch! I missed that!
Ken White
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