Pascal 对象:如何进行类型化前向声明?
我正在将很棒的 fmod C 标头翻译为 Pascal,但由于前向声明而陷入困境。 如果我在类型之前声明函数,则错误为“FMOD_CODEC_STATE:未知”,如果我在函数之前声明FMOD_CODEC_STATE,则错误为“FMOD_CODEC_METADATACALLBACK:未知” 知道我该如何解决这个问题吗? 非常感谢 !
type
FMOD_CODEC_STATE = Record
numsubsounds: Integer;
waveformat: array[0..0] of FMOD_CODEC_WAVEFORMAT;
plugindata: Pointer;
filehandle: Pointer;
filesize: Cardinal;
fileread: FMOD_FILE_READCALLBACK;
fileseek: FMOD_FILE_SEEKCALLBACK;
metadata: FMOD_CODEC_METADATACALLBACK;
end;
FMOD_CODEC_METADATACALLBACK = function (codec_state: FMOD_CODEC_STATE; tagtype: FMOD_TAGTYPE; name: PChar; data: Pointer; datalen: Cardinal; datatype: FMOD_TAGDATATYPE; unique: Integer):FMOD_RESULT;
I'm translating the great fmod C header to Pascal, and I'm stuck because of a forward declaration.
If I declare the function before the type, the error is "FMOD_CODEC_STATE: unknown", and if I declare the FMOD_CODEC_STATE before the function, the error is "FMOD_CODEC_METADATACALLBACK: unknown"
Any idea how I could solve this problem?
Thank you very much !
type
FMOD_CODEC_STATE = Record
numsubsounds: Integer;
waveformat: array[0..0] of FMOD_CODEC_WAVEFORMAT;
plugindata: Pointer;
filehandle: Pointer;
filesize: Cardinal;
fileread: FMOD_FILE_READCALLBACK;
fileseek: FMOD_FILE_SEEKCALLBACK;
metadata: FMOD_CODEC_METADATACALLBACK;
end;
FMOD_CODEC_METADATACALLBACK = function (codec_state: FMOD_CODEC_STATE; tagtype: FMOD_TAGTYPE; name: PChar; data: Pointer; datalen: Cardinal; datatype: FMOD_TAGDATATYPE; unique: Integer):FMOD_RESULT;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
记录不需要按值传递。事实上,原始的 C 代码无论如何都不会按值传递它。它是通过引用传递的,带有指针。声明指针,然后声明函数,然后声明记录:
是的,您可以在声明它指向的对象之前声明指向某个对象的指针。但是,您不允许前向声明记录,因此上面给出的顺序是这三个声明的唯一可能的顺序。
The record doesn't need to be passed by value. In fact, the original C code doesn't pass it by value anyway. It's passed by reference, with a pointer. Declare the pointer, then the function, and then the record:
Yes, you're allowed to declare a pointer to something before you've declared the thing it points to. You're not allowed to forward-declare records, though, so the order given above is the only possible order for those three declarations.
Pascal 对指针类有自动前向类型声明,这就是我假设函数实际采用的类型声明。因此,只需将您的声明更改为类似以下内容(警告,我已经超过 12 年没有使用过 pascal)应该可以工作:
Pascal has automatic forward type declaration for pointer classes, which is what I'm assuming that function actually takes. So simply changing your declarations to something like this (warning, I haven't used pascal in over 12 years) should work: