[Gambas-user] Probable bug with "_unknown" method when used for properties
Benoît Minisini
gambas at ...1...
Thu Jun 30 12:04:05 CEST 2011
> Benoit,
>
> Here is more detail on the problem... What I'm attempting to do is
> read/write CISAM files from Gambas3. I am using the external VBISAM
> library "libvbisam.so". I have a VBISAM class and a driver program. Here
> is the VBISAM Class:
>
> ---------------------------------------------Begin
> VBISAM-------------------------------------
> Class VBISAM
>
> Const ISFIRST As Integer = 0
> Const ISLAST As Integer = 1
> Const ISNEXT As Integer = 2
> Const ISPREV As Integer = 3
> Const ISCURR As Integer = 4
> Const ISEQUAL As Integer = 5
> Const ISGREAT As Integer = 6
> Const ISGTEQ As Integer = 7
>
> Const ISLOCK As Integer = &H100&
> Const ISSKIPLOCK As Integer = &H200&
> Const ISWAIT As Integer = &H400&
> Const ISLCKW As Integer = &H500&
> Const ISKEEPLOCK As Integer = &H800&
>
> Const ISAUTOLOCK As Integer = &H200&
> Const ISMANULOCK As Integer = &H400&
> Const ISEXCLLOCK As Integer = &H800&
>
> Const ISINPUT As Integer = 0
> Const ISOUTPUT As Integer = 1
> Const ISINOUT As Integer = 2
> Const ISTRANS As Integer = 4
> Const ISNOLOG As Integer = 8
>
> Const ISVARLEN As Integer = &H10&
> Const ISFIXLEN As Integer = 0
>
> Extern isopen(FNAME As String, MODE As Integer) As Integer In "libvbisam"
> Extern isread(FD As Integer, BUFF As Pointer, MODE As Integer) As Integer
> In "libvbisam"
> Extern isclose(FD As Integer) As Integer In "libvbisam"
>
> Public RecLen As Integer = 768
> Private FD As Integer
> Public ReturnCode As Integer
> Private BUFF As Pointer = Alloc(RecLen)
> Public DataRecord As String
> Private Dictionary As Collection
>
> Private Sub ReadDict(FName As String)
> Dim items As New String[30]
> Dim DictIn As File
> Dim TextLine As String
> Dim i As String
> Dim x As Integer
> Dim Dict As DictEntry
>
> DictIn = Open FNAME & ".dic" For Read
> ' Loop through each line until the end of file.
> ' Eof() returns true at the end of the file.
>
> Dictionary = New Collection
>
> While Not Eof(DictIn)
> Line Input #DictIn, TextLine
> ' Split each line into fields
> ' Note that we set the " char as an escape char
>
> items = Split(TextLine, ",", "\"")
>
> Dict = New DictEntry
> items[3] = Replace$(items[3], "-", "_")
> Dict.DataName = items[3]
> Dict.Pos = items[4] + 1
> Dict.Len = items[5]
> Dict.Type = items[6]
> Dict.Occurs = items[8]
> Dict.Edit = items[12]
> Dict.SerialNo = items[19]
> Dictionary[items[3]] = Dict
>
> Wend
> Close #DictIn
> End
>
> Public Sub _new(FNAME As String, Optional MODE As Integer = ISINPUT +
> ISMANULOCK)
> FD = isopen(FNAME, MODE)
> ReadDict(FNAME)
> End
>
> Public Sub close()
> Dim ReturnCode As Integer
> ReturnCode = isclose(FD)
> Free(BUFF)
> End
>
> Public Sub first() As Integer
> Dim ch As Byte
> Dim tmp As Pointer = BUFF
> Dim I As Integer
> Dim BuffStream As Stream
> ReturnCode = isread(FD, BUFF, 0)
> If ReturnCode < 0 Then
> Return ReturnCode
> Endif
> BuffStream = Memory BUFF For Write
> DataRecord = Read #BuffStream As String
> Return ReturnCode
> End
>
> Public Sub _next()
> Dim ch As Byte
> Dim tmp As Pointer = BUFF
> Dim I As Integer
> Dim BuffStream As Stream
> BuffStream = Memory BUFF For Write
> ReturnCode = isread(FD, BUFF, ISNEXT)
> If ReturnCode < 0 Then Enum.Stop
> DataRecord = Read #BuffStream As String
> Return
> End
>
> Public Function _unknown(...) As Variant
> Dim Params As Integer = Param.Count
> Dim D As DictEntry = Dictionary[Upper$(Param.Name)]
> Dim Value As Variant
> If Param.Property
> If Params = 0 Then
> Return Mid$(DataRecord, D.Pos, D.Len)
> Else
> Value = Param[0]
> Mid$(DataRecord, D.Pos, D.Len) = Value
> Endif
> Endif
> End
>
> -----------------------------------------------End
> VBISAM-------------------------------------
>
> And here is the driver:
> ----------------------------------------------Begin
> MMain---------------------------------------
> ' Gambas module file
>
> Public Sub Main()
> Dim CUSTOMER As VBISAM
> Dim RESULT As Integer
> Dim CustCount As Integer = 0
> Dim Branch As String
> CUSTOMER = New VBISAM("/data/CUSTFILE")
> RESULT = CUSTOMER.first()
> For Each CUSTOMER
> Branch = CUSTOMER.Branch
> If CUSTOMER.Branch = "000" Then Goto ReadNext
> Print CUSTOMER.Key, CUSTOMER.Name, CUSTOMER.City, CUSTOMER.State,
> CUSTOMER.Zip_Code
> CustCount += 1
> ReadNext:
> Next
> CUSTOMER.close()
> Print "Total Customers: " & CustCount
> End
> -------------------------------------------End
> MMain----------------------------------------
>
> The error message I get in line 12 of MMain is:
> Type mismatch: Wanted Number, Date, or String, got Function instead in
> MMain:12.
>
>
> Without the "If CUSTOMER" statement, everything is fine (i.e., I can use a
> property as as string when I print or do other opeations). However, the
> "IF" statrement (line 12) doesn't like the unknown property at all! I set
> a breakpoint in the _unknown method of VBISAM and it gets there when using
> the unknown properties in print statements (or other expressions), but
> does not when using it in a conditional.
>
> Hope that helps,
>
> gwalborn
Can you provide a project with the previous code so that I can debug?
--
Benoît Minisini
More information about the User
mailing list