Use Windows.pkg Use dfRadio.pkg Use dfCmbFrm.pkg Use File_dlg.Pkg Use cCJGrid.pkg Use cCJGridColumn.pkg Use cDataColumn.pkg Use cTextFile.pkg Use ImportTextFieldMarkup.dg // ToDo: Add option to apply a string of hex values like {$0C}{$0A} for the separation character forms. Object Import_textfile is a ModalPanel Set Label to "Import textfile" Set Location to 10 9 Set Size to 313 544 Set piMinSize to 250 500 Property Boolean pbOk False Property String psFileName "" Property tsTextFileStructure plsTextFileStructure Property Boolean pbPreload True Property Boolean pbLoadExampleData True Set Border_Style to Border_Thick Object oOK_btn is a Button Set Label to "&OK" Set Location to 296 437 Set peAnchors to anBottomRight Procedure OnClick tsTextFileStructure lsTextFileStructure Get TextFileStructure of oFields to lsTextFileStructure Set plsTextFileStructure to lsTextFileStructure Set pbOK to True Send Close_Panel End_Procedure End_Object Object oCancel_btn is a Button Set Label to "&Cancel" Set Location to 296 491 Set peAnchors to anBottomRight Procedure OnClick Send Close_Panel End_Procedure End_Object Object oCntHeader is a Container3d Set Size to 125 245 Set Location to 2 3 Object oTextFormat is a RadioGroup Set Size to 39 77 Set Location to 4 12 Set Label to "Textformat" Object oFixed is a Radio Set Label to "Fixed length." Set Size to 10 57 Set Location to 10 5 End_Object Object oSeparator is a Radio Set Label to "Separator." Set Size to 10 49 Set Location to 25 5 End_Object Procedure Notify_Select_State Integer iToItem Integer iFromItem Forward Send Notify_Select_State iToItem iFromItem If (iToItem = 0) Begin Set pbTextFormatIsFixedLength to True Set pbVisible of oTextFieldStart to True Set pbVisible of oTextFieldLength to True Set Enabled_State of oFieldSeparator to False Set Enabled_State of oText to False Set Enabled_state of oFldAdd_bn to True Set Enabled_state of oFldInsert_bn to True Set Enabled_state of oFldDelete_bn to True Set Enabled_State of oFldRange_bn to True Send ClearFieldStructure End Else Begin Set pbTextFormatIsFixedLength to False Set pbVisible of oTextFieldStart to False Set pbVisible of oTextFieldLength to False Set Enabled_State of oFieldSeparator to True Set Enabled_State of oText to True Set Enabled_state of oFldAdd_bn to False Set Enabled_state of oFldInsert_bn to False Set Enabled_state of oFldDelete_bn to False Set Enabled_State of oFldRange_bn to False End Set pbPreload to True End_Procedure Procedure ClearFieldStructure tsTextFileStructure lsTextFileStructure Get plsTextFileStructure to lsTextFileStructure Move (ResizeArray(lsTextFileStructure.lsField, 0)) to lsTextFileStructure.lsField Set plsTextFileStructure to lsTextFileStructure Send ResetGrid of oFields End_Procedure Procedure Activating Forward Send Activating Set Current_Radio to 1 End_Procedure End_Object Object oCodepage is a RadioGroup Set Size to 39 77 Set Location to 46 12 Set Label to "Codepage" Object oANSI is a Radio Set Label to "ANSI." Set Size to 10 35 Set Location to 10 5 End_Object Object oOEM is a Radio Set Label to "OEM." Set Size to 10 35 Set Location to 25 5 End_Object Procedure Notify_Select_State Integer iToItem Integer iFromItem Forward Send Notify_Select_State iToItem iFromItem Set pbPreload to True End_Procedure End_Object Object oFirstRow is a CheckBox Set Label to "First row contains field names." Set Size to 10 105 Set Location to 108 5 Procedure OnChange Boolean bChecked Set pbPreload to True End_Procedure End_Object Object oRowSeparator is a ComboForm Set Label to "Row separator:" Set Size to 12 67 Set Location to 2 170 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Combo_Sort_State to False Procedure Combo_Fill_List Send Combo_Add_Item "{CR_LF}" Send Combo_Add_Item "{CL}" End_Procedure Function SeparatorCharacter Returns String String sValue Get Value to sValue If (sValue = "{CR_LF}") Move ((Character(13))+(character(10))) to sValue If (sValue = "{CL}") Move (Character(10)) to sValue Function_Return sValue End_Function Procedure Set SeparatorCharacter String sValue If (sValue = ((Character(13))+(character(10)))) Move "{CR_LF}" to sValue If (sValue = (Character(10))) Move "{CL}" to sValue Set Value to sValue End_Procedure Procedure Activating Forward Send Activating Set Value to "{CR_LF}" End_Procedure End_Object Object oFieldSeparator is a ComboForm Set Label to "Field separator:" Set Size to 12 67 Set Location to 22 170 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Combo_Sort_State to FALSE Procedure Combo_Fill_List Send Combo_Add_Item "," Send Combo_Add_Item ";" Send Combo_Add_Item "{Tabulator}" Send Combo_Add_Item "{Space}" End_Procedure Function SeparatorCharacter Returns String String sValue Get Value to sValue If (sValue = "{Tabulator}") Move (Character(9)) to sValue If (sValue = "{Space}") Move " " to sValue Function_Return sValue End_Function Procedure Set SeparatorCharacter String sValue If (sValue = (Character(9))) Move "{Tabulator}" to sValue If (sValue = " ") Move "{Space}" to sValue Set Value to sValue End_Procedure Procedure Activating Forward Send Activating Set Value to "," End_Procedure End_Object Object oText is a ComboForm Set Label to "Text qualification:" Set Size to 12 67 Set Location to 37 170 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Combo_Sort_State to FALSE Procedure Combo_Fill_List Send Combo_Add_Item '"' Send Combo_Add_Item "'" End_Procedure Procedure OnChange String sValue Get Value to sValue End_Procedure Procedure Activating Forward Send Activating Set Value to '"' End_Procedure End_Object Object oDateFormat is a ComboForm Set Label to "Date format:" Set Size to 12 67 Set Location to 59 170 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Entry_State to False Set Combo_Sort_State to False Set Capslock_State to True {Visibility = Private} Property Integer piCurrentItem -1 Procedure Combo_Fill_List String sValue sYear sDateSep Boolean bFourYear Send Combo_delete_data Get Value of oDateSeparator to sDateSep Get Checked_State of oFourDigitYear to bFourYear Move "YY" to sYear If (bFourYear = True) Move "YYYY" to sYear Move "" to sValue Append sValue "DD" sDateSep "MM" sDateSep sYear // European format Send Combo_Add_Item sValue Move "" to sValue Append sValue "MM" sDateSep "DD" sDateSep sYear // USA format Send Combo_Add_Item sValue Move "" to sValue Append sValue sYear sDateSep "MM" sDateSep "DD" // Military format Send Combo_Add_Item sValue End_Procedure Procedure OnChange String sValue Integer iComboItem Get Value to sValue Get Combo_Item_Matching sValue to iComboItem Set piCurrentItem to iComboItem End_Procedure Procedure SelectDefaultDateFormat Integer iDateFormat iComboItem String sValue Get piCurrentItem to iComboItem If (iComboItem = -1) Begin Get_Attribute DF_DATE_FORMAT to iDateFormat If (iDateFormat = DF_DATE_EUROPEAN) Begin Move 0 to iComboItem End Else If (iDateFormat = DF_DATE_USA) Begin Move 1 to iComboItem End Else Begin Move 2 to iComboItem End End Get Combo_Value iComboItem to sValue Set Value to sValue Set piCurrentItem to iComboItem End_Procedure Procedure Deactivating Forward Send Deactivating Set piCurrentItem to -1 End_Procedure End_Object Object oDateSeparator is a ComboForm Set Label to "Date separator:" Set Size to 12 67 Set Location to 74 170 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Combo_Sort_State to False Procedure Combo_Fill_List Send Combo_Add_Item "-" Send Combo_Add_Item "/" End_Procedure Procedure OnChange Send Combo_fill_list of oDateFormat Send SelectDefaultDateFormat of oDateFormat End_Procedure Procedure Activating Integer iChar Forward Send Activating Get_Attribute DF_DATE_SEPARATOR to iChar Set Value to (Character(iChar)) End_Procedure End_Object Object oFourDigitYear is a CheckBox Set Label to "Four digit year." Set Size to 10 63 Set Location to 88 170 Procedure OnChange Send Combo_fill_list of oDateFormat Send SelectDefaultDateFormat of oDateFormat End_Procedure Procedure Activating Forward Send Activating Set Checked_State to True End_Procedure End_Object Object oDecimalsign is a ComboForm Set Label to "Decimal sign:" Set Size to 12 67 Set Location to 106 170 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Procedure Combo_Fill_List Send Combo_Add_Item "," Send Combo_Add_Item "." End_Procedure Procedure Activating Integer iChar Forward Send Activating Get_Attribute DF_DECIMAL_SEPARATOR to iChar Set Value to (Character(iChar)) End_Procedure End_Object Procedure LoadFileStructure tsTextFileStructure lsTextFileStructure Get plsTextFileStructure to lsTextFileStructure Set Current_Radio of oTextFormat to lsTextFileStructure.iFormat Set SeparatorCharacter of oRowSeparator to lsTextFileStructure.sRowSeparator Set SeparatorCharacter of oFieldSeparator to lsTextFileStructure.sFieldSeparator Set Value of oText to lsTextFileStructure.sTextQualification Set Current_Radio of oCodepage to lsTextFileStructure.iCodePage Set Checked_State of oFirstRow to lsTextFileStructure.bFirstRowHasFieldNames Set Value of oDateSeparator to lsTextFileStructure.sDateSeparator Set Checked_State of oFourDigitYear to lsTextFileStructure.bFourDigitYear Set Value of oDateFormat to lsTextFileStructure.sDateFormat // Set the date format after the date separator and four-year marker has been set. Set Value of oDecimalsign to lsTextFileStructure.sDecimalSign End_Procedure End_Object Object oCntData is a Container3d Set Size to 164 539 Set Location to 129 2 Set peAnchors to anAll Object oExampleTextfile is a cTextFile Procedure OnFormatData Integer iColumn String ByRef sData Boolean ByRef bCancel Integer iColumnsLimit Forward Send OnFormatData iColumn (&sData) Get Value of oColumnsLimit to iColumnsLimit If (iColumnsLimit > 0 and iColumn >= iColumnsLimit) Begin Move True to bCancel End End_Procedure End_Object Object oData is a cCJGrid Set Size to 143 529 Set Location to 14 3 Set pbReadOnly to True Set peAnchors to anAll // ToDo: When dragging and reordering the columns it should be reflected in the file structure. Procedure LoadDataExample Handle hColumn String sProgressmessage tsTextFileStructure lsTextFileStructure tDataSourceRow[] lsData Boolean bOk bEndOfFile bStop String[] sRow Integer iMaxColumn iColumn iFileRow iDataRow iShowColumn Integer iLeftCif iRightCif iMaxRows Send DestroyColumnObjects Send Initialize_StatusPanel of ghoStatusPanel "Import textfile" "Example data" "Building example data grid" Send Start_StatusPanel of ghoStatusPanel Send Update_StatusPanel of ghoStatusPanel "Creating columns.." Get TextFileStructure of oFields to lsTextFileStructure Set plsTextFileStructure of oExampleTextfile to lsTextFileStructure Get Value of oRecordsLimit to iMaxRows If (iMaxRows = 0) Begin Move -1 to iMaxRows End Get OpenTextFile of oExampleTextfile to bOk If bOk Begin Move (SizeOfArray(lsTextFileStructure.lsField)) to iMaxColumn For iColumn from 0 to (iMaxColumn - 1) If (not(lsTextFileStructure.lsField[iColumn].bSkip)) Begin Get Create (RefClass(cDataColumn)) to hColumn Set psCaption of hColumn to lsTextFileStructure.lsField[iColumn].sName Set piDefinedColumns of hColumn to (SizeOfArray(lsTextFileStructure.lsField)) Case Begin Case (lsTextFileStructure.lsField[iColumn].iType = C_TEXTFIELDTYPE_ASCII) Set piWidth of hColumn to 100 Case Break Case (lsTextFileStructure.lsField[iColumn].iType = C_TEXTFIELDTYPE_NUMERIC) Set piWidth of hColumn to 60 Set peDataType of hColumn to Mask_Numeric_Window Move (Integer(lsTextFileStructure.lsField[iColumn].nLength)) to iLeftCif Move ((lsTextFileStructure.lsField[iColumn].nLength - iLeftCif) * 10) to iRightCif Send CreateNumericMask of hColumn iLeftCif iRightCif Case Break Case (lsTextFileStructure.lsField[iColumn].iType = C_TEXTFIELDTYPE_DATE) Set piWidth of hColumn to 45 Set peDataType of hColumn to Mask_Date_Window Case Break Case End End Loop Send CreateColumns Move 0 to iFileRow Move 0 to iDataRow If (iMaxRows = -1) Begin Move "Loading %1 records..." to sProgressmessage End Else Begin Move "Loading %1 of %2 records..." to sProgressmessage End Repeat Get NextTextRow of oExampleTextfile (&sRow) (&bEndOfFile) to bOk If bOk Begin Send Update_StatusPanel of ghoStatusPanel (SFormat(sProgressmessage, iDataRow, iMaxRows)) If (iFileRow = 0 and lsTextFileStructure.bFirstRowHasFieldNames = True) Begin // Skip the first row. End Else Begin Move 0 to iShowColumn Move (SizeOfArray(sRow)) to lsData[iDataRow].vTag For iColumn from 0 to (iMaxColumn - 1) If (lsData[iDataRow].vTag > iColumn) Begin If (not(lsTextFileStructure.lsField[iColumn].bSkip)) Begin Move sRow[iColumn] to lsData[iDataRow].sValue[iShowColumn] Increment iShowColumn End End End Increment iDataRow End End Increment iFileRow Get Check_StatusPanel of ghoStatusPanel to bStop Until (iDataRow = iMaxRows or bEndOfFile = True or bOk = False or bStop = True) Get CloseTextFile of oExampleTextfile to bOk End Send InitializeData lsData Send MovetoFirstRow Send Stop_StatusPanel of ghoStatusPanel End_Procedure End_Object Object oTextBox1 is a Textbox Set Label to "Example of data as imported:" Set Location to 2 3 Set Size to 10 135 End_Object Object oRecordsLimit is a Form Set Size to 13 45 Set Location to 1 349 Set Label to "Limit example rows to:" Set Label_Col_Offset to 0 Set Label_Justification_Mode to JMode_Right Set Numeric_Mask 0 to 6 0 Set peAnchors to anTopRight Procedure Activating Forward Send Activating Set Value to 50 End_Procedure End_Object Object oColumnsLimit is a Form Set Size to 13 45 Set Location to 1 479 Set Label to "Limit example columns to:" Set Label_Col_Offset to 0 Set Label_Justification_Mode to JMode_Right Set Numeric_Mask 0 to 6 0 Set peAnchors to anTopRight // ToDo: Check to see, if this is still working. Procedure Activating Forward Send Activating Set Value to 200 End_Procedure End_Object End_Object Object oCntFields is a Container3d Set Size to 125 291 Set Location to 2 250 Set peAnchors to anTopLeftRight Object oFields is a cCJGrid Set Size to 89 281 Set Location to 12 3 Set pbDrawGridForEmptySpace to False Set pbAllowColumnRemove to False Set pbAllowColumnReorder to False Set peAnchors to anAll Set peColumnStyle to xtpColumnShaded Object oTextFieldName is a cCJGridColumn Set piWidth to 188 Set psCaption to "Name" Set phoHeaderContextMenu to 0 Function OnValidating Returns Boolean Boolean bRetVal String sValue Forward Get OnValidating to bRetVal Get SelectedRowValue to sValue If (Trim(sValue) = "") Begin Send UserError "Please enter a name for the text field." "Text field name validation error" Move True to bRetVal End Function_Return bRetVal End_Function Procedure Prompt Send DoMarkup End_Procedure Function InitialValue Returns String Handle hoDatasource Integer iSize Get phoDataSource to hoDatasource Get RowCount of hoDatasource to iSize Increment iSize Function_Return (SFormat("Field %1", iSize)) End_Function End_Object Object oTextFieldType is a cCJGridColumn Set piWidth to 94 Set psCaption to "Type" Set pbComboButton to True Set pbComboEntryState to False Send ComboAddItem "Text" C_TEXTFIELDTYPE_ASCII Send ComboAddItem "Numeric" C_TEXTFIELDTYPE_NUMERIC Send ComboAddItem "Date" C_TEXTFIELDTYPE_DATE Function OnValidating Returns Boolean Boolean bRetVal String sValue Forward Get OnValidating to bRetVal Get SelectedRowValue to sValue If (Trim(sValue) = "") Begin Send UserError "Please select a text field type" "Text field type validation error" Move True to bRetVal End Function_Return bRetVal End_Function Function CompareComboData tComboItemData lsA tComboItemData lsB Returns Integer If (lsA.iData > lsB.iData) Function_Return (GT) If (lsA.iData < lsB.iData) Function_Return (LT) Function_Return (EQ) End_Function // Gets iData from the row with matching caption. // Returns true if the row could be found. Function ComboRowData String sCaption Integer ByRef iData Returns Boolean Integer iComboItem tComboItemData[] lsComboData Get ComboData to lsComboData Get ComboFindItem 0 sCaption to iComboItem If (iComboItem > -1) Begin Move lsComboData[iComboItem].iData to iData End Function_Return (iComboItem > -1) End_Function // Gets Caption from the row with matching iData. // Returns true if the row could be found. Function ComboRowCaption Integer iData String ByRef sCaption Returns Boolean Integer iComboItem tComboItemData[] lsFieldTypeData tComboItemData lsSearchFieldTypeData Get ComboData to lsFieldTypeData Move iData to lsSearchFieldTypeData.iData Move (SearchArray(lsSearchFieldTypeData, lsFieldTypeData, Self, RefFunc(CompareComboData))) to iComboItem If (iComboItem > -1) Begin Move lsFieldTypeData[iComboItem].sCaption to sCaption End Function_Return (iComboItem > -1) End_Function // Gets iData from the selected combo item. Function SelectedComboRowData Integer ByRef iData Returns Boolean String sCaption Boolean bRowDataFound Get SelectedRowValue to sCaption Get ComboRowData sCaption (&iData) to bRowDataFound Function_Return bRowDataFound End_Function Procedure Prompt Send DoMarkup End_Procedure Function InitialValue Returns String Function_Return "Text" End_Function End_Object Object oTextFieldStart is a cCJGridColumn Set piWidth to 76 Set psCaption to "Start" Set Prompt_Button_Mode to PB_PromptOn Send CreateNumericMask 6 0 Function OnValidating Returns Boolean Boolean bRetVal Integer iValue iFormat Forward Get OnValidating to bRetVal Get Current_Radio of oTextFormat to iFormat If (iFormat = C_TEXTFORMAT_FIXEDLENGTH) Begin Get SelectedRowValue to iValue If (iValue = 0) Begin Send UserError "Please enter a start value" Move True to bRetVal End End Function_Return bRetVal End_Function Procedure Prompt Send DoMarkup End_Procedure Function InitialValue Returns String Function_Return "1" End_Function End_Object Object oTextFieldLength is a cCJGridColumn Set piWidth to 76 Set psCaption to "Length" Set Prompt_Button_Mode to PB_PromptOn Send CreateNumericMask 6 1 Function OnValidating Returns Boolean Boolean bRetVal bRowDataFound Integer iFormat iData Number nValue Forward Get OnValidating to bRetVal Get Current_Radio of oTextFormat to iFormat If (iFormat = C_TEXTFORMAT_FIXEDLENGTH) Begin Get SelectedRowValue to nValue If (nValue = 0) Begin Send UserError "Please enter a length value" Move True to bRetVal End Else Begin If (Integer(nValue) <> nValue) Begin // Check if there are a decimal value. Get SelectedComboRowData of oTextFieldType (&iData) to bRowDataFound If (iData <> C_TEXTFIELDTYPE_NUMERIC) Begin Send UserError "Number of decimals are only allowed for numeric field types." Move True to bRetVal End End End End Function_Return bRetVal End_Function Procedure Prompt Send DoMarkup End_Procedure Function InitialValue Returns String Function_Return "1" End_Function End_Object Object oTextFieldSkip is a cCJGridColumn Set piWidth to 57 Set psCaption to "Skip" Set pbCheckbox to True End_Object Function TextFileStructure Returns tsTextFileStructure tDataSourceRow[] lsData Handle hDataSource Integer iMax iCurrent Integer iNameCol iTypeCol iStartCol iLengthCol iSkipCol tsTextFileStructure lsTextFileStructure Boolean bRowDataFound Get phoDataSource to hDataSource Get DataSource of hDataSource to lsData Move (SizeOfArray(lsData)) to iMax Get piColumnId of oTextFieldName to iNameCol Get piColumnId of oTextFieldType to iTypeCol Get piColumnId of oTextFieldStart to iStartCol Get piColumnId of oTextFieldLength to iLengthCol Get piColumnId of oTextFieldSkip to iSkipCol For iCurrent from 0 to (iMax - 1) Move lsData[iCurrent].sValue[iNameCol] to lsTextFileStructure.lsField[iCurrent].sName Get ComboRowData of oTextFieldType lsData[iCurrent].sValue[iTypeCol] (&lsTextFileStructure.lsField[iCurrent].iType) to bRowDataFound Move lsData[iCurrent].sValue[iStartCol] to lsTextFileStructure.lsField[iCurrent].iStart Move lsData[iCurrent].sValue[iLengthCol] to lsTextFileStructure.lsField[iCurrent].nLength Move lsData[iCurrent].sValue[iSkipCol] to lsTextFileStructure.lsField[iCurrent].bSkip Loop Get Current_Radio of oTextFormat to lsTextFileStructure.iFormat Get SeparatorCharacter of oRowSeparator to lsTextFileStructure.sRowSeparator Get SeparatorCharacter of oFieldSeparator to lsTextFileStructure.sFieldSeparator Get Value of oText to lsTextFileStructure.sTextQualification Get Current_Radio of oCodepage to lsTextFileStructure.iCodePage Get Checked_State of oFirstRow to lsTextFileStructure.bFirstRowHasFieldNames Get Value of oDateFormat to lsTextFileStructure.sDateFormat Get Value of oDateSeparator to lsTextFileStructure.sDateSeparator Get Checked_State of oFourDigitYear to lsTextFileStructure.bFourDigitYear Get Value of oDecimalsign to lsTextFileStructure.sDecimalSign Get psFileName to lsTextFileStructure.sFilename Function_Return lsTextFileStructure End_Function Procedure LoadFileStructure tsTextFileStructure lsTextFileStructure tDataSourceRow[] lsData Integer iMaxTextFields iTextField iNameCol iTypeCol iStartCol iLengthCol iSkipCol Boolean bRowDataFound Get plsTextFileStructure to lsTextFileStructure Get piColumnId of oTextFieldName to iNameCol Get piColumnId of oTextFieldType to iTypeCol Get piColumnId of oTextFieldStart to iStartCol Get piColumnId of oTextFieldLength to iLengthCol Get piColumnId of oTextFieldSkip to iSkipCol Move (SizeOfArray(lsTextFileStructure.lsField)) to iMaxTextFields For iTextField from 0 to (iMaxTextFields - 1) Move lsTextFileStructure.lsField[iTextField].sName to lsData[iTextField].sValue[iNameCol] Get ComboRowCaption of oTextFieldType lsTextFileStructure.lsField[iTextField].iType (&lsData[iTextField].sValue[iTypeCol]) to bRowDataFound Move lsTextFileStructure.lsField[iTextField].iStart to lsData[iTextField].sValue[iStartCol] Move lsTextFileStructure.lsField[iTextField].nLength to lsData[iTextField].sValue[iLengthCol] Move lsTextFileStructure.lsField[iTextField].bSkip to lsData[iTextField].sValue[iSkipCol] Loop Send InitializeData lsData Send MovetoFirstRow Set pbLoadExampleData to True End_Procedure Procedure DoMarkup Integer iStart iLength iFormat String sFilename sName Boolean bOk Boolean bFirstRowHasFieldNames Get Current_Radio of oTextFormat to iFormat If (iFormat = C_TEXTFORMAT_SEPARATED) Begin Procedure_Return End Get SelectedRowValue of oTextFieldStart to iStart Get SelectedRowValue of oTextFieldLength to iLength Get Checked_State of oFirstRow to bFirstRowHasFieldNames Get psFileName to sFilename Get SelectedRowValue of oTextFieldName to sName Get MarkupField of oImportTextFieldMarkup sFilename bFirstRowHasFieldNames (&iStart) (&iLength) (&sName) to bOk If bOk Begin Send UpdateCurrentValue of oTextFieldStart iStart Send UpdateCurrentValue of oTextFieldLength iLength If bFirstRowHasFieldNames Begin Send UpdateCurrentValue of oTextFieldName sName End End End_Procedure End_Object Object oTextBox2 is a Textbox Set Label to "Columns:" Set Location to 2 3 Set Size to 10 30 End_Object Object oFldAdd_bn is a Button Set Label to "Add" Set Location to 105 3 Set peAnchors to anBottomLeft Procedure OnClick Send Request_AppendRow of oFields Send Activate of oFields End_Procedure Procedure Set Enabled_State Integer bState Forward Set Enabled_State to bState Set pbAllowAppendRow of oFields to bState End_Procedure End_Object Object oFldInsert_bn is a Button Set Label to "Insert" Set Location to 105 57 Set peAnchors to anBottomLeft Procedure OnClick Send Request_InsertRow of oFields Send Activate of oFields End_Procedure Procedure Set Enabled_State Integer bState Forward Set Enabled_State to bState Set pbAllowInsertRow of oFields to bState End_Procedure End_Object Object oFldDelete_bn is a Button Set Label to "Delete" Set Location to 105 111 Set peAnchors to anBottomLeft Procedure OnClick Send Request_Delete of oFields Send Activate of oFields End_Procedure Procedure Set Enabled_State Integer bState Forward Set Enabled_State to bState Set pbAllowDeleteRow of oFields to bState End_Procedure End_Object Object oFldRange_bn is a Button Set Location to 105 165 Set Label to "Range" Procedure OnClick Send DoMarkup of oFields Send Activate of oFields End_Procedure End_Object End_Object Object oRefresh_bn is a Button Set Label to "Refresh" Set Location to 296 383 Set peAnchors to anBottomRight Procedure OnClick Set pbPreload to True Set pbLoadExampleData to True End_Procedure End_Object Object oSave is a Button Set Label to "Save definition" Set Size to 14 61 Set Location to 296 3 Set peAnchors to anBottomLeft Procedure OnClick Send DoSaveDefinitionFile of oSaveAsDialog End_Procedure End_Object Object oLoad is a Button Set Label to "Load definition" Set Size to 14 61 Set Location to 296 68 Set peAnchors to anBottomLeft Procedure OnClick Send DoLoadDefinitionFile of oOpenDialog End_Procedure End_Object Object oSaveAsDialog is a SaveAsDialog Set Dialog_Caption to "Save AnyFlex Text Definition file" Set Filter_String to "AnyFlex Text Definition files (*.atd)|*.atd" Procedure DoSaveDefinitionFile String sFilename sDir sImportDefFile sFilenameOnly sExtention Boolean bOk bSaveOk Handle hTextFile tsTextFileStructure lsTextFileStructure Integer iPos Get psFileName to sFilename Get ExtractFilePath sFilename to sDir Get ExtractFileName sFilename to sFilenameOnly Get RemoveExtention of oFilesystem (&sFilenameOnly) to sExtention Move (sFilenameOnly + ".atd") to sImportDefFile Set File_title to sImportDefFile Set Initial_Folder to sDir Get Show_Dialog to bSaveOk If (bSaveOk = True) Begin Get File_Name to sImportDefFile Get TextFileStructure of oFields to lsTextFileStructure Get Create (RefClass(cTextFile)) to hTextFile Set plsTextFileStructure of hTextFile to lsTextFileStructure Get SaveTextFileStructure of hTextFile sImportDefFile to bOk If bOk Begin Send Info_Box "AnyFlex Textfile Definition save ok." "AnyFlex" End Else Begin Send UserError "AnyFlex Textfile Definition save error." "AnyFlex" End Send Destroy of hTextFile End End_Procedure End_Object Object oOpenDialog is a OpenDialog Set Dialog_Caption to "Load AnyFlex Text Definition file" Set Filter_String to "AnyFlex Text Definition files (*.atd)|*.atd" Set CreatePrompt_State to False Set ShowFileTitle_State to True Procedure DoLoadDefinitionFile String sFilename sDir sImportDefFile sFilenameOnly sExtention Boolean bOk bLoadOk Handle hTextFile tsTextFileStructure lsTextFileStructure Integer iPos Get psFileName to sFilename Get ExtractFilePath sFilename to sDir Get ExtractFileName sFilename to sFilenameOnly Get RemoveExtention of oFilesystem (&sFilenameOnly) to sExtention Move (sFilenameOnly + ".atd") to sImportDefFile Set File_title to sImportDefFile Set Initial_Folder to sDir Get Show_Dialog to bLoadOk If (bLoadOk = True) Begin Get File_Name to sImportDefFile Get Create (RefClass(cTextFile)) to hTextFile Get LoadTextFileStructure of hTextFile sImportDefFile to bOk If bOk Begin Get plsTextFileStructure of hTextFile to lsTextFileStructure Set plsTextFileStructure to lsTextFileStructure // Important! Load the header structure first as this clears the field structure. Send LoadFileStructure of oCntHeader // Stop trying to guess the filestructure. Set pbPreload to False // Reset the fields structure as it has now been cleared by LoadFileStructure of oCntHeader Set plsTextFileStructure to lsTextFileStructure Send LoadFileStructure of oFields End Else Begin Send UserError "AnyFlex Textfile Definition load error." "AnyFlex" End Send Destroy of hTextFile End End_Procedure End_Object On_Key kCancel Send KeyAction of oCancel_btn Object oPreloadTextfile is a cTextFile Procedure OnFormatData Integer iColumn String ByRef sData Boolean ByRef bCancel Integer iColumnsLimit Forward Send OnFormatData iColumn (&sData) Get Value of oColumnsLimit to iColumnsLimit If (iColumnsLimit > 0 and iColumn >= iColumnsLimit) Begin Move True to bCancel End End_Procedure End_Object Procedure PreloadTextFile tsTextFileStructure lsTextFileStructure tsTextFileField lsDefaultTextFileField Boolean bOk bEndOfFile bAutoBuildFileStructure String[] sRow Integer iMaxColumn iColumn Move False to bAutoBuildFileStructure Get TextFileStructure of oFields to lsTextFileStructure If (lsTextFileStructure.iFormat = C_TEXTFORMAT_SEPARATED) begin Set plsTextFileStructure of oPreloadTextfile to lsTextFileStructure Get OpenTextFile of oPreloadTextfile to bOk If bOk Begin Get NextTextRow of oPreloadTextfile (&sRow) (&bEndOfFile) to bOk If bOk Begin Move (SizeOfArray(sRow)) to iMaxColumn If (iMaxColumn) Begin Move C_TEXTFIELDTYPE_ASCII to lsDefaultTextFileField.iType Move (ResizeArray(lsTextFileStructure.lsField, iMaxColumn, lsDefaultTextFileField)) to lsTextFileStructure.lsField for iColumn from 0 to (iMaxColumn - 1) If (lsTextFileStructure.bFirstRowHasFieldNames) Begin Move sRow[iColumn] to lsTextFileStructure.lsField[iColumn].sName End Else Begin If (lsTextFileStructure.lsField[iColumn].sName = "") Begin Move (SFormat("Field %1", iColumn + 1)) to lsTextFileStructure.lsField[iColumn].sName End End Loop End Set plsTextFileStructure to lsTextFileStructure End Get CloseTextFile of oPreloadTextfile to bOk End Send LoadFileStructure of oFields End Else Begin If (SizeOfArray(lsTextFileStructure.lsField) = 0) Begin Move C_TEXTFIELDTYPE_ASCII to lsTextFileStructure.lsField[0].iType Move 1 to lsTextFileStructure.lsField[0].iStart Move 500 to lsTextFileStructure.lsField[0].nLength Move "Field 1" to lsTextFileStructure.lsField[0].sName Set plsTextFileStructure to lsTextFileStructure Send LoadFileStructure of oFields End End End_Procedure Object oIdleHandler is a cIdleHandler Procedure OnIdle Boolean bPreload bLoadExampleData Forward Send OnIdle Get pbPreload to bPreload If bPreload Begin Set pbPreload to False Send PreloadTextFile End Get pbLoadExampleData to bLoadExampleData If bLoadExampleData Begin Set pbLoadExampleData to False Send LoadDataExample of oData End End_Procedure End_Object Procedure Activating Forward Send Activating Set pbEnabled of oIdleHandler to True End_Procedure Procedure Deactivating Set pbEnabled of oIdleHandler to False Forward Send DeActivating End_Procedure // Returns true if file structure is accepted. Function MakeTextFileStructure String sTextFile tsTextFileStructure ByRef lsTextFileStructure Returns Boolean Boolean bOk Set psFileName to sTextFile Set Label to (SFormat("Import textfile %1", sTextFile)) Set pbOK to False Set pbPreload to True Send Popup Get pbOK to bOk If bOk Begin Get plsTextFileStructure to lsTextFileStructure End Function_Return bOk End_Function End_Object