[fpc-pascal] Two questions about Pascal
joshyfun at gmail.com
Fri Jul 30 00:12:29 CEST 2010
Thursday, July 29, 2010, 8:54:44 PM, you wrote:
>> 1) Is there any way in Pascal to write something like this
>> With Result:=Object.Create() do begin
JM> Just leave out the "Result:=" part and it will compile/work fine..
I was looking for a "with" like:
with TNX(a) "named" as TNX_a do begin
with TNXX(b) "named" as TNXX_b do begin
But I think that there is nothing like that in Pascal. Once piece of
code uses a heavy polimorfism (in fact I think too heavy) and in some
pieces of code I must perform a lot of type castings or assign a
variable of the desired type wich incurres in some unneeded
asignements. I had solved many of them using the "absolute" keyword,
but others would be solved with a "variable scoped retype", but once
the variable needs to be assigned to a result, in example, another
bunch of type casts appears :(
>> 2) Which is the expected way to detect if a float value is exact ?
>> Maybe only applying "if V = trunc(V) then ..." ?
JM> Use "if V = int(V) then ..." instead. trunc() converts to an
JM> int64 (which will then again be converted to a float), while int()
JM> returns a floating point type (with the fractional part removed).
Fine! Thank you.
More information about the fpc-pascal