Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Problem including units

Victor MVS
2012-03-13
2013-04-25
  • Victor MVS
    Victor MVS
    2012-03-13

    Hi!

    I'm working with units and I can't reference a unit inside another:

    unit A;
    interface
    type typeA = record
    end;
    ...
    

    I want to use this unit here:

    unit B;
    uses A; // n.1
    interface
    uses A; // n.2
    procedure sampleB(myVar : typeA);
    ...
    

    Both "uses" clauses produce a compiler error. Is there any possibility doing that?
    I can compile this code using pascal compiler like FreePascal.
    If it's not possible, then I have to write this code inside one big unit :(

    Thanks for the help in advance.

     
  • Hi,

    Sure, be sure to name your units with at least 3 characters, let's say AAA and BBB.

    unit AAA;
    interface
    type recA=record
    end;
    implementation
    end.
    

    and

    unit BBB;
    interface
    implementation
    uses AAA;
    var aaaaa: AAA.recA;
    end.
    

    compiles fine here.

    Thanks for post.

     
  • Victor MVS
    Victor MVS
    2012-03-14

    The problem exists when unit BBB is like:

    unit BBB;
    interface
    uses AAA; // line n.1
    procedure sampleBBB(myvar : recA); // line n.2
    implementation
    procedure sampleBBB(myvar : recA);
    begin
    end;
    end.
    

    This way I can't compile. It shows me an error like: " test.mpsrc(n.1): E204 unexpected token 'uses'
    "

    I think that I need line n.1 due to param definition of sampleBBB procedure. But if I comment line n.1, it compiles OK.

    The problem rises again when I write on unit BBB this:

    unit BBB;
    interface
    function sampleBBB(myInt : integer) : recA; // line n.3
    function sampleBBB2(myInt) : array[1..10] of recA; // line n.4
    implementation
    uses AAA;
    function sampleBBB(myInt : integer) : recA;
    begin
    end;
    function sampleBBB2(myInt : integer) : array[1..10] of recA;
    begin
    end;
    end.
    

    In this case, the compiler returns: " test.mpsrc(n.3): E406 unknown type 'recA' "

    For line n.4, the compiler error is: " test.mpsrc(n.4): E406 unknown type 'array'
    "
    I know I can solve this using:

    // The old returned value is retVar now. Passing it by reference
    // due to being a record
    function sampleBBB(myInt : integer; retVar : recA) : integer;
    function sampleBBB2(myInt : integer; retVar : array[1..10] of recA) : integer; // line n.5
    

    Line n.3 is solved but line n.5 instead of line n.4 doesn't work. Compiler error shows: " test.mpsrc(n.5): E202 identifier (name) expected
    "
    I don't know how to solve this problem with arrays.

    Thanks for your answer and waiting your helping hand :)

     
  • Hi,

    MIDletPascal, and it's pascal dialect, has it's idiosyncrasies and some limitations too. It seems you are facing them, but the bad new is that there is not enough people using MP nowadays to assist you.

    Anyway, here is my help this time. The workaround to the issue you couldn't solve is to define a new type:

    type
      someName = array of recA;

    and use that new type in your parameter:

      function sampleBBB2(myInt : integer; retVar : someName) : integer;

    Btw, and despite the lower amount of developers using MP actively (J2ME as a platform is mostly dead now), I will try to reach the final release of the 3.5 version. It will be really hard, but I will try it.

    Thanks and good luck with your MP projects.

     
  • Victor MVS
    Victor MVS
    2012-03-15

    Thanks for this solution. I'm going to try more small projects with MidletPascal.
    I hope this project can walk for some years :)

    Thank you for your job developing this project.