Forward declarations for record types

懵懂的女人 提交于 2020-01-11 05:35:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16344358/forward-declarations-for-record-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!