A question from the old Pascal school about how to correctly execute the parameters of the option write function

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 ( , - ), ?

+3
1

Free Pascal , Delphi, () , const ( , ). Delphi FPC , , , .

, , . ( : ) .

, ,

 procedure rec(vartype:Ttypeofvar;var value):tvariantrecord;
 begin
   rec.t:=vartype
   case vartype of 
      vt_int: move (value,@rec.i,sizeof(integer));
      ..
      ..
 end;

, typeafe, rec (varint, "something double" ). TP , VAR.

, TP7. 16 . .

+1

Source: https://habr.com/ru/post/1764042/


All Articles