Hi Bram,
I am using DF19.1 with a Pervasive database.
I have moved on since that original post and, as well as fixing the problem with numeric fields I have also added support for multi-column display which was allowed in the tSuggestion struct but not implemented. This required adding a new WebProperty to the Class.
Here is the code in the new sub-class:
Code:
Procedure SuggestionsFindIncremental String sSearch tSuggestion[] ByRef aSuggestions
Integer iFile iField iIndex iLen iRow iMax eType iLength iDec
Handle hoServer
Boolean bContinue bCase bOldRelate bNeedsRelate
String sVal sLowSearch
RowID riTest
// ***************************************************//
// Added to fix Numeric Field
Integer iFirstRecord
// Added to support multiple columns
String[] asColumns
String sColumns
Integer iColumnCntr
//
// ********************************
Get Server to hoServer
Get Data_File to iFile
Get Data_Field to iField
If ((hoServer <> 0) and (iFile <> 0)) Begin
Get piFindIndex to iIndex
WebGet piMaxResults to iMax
WebGet pbCaseSensitive to bCase
Get_Attribute DF_FIELD_TYPE of iFile iField to eType
Get_Attribute DF_FIELD_LENGTH of iFile iField to iLength
Get_Attribute DF_FIELD_PRECISION of iFile iField to iDec
Move (iLength - iDec) to iLength
// Determine how many Columns will be displayed. psColumns is a new WebPropery holding a comma delimited list of Fields to display
WebGet psColumns to sColumns
Move (StrSplitToArray(sColumns,",")) to asColumns
If (iIndex <= 0) Begin
Get_Attribute DF_FIELD_INDEX of iFile iField to iIndex
End
If (iIndex > 0) Begin
Get No_Relate_State of hoServer to bOldRelate
Get DDOConstraintNeedsRelate of hoServer iIndex to bNeedsRelate
Set No_Relate_State of hoServer to (not(bNeedsRelate))
Move True to bContinue
Move (Length(sSearch)) to iLen
Move (Lowercase(sSearch)) to sLowSearch
Move 0 to iRow
// Find first record
Send Request_Read of hoServer FIRST_RECORD iFile iIndex
Get_Field_Value iFile iField to iFirstRecord // Save the value of the first record
Set_Field_Value iFile iField to sSearch
Send Request_Read of hoServer GE iFile iIndex
While (Found and bContinue)
Get_Field_Value iFile iField to sVal
If ((not(bCase) and Lowercase(Left(sVal, iLen)) = sLowSearch) or (bCase and Left(sVal, iLen) = sSearch)) Begin
Move (SerializeRowID(GetRowID(iFile))) to aSuggestions[iRow].sRowId
Move 0 to iColumnCntr
// Retrieve the display fields from the array
While (iColumnCntr<(SizeOfArray(asColumns)))
Get_Field_Value iFile asColumns[iColumnCntr] to aSuggestions[iRow].aValues[iColumnCntr]
Increment iColumnCntr
Loop
Increment iRow
Move (iRow < iMax) to bContinue
Send Request_Read of hoServer GT iFile iIndex
End
Else Begin
If (eType = DF_BCD and Length(sSearch) < iLength) Begin
// For numeric fields we'll jump in the index to the next possible value (for example from 40 to 400)
Move (GetRowID(iFile)) to riTest
// Consider: Runtime expression if sSearch contains something else as a number!
//Initialise the search by increasing the order of magnitude of sSearch in a loop until a record is found other than the first record.
While ( (Integer(sVal))=iFirstRecord)
Move (sSearch * 10) to sSearch
Set_Field_Value iFile iField to sSearch
Send Request_Read of hoServer GE iFile iIndex
Get_Field_Value iFile iField to sVal
Loop
//Add the record to the result. This step is not in the Original Class
Move (SerializeRowID(GetRowID(iFile))) to aSuggestions[iRow].sRowId
Move 0 to iColumnCntr
// Retrieve the display fields from the array
While (iColumnCntr<(SizeOfArray(asColumns)))
Get_Field_Value iFile asColumns[iColumnCntr] to aSuggestions[iRow].aValues[iColumnCntr]
Increment iColumnCntr
Loop
Increment iRow
Move (iRow < iMax) to bContinue
Send Request_Read of hoServer GT iFile iIndex
End
Else Begin
Move False to bContinue
End
End
Loop
Set No_Relate_State of hoServer to bOldRelate
End
End
End_Procedure
I have shown a screenshot of the finished product. The Code field starts at 10000.
Ian