Ken G. Brown wrote:
Thx a lot for your long explanation of Strings.
Here is another one that has me baffled.
My code in a procedure:
procedure doHeader (pageNum, numPages : Integer);
var pageNumStr, numPagesStr : Str255;
the call: NumToString(pageNum,pageNumStr);
I get compile error: error: type mismatch in argument 2 of `NumToString'
In NumberFormatting.p procedure NumToString(theNum: SInt32; var theString: Str255); external name '_NumToString';
What do I need to do in this case?
First, when you ask for help you should post a complete example.
Secondly, the following "works" for me:
program foo; type Str255 = string(255); SInt32 = integer; var pageNum : SInt32; pageNumStr, numPagesStr : Str255; procedure NumToString(theNum: SInt32; var theString: Str255); external name '_NumToString';
begin NumToString(pageNum,pageNumStr); end .
"Works" here means that the linker complains about undefined function _NumToString (which is expected since I did not provide that function). I use a newer gpc version which fixed some parameter passing problems, but I doubt that gpc version matters for your problem
Third, if you want to call Pascal functions defined in different files, then read about units and modules in gpc documentation (external is for interfacing with other languages). OTOH if you want to call foreign function then you need correct definition of Str255 (Pascal string is probably wrong).