vas
vas

Reputation: 2096

Delphi 4 error:- Incompatible Types : “TBitmap” and “TObject”

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

Upvotes: 2

Views: 2033

Answers (2)

Francesca
Francesca

Reputation: 21640

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;

Upvotes: 6

Ken White
Ken White

Reputation: 125620

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.

Upvotes: 1

Related Questions