Functions inside types

In this category you can exchange your programming questions and solutions.
Post Reply
Bob Hays
Posts: 26
Joined: Sun Oct 03, 2010 4:49 pm

Functions inside types

Post: # 1183Post Bob Hays
Wed May 21, 2014 5:50 pm

I am attempting to port an sqlite3 wrapper from Rapidq.
There are functions inside the type definition.

When I attempt to assign the return value to "Result" the compiler complains with "RESULT" not declared/unknown.

What is the proper way to return the results from a function inside a type definition or can i?
:-?

CODE:
Type SQLite3 As Panel
     Databasepath As String
     Commandtext As String
     Handle As Long
     StringSep As String
     `onerror as event
     SqLiteOK As Long

     Function LibraryVersion() As String
           Dim bchar As Byte, iCounter As Byte
           Dim ptr_version As Long
           Dim str_version As String
           
           str_version=""
           
           ptr_version = sqlite3_libversion()
           icounter=0

           Do
                 Memcopy(Varptr(bchar),ptr_version+icounter,1)
                 If bchar=0 Then Exit Do
                 str_version=str_version+Chr$(bchar)
                 Inc(icounter)
           Loop
           result = str_version
     End Function

     Function sq3_errorCode(errNumber As Long) As String
           Dim errstr As String
           Select Case errNumber
                 Case 1
                       errstr = "SQL syntax error or access to basic non-valid data: " + Chr$(13) + SQLite3.commandText
                 Case Else
                       errstr = "An error occured. SQL Error numver : "+Str$(errNumber)      
           End Select
           `result = errstr
     End Function
End Type

END CODE

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

Functions inside types

Post: # 1184Post PaPi
Fri Jun 13, 2014 7:21 pm

Hi, this error occurred for me too. Bat It would be good to know the reason...
PaPi

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Functions inside types

Post: # 1185Post Marco
Sat Jun 14, 2014 8:56 pm

For what it is worth, I think functions are not fully implanted in types.
but it can be used in this way, maybe you can something whit it.

``example code
type mytype as button
  caption="click for color"
  onclick=getc
  function getcolor as integer
    getcolor.result=rgb(255,0,0)
  end function
  sub getc
    getcolor
    caption=str$(getcolor.result)
  end sub
end type

object myform as form
  center
 
end object

dim mybutton as mytype
mybutton.parent=myform


myform.showmodal

Post Reply