//AB/ Project Anyflex
//AB/ Object oIDE_Project is a MdiFrame_Project
    //AB/ Set Size to 308 517
    //AB/ Set ProjectName to "Anyflex"
    //AB/ Set ProjectFileName to "Anyflex.src"
    //AB/ Set GenerateFileName to "NONAME15"

//AB-IgnoreStart
Use AnyflexEnt.pkg
#REPLACE CURRENT$WORKSPACE   "Tools.Anyflex"

// Project Object Structure
//   Main is a Panel
//     Client_Area is a AppClientArea
//     aData is a Array
//     aFilDef is a Array
//     aRecData is a Array
//     aFields is a Array
//     oRefreshTimer is a dfTimer
//     aColumnFilters is a Set

// Register all objects
Register_Object aColumnFilters
Register_Object aData
Register_Object aFields
Register_Object aFilDef
Register_Object aRecData
Register_Object Client_Area
Register_Object Main
Register_Object oRefreshTimer
//AB-IgnoreEnd


//AB-StoreTopStart
Use AnyFlexEnt.pkg  // Just if it is not precompiled.
Use AnyFlexCfg.pkg
Use cApplication.pkg
Use SysInfoDialog.Dg

//  Set date attributes as needed
Set_Date_Attribute SysDate4_State to True
Set_Date_Attribute Date4_State    to True
Set_Date_Attribute Epoch_Value    to 30

Object oApplication is a cApplication
    Set psCompany to "Nordteam Gruppen Aps"
    Set psProduct to "Anyflex"
    //Set psVersion to ""
    //Set psProgram to ""
    //Set psHelpFile To ""

    // Do not save window size. If this is set to true
    // the next time Anyflex i started it will start i maximized mode.
    Set pbPreserveEnvironment to False

    Procedure OnCreate
    //    Send DoOpenWorkspace CURRENT$WORKSPACE
    End_Procedure

End_Object  // oApplication

//Use Help_Ids.inc // Developer should provide this file of help context links.
//Use Std_Help.pkg


Use GlobalMemoryStatus.pkg
Procedure Activate_About
//    String sTitle sCopyright sVersion sAuthor
//    Move "Anyflex - Database editor" to sTitle
//    Move "Version 2006" to sVersion
//    Move "Open source" to sCopyright
//    Move "Allan Kim Eriksen"  to sAuthor
//    Send DoAbout sTitle sVersion sCopyright sAuthor "Anyflex.bmp"
    Send popup of oSystemInformationDialog
End_Procedure
On_Key Key_CTRL+Key_F1 Send Activate_About


Define C_SIZE_AFIELDS For 5
Define C34 For (Character(34))

Enum_List
    Define C_TEXTFIELDTYPE_ASCII
    Define C_TEXTFIELDTYPE_NUMERIC
    Define C_TEXTFIELDTYPE_DATE
End_Enum_List

Set_Argument_Size 64000


Object info_panel is a toolPanel
    Set locate_mode to center_on_screen
    Set minimize_icon to False
    Set modal_state to False
    Set Label to "Searching..."
    Set Size to 40 150
    Object tekst is a TextBox
        Set label to ""
        Set Size to 10 80
        Set Location to 5 5
    End_Object    // Textbox1
    Object tekst2 is a TextBox
        Set label to ""
        Set Size to 10 80
        Set Location to 15 5
    End_Object    // Textbox1
    Procedure DoShowWorking String sBesked
        Set label to "Working..."
        Set label of (tekst(Self)) to sBesked
        Set label of (tekst2(Self)) to ""
        Send Activate
    End_Procedure
End_Object


Object resinfo is a toolPanel
    Set locate_mode to center_on_screen
    Set minimize_icon to False
    Set modal_state to False
    Set Label to "Information"
    Set Size to 50 250
    Object otext is a TextBox
        Set label to ""
        Set Size to 10 100
        Set Location to 5 10
    End_Object    // Textbox1
    Object oPrg is a TextBox
        Set label to ""
        Set Size to 10 100
        Set Location to 17 10
    End_Object    // Textbox1
        Function callback String s Integer i Returns Integer
                If i eq 1 Set label to s
                Else If i eq 7 Set value of (oText(Self)) to s
                Else If i eq 8 Set value of (oPrg(Self)) to (Replace(",",s," of "))
        End_Function
End_Object


Procedure DoShowWorking String sBesked
    Send DoShowWorking of info_panel sBesked
End_Procedure


Procedure DoLukInfoPanel
    Send Close_panel of info_panel
End_Procedure


//AB-StoreTopEnd

//AB-IgnoreStart
Use dfPanel.pkg
Use DfAClnt.pkg
Use Windows.pkg
Use dfTimer.pkg
Use Set.pkg
//AB-IgnoreEnd

Object Main is a Panel

    //AB-StoreTopStart
    Property String pVersion Public ""
    
    //AB-StoreTopEnd

    Set Label to "ANYFLEX - Database editor"
    Set Location to 5 13
    Set Size to 269 456
    Set piMinSize to 102 300
    //AB-ToolbarPackage
    Use Statusbar.pkg  //  Tool-Bar object.
    //AB-End
    
    Object Client_Area is a AppClientArea

        //AB-StoreTopStart
        Property Integer pFilOk Public False            // True if there is a file opened.
        
        Property Integer pSystemFile Public False       // DF_FILE_IS_SYSTEM_FILE
        Property Number pDataNumFields Public 0         // DF_FILE_NUMBER_FIELDS
        
        Property String psFileName Public ""
        
        Property Boolean pIndexChangeOk Public False    // Bypass OnChange for combobox to avoid GPF.
        Property Boolean pbFilelistUsed Public False        // If the filelist can be used for opening files.
        
        Property Integer piFileNumber Public 0          // Contains the choosen filenumber from the filelist.
        Property Boolean pbRecnumFile public False      // Does the file understand recnum fields.
        Property String pValgtFelt Public ""            // The name of the choosen field.
        Property Integer piChoosedField Public -1       // The number of the choosen field.
        Property Integer pInternalFilenumber 0          // When no filelist this represent the last used internal filenumber
        Property String psFillValue Public ""           // The fill value fom the fillvalue.dg
        
        Property String[] psDriverName                  // Contrains a list of valid drivernames.
        
        // Properties used for importing text file
        Property String psImportFile Public ""
        Property String psRecord Public ""
        Property String psFieldSeperator Public ","
        Property String psTextQualification Public '"'
        Property String psDateFormat Public ""
        Property String psDateSeperator Public ""
        Property Boolean pbFourDigitYear Public True
        Property String psDecimalSign Public ""
        Property Boolean pbToOEM Public True
        Property Boolean pbFirstRowIsFieldNames Public False
        Property Boolean pbTextFormatIsFixedLength Public False
        Property Integer piCurrentFilenumber Public 0
        Property String psDFDecimalSeperator Public ""
        Property String psDFDateSeperator Public ""
        
        Define C_ENDOFDATA For "*ANYFLEX_EOD*"
        
        
        Function FixedLengthField Integer iFieldnumber Returns String
            Integer iLng iPos iMax
            String sLine sField
            Move "" to sField
            Get psRecord to sLine
            Get FieldStart of aFields iFieldnumber to iPos
            Get FieldLength of aFields iFieldnumber to iLng
            Move (Length(sLine)) to iMax
            If (iPos > iMax) Function_Return C_ENDOFDATA
            If (iPos <= 0 or iLng <= 0) Function_Return ""
            Move (Mid(sLine, iLng, iPos)) to sField
            Move (Rtrim(sField)) to sField
            Function_Return sField
        End_Function
        
        
        Function VariableLengthField Integer iFieldNumber Returns String
            String sLine sField sTextQual sFieldSep sByte
            Integer iLng iPos iActField iByte iTextQual iFieldSep
            Boolean bTxtQualStatus
            Move "" to sField
            Get psRecord to sLine
            Get psFieldSeperator to sFieldSep
            Get psTextQualification to sTextQual
            Move (Ascii(sFieldSep)) to iFieldSep
            Move (Ascii(sTextQual)) to iTextQual
            Move 0 to iPos
            Move 1 to iActField
            Move False to bTxtQualStatus
            Move (Length(sLine)) to iLng
            If (iLng > 0) Begin
                Repeat
                    Increment iPos
                    Move (Mid(sLine, 1, iPos)) to sByte
                    Move (Ascii(sByte)) to iByte
                    Case Begin
                        Case (iByte = iTextQual)
                            Move (not(bTxtQualStatus)) to bTxtQualStatus
                            Case Break
                        Case (iByte = iFieldSep)
                            If (bTxtQualStatus = False) Begin
                                Increment iActField
                            End
                            Else Begin
                                If (iActField = iFieldNumber) Begin
                                    Append sField sByte
                                End
                            End
                            Case Break
                        Case Else
                            If (iActField = iFieldNumber) Begin
                                Append sField sByte
                            End
                            Case Break
                    Case End
                Until (iPos = iLng or iActField > iFieldNumber)
            End
            If (iTextQual <> 0) Begin
                Move (Left(sField, 1)) to sByte
                Move (Ascii(sByte)) to iByte
                If (iByte = iTextQual) Begin
                    Move (Mid(sField, 2, (Length(sField) - 1))) to sField
                End
                Move (Right(sField, 1)) to sByte
                Move (Ascii(sByte)) to iByte
                If (iByte = iTextQual) Begin
                    Move (Mid(sField, 1, (Length(sField) - 1))) to sField
                End
            End
            If (iActField < iFieldnumber) Move C_ENDOFDATA to sField
            Function_Return sField
        End_Function
        
        
        Function DataFromField Integer iFieldNumber Integer iAsFieldType Returns String
            Boolean bFixed
            String sData sDecimalSign
            Integer iType
            Get pbTextFormatIsFixedLength to bFixed
            If (bFixed) Get FixedLengthField iFieldNumber to sData
            Else Get VariableLengthField iFieldNumber to sData
            Get FieldType of aFields iFieldnumber to iType
            If (num_arguments = 2) Move iAsFieldType to iType
            If (iType = C_TEXTFIELDTYPE_NUMERIC) Get DataFormatNumber sData to sData
            If (iType = C_TEXTFIELDTYPE_DATE) Get DataFormatDate sData to sData
            Function_Return sData
        End_Function
        
        
        Function DataFormatNumber String sNumber Returns String
            String sDecimalSign sTest sDFSep
            Integer iValue
            If (sNumber = "") Move "0" to sNumber
            Get psDecimalSign to sDecimalSign
            Get psDFDecimalSeperator to sDFSep
            Move (Trim(Replaces(sDecimalSign, sNumber, sDFSep))) to sNumber
            Move ("0123456789"+sDFSep) to sTest
            Ifnot (StringConsistsOf(sNumber,sTest)) Function_Return "0"
            Function_Return sNumber
        End_Function
        
        
        Function IsInt Global String sIntegerValue Returns Boolean
            Ifnot (stringConsistsOf(sIntegerValue,"0123456789")) Function_Return False
            Function_Return True
        End_Function
        
        
        Function DataFormatDate String sDate Returns String
            String sDateSep sDateFormat sDFDateSep
            String sYear sMonth sDay sFormatByte sDataByte
            Boolean bFourDigitYear
            Integer iPos iLng iYear iMonth iDay
            If (sDate = "") Function_Return ""
            Get psDateSeperator to sDateSep
            Get psDateFormat to sDateFormat
            Get pbFourDigitYear to bFourDigitYear
            Get psDFDateSeperator to sDFDateSep
            Move (Length(sDateFormat)) to iLng
            Move (Left(sDate, iLng)) to sDate
            Move "" to sYear
            Move "" to sMonth
            Move "" to sDay
            Move 0 to iPos
            Repeat
                Increment iPos
                Move (Mid(sDateFormat, 1, iPos)) to sFormatByte
                Move (Mid(sDate, 1, iPos)) to sDataByte
                If (sFormatByte = "Y") Append sYear sDataByte
                If (sFormatByte = "M") Append sMonth sDataByte
                If (sFormatByte = "D") Append sDay sDataByte
                If (sFormatByte = sDateSep and sDataByte <> sDateSep) Function_Return ""
            Until (iPos = iLng)
            If (bFourDigitYear = True) Begin
                If (Length(sYear) <> 4) Function_Return ""
            End
            Else Begin
                If (Length(sYear) <> 2) Function_Return ""
            End
            If (Length(sMonth) <> 2) Function_Return ""
            If (Length(sDay) <> 2) Function_Return ""
            If ((IsInt(sYear) = False) or (IsInt(sMonth) = False) or (IsInt(sDay) = False)) Function_Return ""
            Move sYear to iYear
            Move sMonth to iMonth
            Move sDay to iDay
            If (iYear = 0) Function_Return ""
            If (iMonth = 0 or iMonth > 12) Function_Return ""
            If (iDay = 0 or iDay > 31) Function_Return ""
            If (iDay > 29 and iMonth = 2) Function_Return ""
            If (iDay > 30 and (iMonth = 4 or iMonth = 6 or iMonth = 9 or iMonth = 11)) Function_Return ""
            Get DateCompose iDay iMonth iYear to sDate
            Function_Return sDate
        End_Function
        
        
        // Evaluate the number of fields from a variable length record
        Function NumberOfFieldsFromRecord Returns Integer
            Integer iFields
            String sField
            Move 0 to iFields
            Repeat
                Increment iFields
                Get VariableLengthField iFields to sField
            Until (sField = C_ENDOFDATA)
            Decrement iFields
            Function_Return iFields
        End_Function
        
        
        Function FilterMode Integer iMode Returns String
            String sRetVal
            Case Begin
                Case (iMode = 0)
                    Move "EQ" to sRetVal
                    Case Break
                Case (iMode = 1)
                    Move "NE" to sRetVal
                    Case Break
                Case (iMode = 2)
                    Move "LT" to sRetVal
                    Case Break
                Case (iMode = 3)
                    Move "LE" to sRetVal
                    Case Break
                Case (iMode = 4)
                    Move "GT" to sRetVal
                    Case Break
                Case (iMode = 5)
                    Move "GE" to sRetVal
                    Case Break
                Case (iMode = 6)
                    Move "CONTAINS" to sRetVal
                    Case Break
                Case (iMode = 7)
                    Move "MATCHES" to sRetVal
                    Case Break
                Case (iMode = 8)
                    Move "UPPER" to sRetVal
                    Case Break
                Case (iMode = 9)
                    Move "NOTUPPER" to sRetVal
                    Case Break
                Case Else
                    Move "" to sRetVal
                    Case Break
            Case End
            Function_Return sRetVal
        End_Function
        
        
        Function OpenTextFile Returns Boolean
            String sFile
            Boolean bOk
            Integer iFilenumber
            Move False to bOk
            Get psImportFile to sFile
            If (sFile = "") Function_Return False
            Get Seq_New_Channel to iFilenumber
            Direct_Input Channel iFilenumber sFile
            If (Seqeof) Begin
                Close_Input Channel iFilenumber
                Send Seq_Release_Channel iFilenumber
                Move 0 to iFilenumber
            End
            Set piCurrentFilenumber to iFilenumber
            If (iFilenumber <> 0) Move True to bOk
            Function_Return bOk
        End_Function
        
        
        Procedure CloseTextFile
            Integer iFilenumber
            Get piCurrentFilenumber to iFilenumber
            If (iFilenumber = 0) Procedure_Return
            Close_Input Channel iFilenumber
            Send Seq_Release_Channel iFilenumber
            Set piCurrentFilenumber to 0
        End_Procedure
        
        
        Function ReadTextFile Returns Boolean
            Integer iFilenumber
            Boolean bConvert bOk
            String sLine
            Move False to bOk
            Get piCurrentFilenumber to iFilenumber
            If (iFilenumber = 0) Function_Return False
            Get pbToOEM to bConvert
            Readln Channel iFilenumber sLine
            Move (not(Seqeof)) to bOk
            If (bConvert = True) Move (ToOEM(sLine)) to sLine
            Set psRecord to sLine
            Function_Return bOk
        End_Function
        
        
        Function NextFreeFilenumber Integer iFrom Returns Integer
            Integer iFile iOffset
            Boolean bFilelistOk
            Move 0 to iOffset
            If (num_arguments = 1) Move iFrom to iOffset
            Get pbFilelistUsed to bFilelistOk
            If (bFilelistOk) Begin
                Get_Attribute DF_FILE_NEXT_EMPTY of iOffset to iFile
            End
            Else Begin
                Get pInternalFilenumber to iFile
                If (iOffset > iFile) Move iOffset to iFile
                Increment iFile
                Set pInternalFilenumber to iFile
            End
            Function_Return iFile
        End_Function
        
        
        Function DriverForOpenAs String sAktFil Returns String
          String sLine sDriver
          Integer iDrvFound iSeqFilenumber
          Move (Trim(sAktFil)) to sAktFil
          Move (toAnsi(sAktFil)) to sAktFil
        //  Uppercase sAktFil
        //  If ".INT" In sAktFil Begin
        //      Move 0 to iDrvFound
        //      Get Seq_New_Channel to iSeqFilenumber
        //      Direct_Input Channel iSeqFilenumber sAktfil
        //      While ((iDrvFound = 0) and (not(Seqeof)))
        //          Readln sLine
        //          If "DRIVER_NAME " In sLine Begin
        //              Right sLine to sDriver (Length(sLine) - 12)
        //              Increment iDrvFound
        //          End
        //      Loop
        //      Close_Input Channel iSeqFilenumber
        //      Send Seq_Release_Channel iSeqFilenumber
        //      If (Pos((sDriver+":"), sAktFil) = 0) Move (sDriver+":"+sAktFil) to sAktFil
        //  End
          Function_Return sAktFil
        End_Function
        
        
        Procedure DoCloseAllFiles
            Close DF_ALL    // Let's see if this has been fixed.
        //    Integer iFile
        //    Move 0 to iFile
        //    Repeat
        //        Get_Attribute DF_FILE_NEXT_OPENED of iFile to iFile
        //        If (iFile > 0) Close iFile
        //    Until (iFile = 0)
        End_Procedure
        
        
        Function Maske Integer iLCif Integer iRCif Returns String
            Local String sMask
            Move ",#" to sMask //tusinde seperator  samt plads til negativ symbol
            If (iLCif > 0) Append sMask (Repeat("#", (iLCif - 1))) "0"
            If (iRCif > 0) Append sMask "." (Repeat("0", iRCif))
            Function_Return sMask
        End_Function
        
        
        Function FirstFieldnumber Returns Integer
            Integer iNumber iColumnFilter
            Boolean bRecnumFile
            Get pbRecnumFile to bRecnumFile
            If (bRecnumFile = True) Move 0 to iNumber
            Else Move 1 to iNumber
            Function_Return iNumber
        End_Function
        
        
        Function FirstIndexNumber Returns Integer
            Integer iNumber
            Boolean bRecnumFile
            Get pbRecnumFile to bRecnumFile
            If (bRecnumFile = True) Move 0 to iNumber
            Else Move 1 to iNumber
            Function_Return iNumber
        End_Function
        
        
        Procedure DoInitProp
            String[] sDrivername
            Move "DATAFLEX" to sDrivername[0]
            Move "MSSQLDRV" to sDrivername[1]
            Move "DFBTRDRV" to sDrivername[2]
            Move "DB2_DRV"  to sDrivername[3]
            Move "ODBC_DRV" to sDrivername[4]
            Set psDrivername to sDrivername
        End_Procedure
        
        
        // Returns the drivername if sEntry begins with a valid drivername.
        Function ExtractDrivername String sEntry Returns String
            String[] sDrivername
            Integer iAkt iMax
            Get psDrivername to sDrivername
            Move (SizeOfArray(sDrivername)) to iMax
            Decrement iMax
            For iAkt From 0 to iMax
                If (sEntry Contains (sDrivername[iAkt]+":")) Function_Return sDrivername[iAkt]
            Loop
            Function_Return ""
        End_Function
        
        
        // Returns true if sEntry begins with one of the valid drivernames.
        Function ContainsDrivername String sEntry Returns Boolean
            String sDrivername
            Get ExtractDrivername sEntry to sDrivername
            If (sDrivername <> "") Function_Return True
            Function_Return False
        End_Function
        
        
        // Remove leading drivername and traling .INT
        Function StripPrefix String sEntry Returns String
            String sDrivername
            Move (Trim(Uppercase(sEntry))) to sEntry
            Get ExtractDrivername sEntry to sDrivername
            If (sDrivername <> "") Move (Replace((sDrivername+":"), sEntry, "")) to sEntry
            Move (Replace(".INT", sEntry, "")) to sEntry
            Move (Replace(".DAT", sEntry, "")) to sEntry
            Function_Return sEntry
        End_Function
        
        
        //AB-StoreTopEnd

        //AB-ViewStart
        Use anyflex.vw
        //AB-ViewEnd

        //AB-StoreStart
        
        Procedure Activate
            String sValue
            Integer iValue
            Send DoInitProp
            Forward Send Activate
            Get_Attribute DF_DECIMAL_SEPARATOR to iValue
            Move (Character(iValue)) to sValue
            Set psDFDecimalSeperator to sValue
            Get_Attribute DF_DATE_SEPARATOR to iValue
            Move (Character(iValue)) to sValue
            Set psDFDateSeperator to sValue
        End_Procedure
        
        
        Procedure OnRefreshTimer
            Send OnRefreshTimer of tilpas_vw
        End_Procedure
        
        
        
        //AB-StoreEnd

    End_Object    // Client_Area

    Object aData is a Array
        //AB/ Set Location to 5 119
    End_Object    // aData

    Object aFilDef is a Array
        //AB/ Set Location to 6 172
    End_Object    // aFilDef

    Object aRecData is a Array
        //AB/ Set Location to 6 143
    End_Object    // aRecData

    Object aFields is a Array
        //AB/ Set Location to 34 120

        //AB-StoreStart
        // Used for importing text file
        //
        // Item 0: FieldName
        // Item 1: FieldType
        // Item 2: FieldStart  (Fixed length only, else 0)
        // Item 3: FieldLength
        // Item 4: FieldSkip   (True/False)
        
        
        Function Fieldname Integer iFieldnumber Returns String
            String sValue
            Integer iItem
            Decrement iFieldnumber
            Move (iFieldnumber * C_SIZE_AFIELDS) to iItem
            Get string_value Item iItem to sValue
            Function_Return sValue
        End_Function
        
        
        Procedure Set Fieldname Integer iFieldnumber String sValue
            Integer iItem
            Decrement iFieldnumber
            Move (iFieldnumber * C_SIZE_AFIELDS) to iItem
            Set array_value Item iItem to sValue
        End_Procedure
        
        
        Function FieldType Integer iFieldnumber Returns Integer
            Integer iValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 1) to iItem
            Get integer_value Item iItem to iValue
            Function_Return iValue
        End_Function
        
        
        Procedure Set FieldType Integer iFieldnumber Integer iValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 1) to iItem
            Set array_value Item iItem to iValue
        End_Procedure
        
        
        Function FieldStart Integer iFieldnumber Returns Integer
            Integer iValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 2) to iItem
            Get integer_value Item iItem to iValue
            Function_Return iValue
        End_Function
        
        
        Procedure Set FieldStart Integer iFieldnumber String sValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 2) to iItem
            Set array_value Item iItem to sValue
        End_Procedure
        
        
        Function FieldLength Integer iFieldnumber Returns Number
            Number nValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 3) to iItem
            Get number_value Item iItem to nValue
            Function_Return nValue
        End_Function
        
        
        Procedure Set FieldLength Integer iFieldnumber Number nValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 3) to iItem
            Set array_value Item iItem to nValue
        End_Procedure
        
        
        Function FieldSkip Integer iFieldnumber Returns Boolean
            String sValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 4) to iItem
            Get string_value Item iItem to sValue
            Function_Return sValue
        End_Function
        
        
        Procedure Set FieldSkip Integer iFieldnumber Boolean bValue
            Integer iItem
            Decrement iFieldnumber
            Move ((iFieldnumber * C_SIZE_AFIELDS) + 4) to iItem
            Set array_value Item iItem to bValue
        End_Procedure
        
        
        Function NumberOfFields Returns Integer
            Integer iMaxItems iValue
            Get item_count to iMaxItems
            Move (iMaxItems / C_SIZE_AFIELDS) to iValue
            Function_Return iValue
        End_Function
        
        
        Function NumberOfImportFields Returns Integer
            Integer iNoFields iCnt iColumns
            Boolean bSkip
            Get NumberOfFields of aFields to iNoFields
            Move 0 to iColumns
            For iCnt From 1 to iNoFields
                Get FieldSkip iCnt to bSkip
                If (bSkip = False) Increment iColumns
            Loop
            Function_Return iColumns
        End_Function
        
        
        Procedure DoFormatFieldList Integer iNoFields
            Integer iMax iAct iCnt
            Get NumberOfFields to iAct
            While (iAct < iNoFields)
                Increment iAct
                Set FieldName iAct to ("Field"+String(iAct))
                Set FieldType iAct to C_TEXTFIELDTYPE_ASCII
                Set FieldStart iAct to 0
                Set FieldLength iAct to 50
                Set FieldSkip iAct to False
            Loop
            Get item_count to iMax
            Decrement iMax
            Move (iNoFields * C_SIZE_AFIELDS) to iAct
            For iCnt From iAct to iMax
                Send Delete_Item iAct
            Loop
        End_Procedure
        
        
        Function FieldTypeToInteger String sType Returns Integer
            Integer iType
            Case Begin
                Case (sType = "Numeric")
                    Move C_TEXTFIELDTYPE_NUMERIC to iType
                    Case Break
                Case (sType = "Date")
                    Move C_TEXTFIELDTYPE_DATE to iType
                    Case Break
                Case Else
                    Move C_TEXTFIELDTYPE_ASCII to iType
                    Case Break
            Case End
            Function_Return iType
        End_Function
        
        
        Function FieldTypeToString Integer iType Returns String
            String sType
            Case Begin
                Case (iType = C_TEXTFIELDTYPE_NUMERIC)
                    Move "Numeric" to sType
                    Case Break
                Case (iType = C_TEXTFIELDTYPE_DATE)
                    Move "Date" to sType
                    Case Break
                Case Else
                    Move "Text" to sType
                    Case Break
            Case End
            Function_Return sType
        End_Function
        
        
        Function FieldAtNumber String sFieldname Returns Integer
            Integer iCnt iMax iFieldnumber
            String sTest
            Move (Uppercase(sFieldname)) to sFieldname
            Get NumberOfFields to iMax
            Move 0 to iFieldNumber
            Move 1 to iCnt
            Repeat
                Get FieldName iCnt to sTest
                Move (Uppercase(sTest)) to sTest
                If (sTest = sFieldname) Move iCnt to iFieldnumber
                Increment iCnt
            Until (iCnt > iMax or iFieldnumber > 0)
            Function_Return iFieldnumber
        End_Function
        
        
        Procedure CopyField Integer iFieldFrom Integer iFieldTo
            String sName
            Integer iType iStart iMax
            Boolean bSkip
            Number nLength
            If (iFieldFrom = 0 or iFieldTo = 0) Procedure_Return
            Get NumberOfFields to iMax
            If (iFieldTo > iMax) Send DoFormatFieldList iFieldTo
            Get FieldName iFieldFrom to sName
            Get FieldType iFieldFrom to iType
            Get FieldStart iFieldFrom to iStart
            Get FieldLength iFieldFrom to nLength
            Get FieldSkip iFieldFrom to bSkip
            Set FieldName iFieldTo to sName
            Set FieldType iFieldTo to iType
            Set FieldStart iFieldTo to iStart
            Set FieldLength iFieldTo to nLength
            Set FieldSkip iFieldTo to bSkip
        End_Procedure
        //AB-StoreEnd

    End_Object    // aFields

    Object oRefreshTimer is a dfTimer
        //AB/ Set Location to 34 147
        Set Auto_Start_State to FALSE
        Set Auto_Stop_State to FALSE
        Set Timer_Active_State to FALSE

        //AB-StoreStart
        //OnTimer is a predefined method in the dfTimer class
        //OnTimer executes each time the TimeOut interval passes
        Procedure OnTimer Integer wParam Integer lParam
            Forward Send OnTimer wParam lParam
            Send OnRefreshTimer
        End_Procedure // OnTimer
        //AB-StoreEnd

    End_Object    // oRefreshTimer

    Object aColumnFilters is a Set
        //AB/ Set Location to 34 173

        //AB-StoreStart
                                                                                                                                                                                                                                                                                
        // If columnfilter is active this array contains the fieldnumbers to show in the grid.
        //AB-StoreEnd

    End_Object    // aColumnFilters

    //AB-StatusBarPackage
    Use Statusbar.pkg  //  Status-Bar object.
    //AB-End
    

    //AB-StoreStart
                                    
    On_Key Key_F1 Send DoHelp
    
    
    Procedure DoHelp
        String sPath
        Get GetApplicationPath of oApplication to sPath
        Send vShellExecute "OPEN" (sPath+"\Anyflex.chm") "" sPath
    End_Procedure
    
    
    Procedure OnRefreshTimer
        Send OnRefreshTimer of Client_Area
    End_Procedure
    
    
    Procedure exit_application
        // Close vdfquery down before forwarding exit_application
        // If vdfquery is not closed it will give an error "invalid message msg_show_status_help"
        Broadcast Send Close_Query_View of Client_Area
        Forward Send exit_application
    End_Procedure
    
    
    //AB-StoreEnd

End_Object    // Main


//AB-StoreStart

Send Activate_View to (tilpas_vw(client_Area(main(Self))))

Start_UI
//AB-StoreEnd

//AB/ End_Object    // oIDE_Project
