• Prevent Variants unit from being implicitly included?

    From JJ@21:1/5 to All on Mon Nov 7 03:51:47 2016
    I have this simple code.

    program test;
    type abc = variant;
    begin
    end.

    If I compile it, the compiler includes the Variants unit, even though the variant type is declared in the System unit.

    The above code doesn't even refer the variant type as a variable, so there
    no need for variant variable initialization. There should be no variant
    related code to be included in the program at all.

    So how to prevent the Variant unit to be included into the program by the compiler? Is there a compiler directive for this? Or a command line
    parameter for DCC32?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Below@21:1/5 to All on Mon Nov 7 17:45:20 2016
    JJ wrote:

    I have this simple code.

    program test;
    type abc = variant;
    begin
    end.

    If I compile it, the compiler includes the Variants unit, even though
    the variant type is declared in the System unit.

    The compiler does nothing of this sort, it is the IDE when you save the
    program file (which it does automatically when you ask it to compile
    the code).


    The above code doesn't even refer the variant type as a variable, so
    there no need for variant variable initialization. There should be no
    variant related code to be included in the program at all.


    So what? In any real code that actually *uses* your abc type you will
    need variant support routines. Your example is completely artifical.

    You could try to use OleVariant instead of Variant, if you already have
    Windows in the Uses clause anyway.

    --
    Peter Below
    TeamB

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to Peter Below on Tue Nov 8 17:18:25 2016
    On Mon, 7 Nov 2016 17:45:20 +0000 (UTC), Peter Below wrote:
    JJ wrote:

    I have this simple code.

    program test;
    type abc = variant;
    begin
    end.

    If I compile it, the compiler includes the Variants unit, even though
    the variant type is declared in the System unit.

    The compiler does nothing of this sort, it is the IDE when you save the program file (which it does automatically when you ask it to compile
    the code).

    Yes it does. I actially tested this using DCC32 command line compiler.

    The above code doesn't even refer the variant type as a variable, so
    there no need for variant variable initialization. There should be no
    variant related code to be included in the program at all.

    So what? In any real code that actually *uses* your abc type you will
    need variant support routines. Your example is completely artifical.

    You could try to use OleVariant instead of Variant, if you already have Windows in the Uses clause anyway.

    I need to implement my own custom variant routines without including the Variants unit - for smaller executable file. Variant values won't be
    accessed as is. They will be type casted to TVarData and will always be accessed as TVarData from within the custom variant routines. Only those routines' function declarations need to have "variant" for a type. e.g.

    procedure XVariantSet(var v: variant; b: boolean); overload;
    begin
    TVarData(v).VType:= varBoolean;
    TVarData(v).VBoolean:= b;
    end;

    procedure XVariantSet(var v: variant; i: integer); overload;
    begin
    TVarData(v).VType:= varInteger;
    TVarData(v).VInteger:= i;
    end;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)