Use Windows.pkg Use dfCmbFrm.pkg Use dfRadio.pkg Object oFindText_dg is a ModalPanel // Search text dialog for use in AnyFlex // // Author: Wil van Antwerpen // Date: June 27th 2004 // // This dialog allows you to search for any text in the database currently // opened in Anyflex. // It can work for other applications too if you like. // It will search for text supplied and will do so in the datadictionary // object set in the phoAnyflex_DD. // If the text is found then the logic will call the function DoGotoFieldFound // in the invoking object. // Start the find dialog by sending popup to it. // // 1/10 2005 - AKE: Corrected so it is enable to be used on non-recnum tables too. // And makes now use of the current index. Property Integer phoAnyflex_DD Public 0 Property String psFieldNameFound Public "" Property String psSearchText Public "" Property Integer piFieldNumberFound Public 0 Property RowID prwRecordFound Public (NullRowId()) Property Integer phoInvokingObject Public 0 Set Minimize_Icon to FALSE Set Label to "Find Text" Set Location to 2 2 // Visual DataFlex 14.0 Client Size Adjuster, modified May 7, 2008: 13:11:32 // Set Size to 100 222 Set Size to 87 221 // Visual DataFlex 14.0 Client Size Adjuster, modified May 7, 2008: 13:11:32 // Set piMinSize to 104 217 Set piMinSize to 87 216 Object oSearchTextCombo is a ComboForm Set Label to "W&hat:" Set Size to 13 117 Set Location to 13 33 Set Form_Border to 0 Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right // Combo_Fill_List is called when the list needs filling Procedure Combo_Fill_List // Fill the combo list with Send Combo_Add_Item //Send Combo_Add_Item "{item Value 1}" //Send Combo_Add_Item "{item Value 2}" End_Procedure // Combo_Fill_List // notification of a selection change or edit change Procedure OnChange If (Enabled_State(oFindBtn(Self))=False) Begin Set Enabled_State of oFindBtn to True Set Default_State of oFindBtn to True Set Enabled_State of oFindNextBtn to False End // String sValue // // Get Value To sValue // the current selected item End_Procedure // OnChange // notification that the list has dropped down //Procedure OnDropDown //End_Procedure // OnDropDown // notification that the list was closed //Procedure OnCloseUp //End_Procedure // OnCloseUp End_Object // oSearchTextCombo Object oFindBtn is a Button Set Label to "&Find" Set Location to 13 158 Set peAnchors to anBottomRight Set Default_State to TRUE Procedure OnClick Send InitializeResults Send FindFirst End_Procedure // OnClick End_Object // oFindBtn Object oFindNextBtn is a Button Set Label to "Find &Next" Set Location to 36 158 Procedure OnClick Send FindNext End_Procedure // OnClick End_Object // oFindNextBtn Object oMatchCaseCb is a CheckBox Set Label to "Match &Case" Set Size to 10 55 Set Location to 38 8 End_Object // oMatchCaseCb Object oWholeWordsCb is a CheckBox Set Label to "Whole &Words Only" Set Size to 10 76 Set Location to 53 8 // Todo: Not supported yet Set Enabled_State to False End_Object // oWholeWordsCb Object oCancelBtn is a Button Set Label to "C&ancel" Set Location to 58 158 Set peAnchors to anBottomRight Procedure OnClick Send Close_Panel End_Procedure // OnClick End_Object // oCancelBtn Object oDirectionGrp is a RadioGroup Set Size to 44 67 Set Location to 33 83 Set Label to "Search Direction" Object oRadio1 is a Radio Set Label to "Up" Set Size to 10 26 Set Location to 13 5 End_Object // oRadio1 Object oRadio2 is a Radio Set Label to "Down" Set Size to 10 35 Set Location to 28 5 End_Object // oRadio2 Procedure Notify_Select_State Integer iToItem Integer iFromItem Forward Send Notify_Select_State iToItem iFromItem //for augmentation End_Procedure // Notify_Select_State // If you set Current_radio you must set this after the // radio objects have been created AND after Notify_select_State has been // created. i.e. Set in bottom-code at end!! Set Current_Radio to 1 End_Object // oDirectionGrp Object oExactMatchCb is a CheckBox Set Label to "Match &Exactly" Set Size to 10 61 Set Location to 68 8 End_Object // oExactMatchCb On_Key kCancel Send Close_Panel On_Key Key_Alt+Key_h Send AddSearchText On_Key Key_Alt+Key_c Send ToggleCase On_Key Key_Alt+Key_w Send ToggleWholeWordsOnly On_Key Key_Alt+Key_e Send ToggleExactMatch On_Key Key_Alt+key_f Send FindFirst On_Key Key_Alt+Key_n Send FindNext On_Key Key_Alt+Key_a Send Close_Panel Procedure InitializeResults Set psFieldNameFound to "" Set prwRecordFound to (NullRowId()) Set piFieldNumberFound to 0 End_Procedure // InitializeResults Function FindCaseSensitive Returns Integer Function_Return (Checked_State(oMatchCaseCb(Self))) End_Function // FindCaseSensitive Function FindWholeWords Returns Integer Function_Return (Checked_State(oWholeWordsCB(Self))) End_Function // FindWholeWords Function FindExactMatch Returns Integer Function_Return (Checked_State(oExactMatchCB(Self))) End_Function // FindExactMatch Function FindDownwards Returns Integer Function_Return (Current_Radio(oDirectionGrp(Self))=1) End_Function // FindDownwards Procedure AddSearchText Send Activate of oSearchTextCombo End_Procedure // AddSearchText Procedure ToggleCheckBox Integer hoCB Integer bState If (hoCB) Begin Get Checked_State of hoCB to bState Move (not(bState)) to bState Set Checked_State of hoCB to bState End End_Procedure // ToggleCheckBox Procedure ToggleCase Integer hoCB Move (oMatchCaseCb(Self)) to hoCB Send Activate of hoCB Send ToggleCheckBox hoCB End_Procedure // ToggleCase Procedure ToggleWholeWordsOnly Integer hoCB Move (oWholeWordsCB(Self)) to hoCB Send Activate of hoCB Send ToggleCheckBox hoCB End_Procedure // ToggleWholeWordsOnly Procedure ToggleExactMatch Integer hoCB Move (oExactMatchCB(Self)) to hoCB Send Activate of hoCB Send ToggleCheckBox hoCB End_Procedure // ToggleWholeWordsOnly // Set the invoking object and enable/disable the buttons Procedure Popup Integer hoFocus RowID rwFound Move (Focus(Desktop)) to hoFocus Set phoInvokingObject to hoFocus Get prwRecordFound to rwFound If (IsNullRowId(rwFound)) Begin Set Enabled_State of oFindBtn to True Set Default_State of oFindBtn to True Set Enabled_State of oFindNextBtn to False Set Default_State of oFindNextBtn to False End Else Begin Set Enabled_State of oFindBtn to False Set Default_State of oFindBtn to False Set Enabled_State of oFindNextBtn to True Set Default_State of oFindNextBtn to True End Forward Send Popup End_Procedure // Popup Procedure FindFirst Integer iFieldCount iStartField Integer iFile iField iFieldType Integer hoDD Integer iFindMode Boolean bSearchText Boolean bFindCaseSensitive Boolean bFindExactMatch Boolean bTextFound Boolean bFindDown String sFieldData sFieldName String sSearchText RowID rwFound Get Value of oSearchTextCombo to sSearchText Send Combo_Add_Item of oSearchTextCombo sSearchText Get FindCaseSensitive to bFindCaseSensitive If not (bFindCaseSensitive) Begin Move (Uppercase(sSearchText)) to sSearchText End Set psSearchText to sSearchText Get FindExactMatch to bFindExactMatch Get FindDownwards to bFindDown Get phoAnyflex_DD to hoDD If (hoDD) Begin Send DefineAllExtendedFields of hoDD // We need to define extended fields for the search in text option. Get Main_File of hoDD to iFile Move (True) to bSearchText Move (False) to bTextFound If (bFindDown) Move (ge) to iFindMode Else Move (le) to iFindMode //Showln "FTS iFile = " iFile " searchtext = [" sSearchText "]" Get_Attribute DF_FILE_NUMBER_FIELDS of iFile to iFieldCount Get FirstFieldnumber to iStartField Send Request_Clear of hoDD Send Request_Find of hoDD iFindMode iFile -1 While (bSearchText) For iField From iStartField to iFieldCount If not (bTextFound) Begin // We only want to see the first field occurance Get Field_Current_Value of hoDD iField to sFieldData Get_Attribute DF_FIELD_TYPE of iFile iField to iFieldType If (iFieldType <> DF_OVERLAP) Begin If not (bFindCaseSensitive) Begin Move (Uppercase(sFieldData)) to sFieldData End If (bFindExactMatch) Begin Move (sSearchText=sFieldData) to bTextFound End Else Begin Move (Pos(sSearchText,sFieldData)<>0) to bTextFound End //Showln "Searching field " iField " with data <" sFieldData ">" If (bTextFound) Begin Get CurrentRowId of hoDD to rwFound Get_Attribute DF_FIELD_NAME of iFile iField to sFieldName //Showln "Text [" sSearchText "] found in field " sFieldName Set psFieldNameFound to sFieldName Set piFieldNumberFound to iField Set prwRecordFound to rwFound End End // <> DF_OVERLAP End // first occurance Loop // For loop If not (bTextFound) Begin If (bFindDown) Move (gt) to iFindMode Else Move (lt) to iFindMode Send Request_Find of hoDD iFindMode iFile -1 Move (Found) to bSearchText End Else Begin Move (False) to bSearchText End Loop If (bTextFound) Begin Set Enabled_State of oFindNextBtn to True Set Default_State of oFindNextBtn to True Send Activate of oFindNextBtn Set Enabled_State of oFindBtn to False Set Default_State of oFindBtn to False Send Close_Panel Send DoGotoFieldFound of (phoInvokingObject(Self)) End Else Begin Send Info_box "Not found!" End End Else Begin Error 300 "Text Search: no datadictionary has been set." End End_Procedure // FindFirst Procedure FindNext Integer iFieldCount iStartField Integer iFile iField iFieldType Integer hoDD Integer iFindMode Boolean bSearchText Boolean bFindCaseSensitive Boolean bFindExactMatch Boolean bFindDown Boolean bTextFound String sFieldData sFieldName String sSearchText RowID rwFound Get psSearchText to sSearchText Get FindCaseSensitive to bFindCaseSensitive Get FindExactMatch to bFindExactMatch Get FindDownwards to bFindDown If (bFindDown) Move (gt) to iFindMode Else Move (lt) to iFindMode Get phoAnyflex_DD to hoDD If (hoDD) Begin Get Main_File of hoDD to iFile Move (True) to bSearchText Move (False) to bTextFound //Showln "FTS iFile = " iFile " searchtext = [" sSearchText "]" Get_Attribute DF_FILE_NUMBER_FIELDS of iFile to iFieldCount Get FirstFieldnumber to iStartField Send Request_Find of hoDD iFindMode iFile -1 While (bSearchText) For iField From iStartField to iFieldCount If not (bTextFound) Begin // We only want to see the first field occurance Get Field_Current_Value of hoDD iField to sFieldData Get_Attribute DF_FIELD_TYPE of iFile iField to iFieldType If (iFieldType <> DF_OVERLAP) Begin If not (bFindCaseSensitive) Begin Move (Uppercase(sFieldData)) to sFieldData End If (bFindExactMatch) Begin Move (sSearchText=sFieldData) to bTextFound End Else Begin Move (Pos(sSearchText,sFieldData)<>0) to bTextFound End //Showln "Searching field " iField " with data <" sFieldData ">" If (bTextFound) Begin Get CurrentRowId of hoDD to rwFound Get_Attribute DF_FIELD_NAME of iFile iField to sFieldName //Showln "Text [" sSearchText "] found in field " sFieldName Set psFieldNameFound to sFieldName Set piFieldNumberFound to iField Set prwRecordFound to rwFound End End // <> DF_OVERLAP End // first occurance Loop // For loop If not (bTextFound) Begin Send Request_Find of hoDD iFindMode iFile -1 Move (Found) to bSearchText End Else Begin Move (False) to bSearchText End Loop If (bTextFound) Begin Send DoGotoFieldFound to (phoInvokingObject(Self)) End Else Begin Send Info_box "Not found!" End End Else Begin Error 300 "Text Search: no datadictionary has been set." End End_Procedure // FindNext End_Object // oFindText_dg