Need Help ! Compile error

edsphu

Member
Licensed User
Trying to learn Basic4PPC, i used BouncingSmiley program as a template to explore the ADDOBJECT function. I added logic to add more smileys when it hit the edges. I randomly obtain the new speed and size of the smiley. Everything works well on desktop. When I tried to COMPILE DEVICE EXE, I got compile error:

Error compiling program
Error message: Unknown control type. Use Control(Name, Type) instead.
Line number: 39
Line:Control(strB).New1 (appPath & imageFile)

Here the subroutine:

Sub DrawSmileyImage
strB = "objBitmap" & iIndex
strEB = "objEraseBrush" & iIndex
strRS = "objRectSource" & iIndex
strRD = "objRectDest" & iIndex
strD = "objDrawer" & iIndex

speed(iIndex).X = Rnd(1, 5) : Speed(iIndex).Y = speed(iIndex).X
smileySize = Rnd(10,30)

AddObject (strB, "Bitmap")
'Control(strB).New1 (AppPath & "\smiley.gif")
'Control(strB).New1 (AppPath & imagelist1.Item(0))

GetImageFile
Control(strB).New1 (AppPath & imageFile)


transparentColor = Control(strB).GetPixel1(0,0)
SetTransparentColor(transparentColor)
Form1.ForeLayer = True


AddObject (strEB, "Brush")
Control(strEB).New1(transparentColor)

AddObject (strD, "Drawer")
Control(strD).New1("Form1", True)

AddObject (strRS, "Rectangle")
Control(strRS).New1(0,0,Control(strB).Width, Control(strB).Height)

AddObject (strRD, "Rectangle")
T = Rnd(10,120) : L = T
Control(strRD).New1(T, L, smileySize, smileySize)

Control(strD).DrawImage1(Control(strB).Value, Control(strRS).Value, _
Control(strRD).Value, True)

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The optimized compiler requires the object's type during compilation.
This error means that you need to add the types:
B4X:
GetImageFile
   Control(strB, Bitmap).New1 (AppPath & imageFile)

   
   transparentColor = Control(strB, Bitmap).GetPixel1(0,0)
   SetTransparentColor(transparentColor)
   Form1.ForeLayer = True
   
   
   AddObject (strEB, "Brush")
   Control(strEB, Brush).New1(transparentColor)
   
   AddObject (strD, "Drawer")
   Control(strD, Drawer).New1("Form1", True)
   
   AddObject (strRS, "Rectangle")
   Control(strRS, Rectangle).New1(0,0,Control(strB, Bitmap).Width, Control(strB, Bitmap).Height)
   
   AddObject (strRD, "Rectangle")
   T = Rnd(10,120) : L = T
   Control(strRD, Rectangle).New1(T, L, smileySize, smileySize)
   
   Control(strD, Drawer).DrawImage1(Control(strB, Bitmap).Value, Control(strRS, Rectangle).Value,   _ 
         Control(strRD, Rectangle).Value, True)
 

edsphu

Member
Licensed User
Thanks Erel for quick reply but I need more info for a newbie to Basic4ppc. How do I do that? Can you put an example base on my code? I ran from desktop and it works OK only problem when compiling to device EXE.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, instead of this code:
B4X:
Sub GetImageFIle
    imageNumber = Rnd(1,10)
    Select imageNumber 
        Case 1
            imageFile = "\smile001.bmp"
        Case 2
            imageFile = "\smile002.bmp"
        Case 3
            imageFile = "\smile003.bmp"
        Case 4
            imageFile = "\smile004.bmp"
        Case 5
            imageFile = "\smile005.bmp"
        Case 6
            imageFile = "\smile006.bmp"
        Case 7
            imageFile = "\smile007.bmp"
        Case 8
            imageFile = "\smile008.bmp"
        Case 9
            imageFile = "\smile009.bmp"
        Case 10
            imageFile = "\smile010.bmp"
            
    End Select        
End Sub
You can use:
B4X:
imageFile = "\smile" & Format(rnd(1,11),"d3") & ".bmp"
Note that the max number in Rnd is exclusive. So it should be 11 instead of 10.
 

edsphu

Member
Licensed User
Erel,
Many thanks. I expected that I can learn some from you guys. That is a good coding technique.
Btw, I unchecked the optimized compile and was able to compile DEVICE EXE without errors the using SetupBuilder and ezsetup to upload to my Dell Axim pocket pc.

I remembered I read somewhere that using Optimized Compile it may ask for TYPE....

Thanks again! Hope I did not take too much of your time....
 
Top