[fpc-pascal] Two questions about Pascal

José Mejuto joshyfun at gmail.com
Fri Jul 30 00:12:29 CEST 2010


Hello FPC-Pascal,

Thursday, July 29, 2010, 8:54:44 PM, you wrote:


>> 1) Is there any way in Pascal to write something like this
>> (pseudocode):
>> 
>> With Result:=Object.Create() do begin
>>  Free;
>> end;
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
    TNX_a.OP1:=TNXX_b.OP2;
    TNXX_b.OP3:=TNX_a.OP2;
    [.....]
  end;
end;

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.

-- 
Best regards,
 José




More information about the fpc-pascal mailing list