Incompatible types for different pointer types

941 Views Asked by At

I am using quick report 6 in Delphi 10.2. When I add quickreport source path to library paths I am getting Incompatible type errors on qrpdffilt.pas.

Var
  P: ^ pos2table;
  Buff: array of ansichar;
  d: dword;
  RGBCol:TRGBColor;
  PColor: TColor;

  Pos2table is of type packed array

  Incompatible types issue comes for following lines

  P:=@Buff[d];
  RGBCol:=pcolor;

Any solution?

1

There are 1 best solutions below

2
On

P := @Buff[d]; is assigning an ^AnsiChar pointer to a ^pos2table pointer, so of course the compiler will complain since they are pointers to different types, but only if you have type-checked pointers enabled, in which case you need to use a typecast to resolve it, eg:

type
  ppos2table = ^pos2table;
var
  P: ppos2table;
  Buff: array of ansichar;
  ...

P := ppos2table(@Buff[d]);

RGBCol:=pcolor; is trying to assign a TColor (an integer type, not a pointer type) to a TRGBColor (presumably a record type). There is no standard implicit conversion between them, so the compiler complains about this. You can use a pointer typecast to resolve this, too:

type
  PRGBColor = ^TRGBColor;
var
  ...
  RGBCol: TRGBColor;
  PColor: TColor;
  ...

RGBCol := PRGBColor(@pcolor)^;