Forum > DirectX

New version of Lazarus and the code doesn't compile



After updating Lazarus from 9.24 to 9.26 the code that previously worked now does not.

I am getting the message: "function header doesn't match any method of this class".

The function which is supposedly at error is:

--- Code: ---
procedure TDX7LockableTexture.LockRect(Rect: PRect; Level: Integer;
 out Bits: Pointer; out Pitch: Integer);
 MipMap : IDirectDrawSurface7;
 MipDesc: TDDSurfaceDesc2;
 Bits := nil;
 Pitch:= 0;

 MipMap:= GetSurfaceLevel(Level);
 if (MipMap = nil) then
   Errors.Insert(errInvalidCall, Self, ClassName, 'LockRect');

 FillChar(MipDesc, SizeOf(TDDSurfaceDesc2), 0);
 MipDesc.dwSize:= SizeOf(TDDSurfaceDesc2);

 if (Succeeded(MipMap.Lock(Rect, MipDesc, DDLOCK_SURFACEMEMORYPTR or
  DDLOCK_WAIT, 0))) then
   Bits := MipDesc.lpSurface;
   Pitch:= MipDesc.lPitch;
  end else Errors.Insert(errAccessTexture, Self, ClassName, 'LockRect');

 MipMap:= nil;

--- End code ---

Complete declaration of the class is:

--- Code: ---
 TDX7LockableTexture = class(TCustomLockableTexture)
  FSurface: IDirectDrawSurface7;
  FSurfaceDesc: TDDSurfaceDesc2;

  LockedRect: TRect;

  procedure InitSurfaceDesc();
  function CreateTextureInstance(): Boolean;
  procedure DestroyTextureInstance();
  function GetSurfaceLevel(Level: Integer): IDirectDrawSurface7;
  function GetSizeOfLevel(Level: Integer): TPoint2px;
  procedure LockRect(Rect: PRect; Level: Integer; out Bits: Pointer;
   out Pitch: Integer);
  procedure UnlockRect(Rect: PRect; Level: Integer);
  function GetLockRectPtr(Rect: PRect): PRect;
  function GetPixelData(Level: Integer; Buffer: TSystemSurface): Boolean;
  function SetPixelData(Level: Integer; Buffer: TSystemSurface): Boolean;
  function MakeMipmap(DestNo, SrcNo: Integer): Boolean;
  procedure UpdateSize(); override;

  function CreateTexture(): Boolean; override;
  procedure DestroyTexture(); override;
  property Surface: IDirectDrawSurface7 read FSurface;
  property SurfaceDesc: TDDSurfaceDesc2 read FSurfaceDesc;

  procedure Bind(Stage: Integer); override;

  procedure UpdateMipmaps(); override;

  procedure Lock(const Rect: TRect; out Bits: Pointer;
   out Pitch: Integer); override;
  procedure Unlock(); override;

  constructor Create(); override;

--- End code ---

What's interesting is that if I copy and paste the supposedly erroneous function BELOW some other function, now the error appears at other function, e.g. UnlockRect, UpdateMipmaps, whatever. Seems like the compiler just don't want to compile the code below certain point in this unit.

Anyone had this issue before? Is there an option I need to be looking at to fix this?

I guess it's just a syntax error as that message comes at parsing stage. Perhaps there's an unclosed block or something similar. Could you post the whole compiler messages? If the unit is not too big, I guess it's OK to post it too.

Indeed it's some sort of syntax issue.

Apparently, it didn't like "Rect: PRect" parameter. Changing it to "const Rect: TRect" makes the error disappear. Also, on the top of the unit putting "type PRect = ^TRect" fixes the issue, even though PRect is already defined in Lazarus units. I never redefine PRect in my code.

Any reason why would PRect generate this problem?

Check the uses clause, do you use platform specific units (e.g. windows)?. Windows also defines TRect so it may conflict with the one defined by Lazarus (or FPC). I don't know in what unit, just hold ctrl and click TRect in your code to bring you to unit where it's defined.

Indeed the unit "windows" was included in implementation section, which redefined PRect, making the function header different than in interface section. Easily solved by putting windows unit in the interface section instead.

Thanks a lot!


[0] Message Index

Go to full version