I am trying to create a function with an option type parameter that allows inline casting or assignment, as such:
type rectype = ( VT_INT, VT_CHAR, VT_BOOL );
rec = record
case t : rectype of
VT_INT : ( i : integer );
VT_CHAR : ( c : char );
VT_BOOL : ( b : boolean );
end;
procedure handler( r : rec );
begin
case r.t of
VT_INT : { do something with r.i }
VT_CHAR : { do something with r.c }
VT_BOOL : { do something with r.b }
end;
end;
Now the above “works” fine if you take the time to manually configure the variable:
r.t := VT_INT;
r.i := 42;
handler( r );
But I would like to abuse the input system a bit and try to do it inline (I will explain why in an instant), according to:
handler( rec( VT_INT, 42 ) );
A helper function will also be useful, and I tried several different ways to do this, which can be seen here (for the sake of brevity of this post):
http://pastie.org/private/glxhwbpsbbh5gtxju0uvxa
, : , , Pascal ( FreePascal Turbo Pascal 7 (, )). ( , rep), : isI(), isR(), isS(), isP(), isC() .. , , . , , FPC Delphi, IFDEF , TP7, .
, 4 , , , API-, , , , , . API , , :
is( VT_INT, SomeIntFunc( v ), 42, 'Test Name' );
, TP7, .. , , , .
, Pascal ( , - ), ?