iOS Question Compiler does not like this

Robert Valentino

Well-Known Member
Licensed User
Longtime User
This Code
B4X:
    Type TPDFPrint_PageSize(Width As Float, Height As Float)
    Type TPDFPrint_PageMargins(Left As Float, Top As Float, Right As Float, Bottom As Float, TopOfPage As Float, EndOfPage As Float)

    Private    mPageSize                                        As TPDFPrint_PageSize
    Private    mMargins                                        As TPDFPrint_PageMargins


#Region PDFDrawRectangle
Public  Sub PDFDrawRectangle(RectToDraw As Rect, Color As Int, Filled As Boolean, Stroke As Int, FillColor As Int) As Rect
            Dim RealDraw        As Rect
           
            RealDraw.Initialize(RectToDraw.Left, RectToDraw.Top, RectToDraw.Right, RectToDraw.Bottom)

            If  RealDraw.Right = -1 Then
                RealDraw.Right = (mPageSize.Width - (mMargins.Right + RealDraw.Left))
            End If           
           
            If  RealDraw.Bottom = -1 Then
                RealDraw.Height = (mPageSize.Height - (mMargins.Bottom + RealDraw.Top))      ' this is line 592                        
            End If
           
            RealDraw.Left    = RealDraw.Left + mMargins.Left
            RealDraw.Top    = RealDraw.Top    + mMargins.Top
                       
            mPDF.DrawRect(RealDraw, Color, False, Stroke)
           
            If  Filled Then
                mPDF.DrawRect(RealDraw, FillColor, True, Stroke)
            End If
           
            Return RealDraw
End Sub
#end Region

Compiling debugger engine code. Error
B4i line: 592
RealDraw.Height = (mPageSize.Height - (mMargin
shell\src\com\BOBs\BBs\b4i_creports_subs_0.java:1379: error: unexpected type
_realdraw.runMethod(true,"Height") = BA.numberCast(float.class, (RemoteObject.solve(new RemoteObject[] {__ref.getField(false,"_mpagesize" /*RemoteObject*/ ).getField(true,"Height" /*RemoteObject*/ ),(RemoteObject.solve(new RemoteObject[] {__ref.getField(false,"_mmargins" /*RemoteObject*/ ).getField(true,"Bottom" /*RemoteObject*/ ),_realdraw.runMethod(true,"Top")}, "+",1, 0))}, "-",1, 0)));Debug.locals.put("RealDraw", _realdraw); ^
required: variable
found: value
1 error

The code looks fine and works GR8 under B4A


Also did not like this until I moved the string to a int
B4X:
                Dim SortedMatchup         As String  = SortedMatchups.Get(SortedMatchupsLoop)
                Dim SortedParsed()        As String  = Regex.Split("~", SortedMatchup)
                
                If  SortedParsed.Length <> 3 Or IsNumber(SortedParsed(2)) = False Then 
                    Continue
                End If
                 
#if B4A                 
                MatchupsLoop = SortedParsed(2)
#else if B4i
                Dim x As Int = SortedParsed(2)
                
                MatchupsLoop = x
#end if
Compiling debugger engine code. Error
B4i line: 1416
MatchupsLoop = SortedParsed(2)
shell\src\com\BOBs\BBs\b4i_cstandings_subs_0.java:602: error: > expected
_matchupsloop = BA.ObjectToNumber(_sortedparsed.runMethod(true,"getObjectFast:", BA.numberCast(int.class, 2)).<NSString*>get()).intValue;Debug.locals.put("MatchupsLoop", _matchupsloop); ^
1 error
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Couldn't recreate in smaller or test project so shipped code off to Erel.

Hopefully he can figure out what Bozo mistake I did that is causing this.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK, I wrote this TEST code to help figured out one of the compiler problems

This code
B4X:
            Dim Matchups        As List

            Dim SortedMatchups As List
           
            Matchups.Initialize
            SortedMatchups.Initialize

            For MatchupsLoop = 0 To Matchups.Size-1
                Log("Nothing - Just a test")
            Next
                       
  
            For SortedMatchupsLoop = 0 To SortedMatchups.Size-1
                Dim SortedMatchup         As String  = SortedMatchups.Get(SortedMatchupsLoop)
                Dim SortedParsed()        As String  = Regex.Split("~", SortedMatchup)
               
                If  SortedParsed.Length <> 3 Or IsNumber(SortedParsed(2)) = False Then
                    Continue
                End If
                
                MatchupsLoop = SortedParsed(2)                '    FixMe Compiler  Line would not compile in B4i
            Next

Get this error
B4i line: 131
MatchupsLoop = SortedParsed(2) ' FixMe Comp
shell\src\com\BOBs\Testing\b4i_b4xmainpage_subs_0.java:135: error: > expected
_matchupsloop = BA.ObjectToNumber(_sortedparsed.runMethod(true,"getObjectFast:", BA.numberCast(int.class, 2)).<NSString*>get()).intValue;Debug.locals.put("MatchupsLoop", _matchupsloop);

The REASON I found that this code is not working is because MatchupsLoop was defined within the for loop and I assume has gone out of scope. If I were to add a
B4X:
DIM MatchupsLoop as Int
before the for loop then I can use the MatchupsLoop inside the other SortedMatchupsLoop

AGAIN: The code above is just s snip-it of the code but allowed me to see the problem but can compiled as is to inside a a test program to cause the effect. Caught me doing something bad (that works perfectly find under B4A)

This compiles just fine
B4X:
            Dim Matchups        As List

            Dim SortedMatchups As List
           
            Dim MatchupsLoop  as Int

            Matchups.Initialize
            SortedMatchups.Initialize

            For MatchupsLoop = 0 To Matchups.Size-1
                Log("Nothing - Just a test")
            Next
                       
  
            For SortedMatchupsLoop = 0 To SortedMatchups.Size-1
                Dim SortedMatchup         As String  = SortedMatchups.Get(SortedMatchupsLoop)
                Dim SortedParsed()        As String  = Regex.Split("~", SortedMatchup)
               
                If  SortedParsed.Length <> 3 Or IsNumber(SortedParsed(2)) = False Then
                    Continue
                End If
                
                MatchupsLoop = SortedParsed(2)                '    FixMe Compiler  Line would not compile in B4i
            Next
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Attached is a small program that does nothing but causes the 2nd compiler error I was having

B4i line: 83
RealDraw.Height = (mPageSize.Height - (mMargin
shell\src\com\BOBs\Testing\b4i_b4xmainpage_subs_0.java:140: error: unexpected type
_realdraw.runMethod(true,"Height") = BA.numberCast(float.class, (RemoteObject.solve(new RemoteObject[] {__ref.getField(false,"_mpagesize" /*RemoteObject*/ ).getField(true,"Height" /*RemoteObject*/ ),(RemoteObject.solve(new RemoteObject[] {__ref.getField(false,"_mmargins" /*RemoteObject*/ ).getField(true,"Bottom" /*RemoteObject*/ ),_realdraw.runMethod(true,"Top")}, "+",1, 0))}, "-",1, 0)));Debug.locals.put("RealDraw", _realdraw);
^
required: variable
found: value
1 error
 

Attachments

  • Project.zip
    181.9 KB · Views: 13
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The error in the last example happens because Rect.Height is a method. It is not a property or a field. You cannot assign a value to a method.

1651992392544.png
 
Upvote 0
Top