On 29 mei 2006, at 14:46, Thomas Miller wrote:

I am frustrated by a very simple problem. I am trying to convert real to integer, using free pascal for mac. I am an old Think Pascal user who just recently found free pascal and, while thrilled to have a pascal compiler for mac OSX, I am still a bit lost. In Think Pascal, I would have just used "round", but this doesn't seem to work.

x : integer;
y : real;

x := round(y);

gives me an error saying "got "Double" expected "SmallInt"". This occurs no matter how I define x: integer, smallint, etc. In fact, if I set x to real, then the program compiles and works, simply converting decimal values to 0 but not deleting them.

I suspect I am making some simple error.  Any advice?

The problem is that Apple's universal interfaces also include a "round" function, which returns a real instead of an integral type. There are two solutions:

a) use "system.round(y)" so the compiler uses the round function from the system unit instead of from your carbon unit b) switch to a new version of the Universal Interfaces translations (where that "round" function has been renamed "roundd"), available from http://www.elis.ugent.be/~jmaebe/nobackup/fpc/ FPCPInterfaces060428.zip

Note that in case b), instead of the Carbon unit, you have to use the "fpcmacosall" unit instead. It also fixes several bugs in the UI translations, so it's a good idea to upgrade them in either case.


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to