Cannot Convert Type Compile Error

Saj

Active Member
Licensed User
The following lines of code executes when running on the desktop, however it gives the attached error message when attempting to complile.

B4X:
xtablename=tileFileNamePrefix&"_z"&MapNativeZoom*10000
bmpTile.Create3   (SQL.getTilefromDB(xtablename, SQLtilefile))

Is it not proper to do an SQL call as part of creating a new bmp? The SQL.getTilefromDB returns a bitmap.
 

Attachments

  • Cannot Convert Error.jpg
    Cannot Convert Error.jpg
    22.1 KB · Views: 204

mjcoon

Well-Known Member
Licensed User
You cannot return a bitmap from a method in Basic4ppc. You will need to use a global variable.

But a library method may return an image, as in
B4X:
frmJPGsearch.DrawImage(DBreader.GetImage(0), Label1.Left, Label1.Top, _
      Label1.Left + Label1.Width, Label1.Top + Label1.Height)

(which I wrote in answering a question about showing BLOBs a few days ago).

So maybe Erel is referring to a module method? I am guessing that Saj's "SQL" object is some SQLite item (though I don't know of a getTilefromDB method) but without lots more information, or the whole code, we are left wondering...

Mike.
 

Saj

Active Member
Licensed User
I am guessing that Saj's "SQL" object is some SQLite item (though I don't know of a getTilefromDB method) but without lots more information, or the whole code, we are left wondering...

Here's the getTilefromDB Sub:
B4X:
Public Sub getTilefromDB(tablename, tilename)
   If tilesDBfound Then
      s = "SELECT JPG FROM " & tablename & " WHERE tilename='" & tilename & "'"      
      tilesDBcommand.CommandText = s
      tilesDBreader.Value = tilesDBcommand.ExecuteReader   'Fill reader
      
      If tilesDBreader.IsDBNull(0) Then
         Msgbox ("tileDB is NULL, i.e. no results returned")
      Else
         If tilesDBreader.ReadNextRow = False Then
            Msgbox("ERROR08: No results returned from DB table: "& tablename & ". Missing tile.","Error",cMsgboxOK,cMsgboxAsterisk)
         Else
            Return tilesDBreader.GetImage(0)   'return tile
         End If         
      End If      
      tilesDBreader.Close 'Close reader
   End If      
End Sub
 

Saj

Active Member
Licensed User
You cannot return a bitmap from a method in Basic4ppc. You will need to use a global variable.

What is the syntax for a global image variable? I've resorted to doing the following which complies ok:

B4X:
main.bmpTile.Create3(tilesDBreader.GetImage(0))
 

agraham

Expert
Licensed User
Longtime User
Any Image control is effectively a global variable, as is main.bmpTile in your code fragment.

For explanation, what you are doing works fine because you are passing a bitmap returned from a library method to another library method. This works because the bitmap is not "entering" Basic4ppc code. Library methods can pass and return whatever they need to. Basic4ppc Subs are limited to passing and receiving primitive types and strings.
 
Top