Pascal对象:如何做类型化的前向声明? [英] Pascal Object: how to do a typed forward declaration?
问题描述
我正在将出色的fmod C标头转换为Pascal,并且由于前向声明而陷入困境。
如果我在类型之前声明函数 ,则错误为 FMOD_CODEC_STATE:未知,如果我在函数之前声明FMOD_CODEC_STATE ,则错误为 FMOD_CODEC_METADATACALLBACK:未知
知道如何解决此问题吗?
非常感谢!
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;
推荐答案
记录不需要按值传递。实际上,原始的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:
type
PFMOD_CODEC_STATE = ^FMOD_CODEC_STATE;
FMOD_CODEC_METADATACALLBACK = function (codec_state: PFMOD_CODEC_STATE; tagtype: FMOD_TAGTYPE; name: PChar; data: Pointer; datalen: Cardinal; datatype: FMOD_TAGDATATYPE; unique: Integer):FMOD_RESULT;
FMOD_CODEC_STATE = Record
numsubsounds: Integer;
waveformat: PFMOD_CODEC_WAVEFORMAT;
plugindata: Pointer;
filehandle: Pointer;
filesize: Cardinal;
fileread: FMOD_FILE_READCALLBACK;
fileseek: FMOD_FILE_SEEKCALLBACK;
metadata: FMOD_CODEC_METADATACALLBACK;
end;
是的,您可以在声明某物之前声明一个指向某物的指针至。不过,您不允许转发声明记录,因此,上面给出的顺序是这三个声明的唯一可能的顺序。
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对象:如何做类型化的前向声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!