Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward declarations for record types

Tags:

types

delphi

Is there such a thing as in the title? I'm trying to do this in part of converting an API structure, and run into something I haven't encountered before:

PFNReaderTranslatedDispatch = function(var msg: TMsg): BOOL; stdcall;
PFNReaderScroll = function(var prmi: TReaderModeInfo; dx, dy: integer): BOOL; stdcall;
TReaderModeInfo = record
  cbSize: DWord;
  hWnd: THandle;
  fFlags: DWord;
  prc: PRect;
  pfnScroll: PFNReaderScroll;
  fFlags2: PFNReaderTranslatedDispatch;
  lParam: DWord;
end;
PReaderModeInfo = ^TReaderModeInfo;

Those who know Delphi will see the obvious problem. How would you work around this?

like image 633
Glenn1234 Avatar asked May 02 '13 17:05

Glenn1234


1 Answers

I think this is the simplest solution:

PFNReaderTranslatedDispatch = function(var msg: TMsg): BOOL; stdcall;
PReaderModeInfo = ^TReaderModeInfo;
PFNReaderScroll = function(prmi: PReaderModeInfo; dx, dy: integer): BOOL; stdcall;
TReaderModeInfo = record
  cbSize: DWord;
  hWnd: THandle;
  fFlags: DWord;
  prc: PRect;
  pfnScroll: PFNReaderScroll;
  fFlags2: PFNReaderTranslatedDispatch;
  lParam: DWord;
end;

Indeed, you can clearly reaplce a var parameter by a (by-value) pointer parameter. And there is no problem declaring PReaderModeInfo before TReaderModeInfo.

like image 196
Andreas Rejbrand Avatar answered Oct 14 '22 08:10

Andreas Rejbrand