Recent

Author Topic: New version of Lazarus and the code doesn't compile  (Read 7889 times)

ykot

  • Full Member
  • ***
  • Posts: 141
New version of Lazarus and the code doesn't compile
« on: December 12, 2008, 06:34:32 am »
Hi,

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: [Select]

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

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

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

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

 MipMap:= nil;
end;    


Complete declaration of the class is:
Code: [Select]

type
 TDX7LockableTexture = class(TCustomLockableTexture)
 private
  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;
 protected
  procedure UpdateSize(); override;

  function CreateTexture(): Boolean; override;
  procedure DestroyTexture(); override;
 public
  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;


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?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8089
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: New version of Lazarus and the code doesn
« Reply #1 on: December 12, 2008, 11:49:57 am »
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.

ykot

  • Full Member
  • ***
  • Posts: 141
New version of Lazarus and the code doesn't compile
« Reply #2 on: December 12, 2008, 07:52:14 pm »
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?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8089
  • Programming + Glam Metal + Tae Kwon Do = Me
New version of Lazarus and the code doesn't compile
« Reply #3 on: December 13, 2008, 07:16:24 am »
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.

ykot

  • Full Member
  • ***
  • Posts: 141
New version of Lazarus and the code doesn't compile
« Reply #4 on: December 14, 2008, 05:22:00 am »
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!