//TH-Header //***************************************************************************************** // Copyright (c) 2001 Michael Kurz // All rights reserved. // If you want to use this source in your applications conatct: // // $FileName : D:\Entwicklung\SharedClasses\cFDFileReader.pkg // $ProjectName : Codemax // $Author : Michael Kurz // $Created : 14.05.2001 16:44 // // Contents: // Reads the fieldname out of a given *.FD file. //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Use cLineParser.Pkg // is used to Parse the lines of the FD file. Class cFDFileReader Is an Array Procedure Construct_Object Property String psFileName "" Property Integer piSortMode -1 // Not sorting by default. Property Integer piNormalizeEntries false // No normalizing by default. Property Integer piFieldsOnlyState True // Sets: if the file name is removed or not. Object oLineParser Is a cLineParser Set psSepCharacter To " " End_Object End_Procedure // Gets the value with normalized style. // ->All character lowercase only the 1st is uppercase. Function NormalizeEntry String sValue Returns String String sPart1 s1stChar If (Not(piFieldsOnlyState(Self))) Begin Move (Left(sValue,Pos(".",sValue))) To sPart1 Move (Replace(sPart1,sValue,"")) To sValue End Get NormaliseStr sValue To sValue Get NormaliseStr sPart1 To sPart1 //@Move (Lowercase(sValue)) To sValue //@RRS //@Move (Uppercase(Left(sValue,1))) To s1stChar //@RRS //@Move (Overstrike(s1stChar,sValue,1)) To sValue //@RRS Move (sPart1+sValue) To sValue Function_Return sValue End_Function Function NormaliseStr String sStr Returns String String sRet sChr Integer iPos Move (Append(Uppercase(Left(sStr,1)),Lowercase(Right(sStr,Length(sStr)-1)))) To sRet For iPos From 1 To (Length(sRet)) If (Mid(sRet,1,iPos)="_") Begin Increment iPos Move (Uppercase(Mid(sRet,1,iPos))) To sChr Move (Overstrike(sChr,sRet,iPos)) To sRet End Loop Function_Return sRet End_Function // Should fill the object with the FieldNames out of the FD file. Procedure Fill String sFileE String sFile sLine sEntry Integer hoID iLen If NUM_Arguments Gt 0 Set psFileName To sFileE Get psFileName To sFile Direct_Input sFile [seqeof] Begin Error 200 ("Class cFDFileReader: "+sFile+" not found!") Procedure_Return End Move (oLineParser(Self)) To hoID Send Delete_Data Readln sLine // 1st line only contains filename Send ParseLine To hoID sLine Move (Value(hoID,2)) To sFile If (piFieldsOnlyState(Self)) Move "FILE_NUMBER" To sEntry Else Move (sFile+".FILE_NUMBER") To sEntry If (piNormalizeEntries(Self)) Move (NormalizeEntry(Self,sEntry)) To sEntry Move (Length(sFile)) To iLen Set value Item 0 To sEntry Move "" To sEntry Repeat Readln sLine [Not seqeof] Begin Send ParseLine To hoID sLine Get value Of hoID Item 1 To sEntry If (piFieldsOnlyState(Self)) Move (Right(sEntry,Length(sEntry)-iLen-1)) To sEntry If (piNormalizeEntries(Self)) Move (NormalizeEntry(Self,sEntry)) To sEntry Set value Item (Item_Count(Self)) To sEntry End Until [seqeof] If (piSortMode(Self)) Ge 0 Send Sort_Items (piSortMode(Self)) Close_Input End_Procedure // Gets the normalized value. Function NormalizedValue Integer iItem Returns String String sValue Get value Item iItem To sValue Function_Return (NormalizeEntry(Self,sValue)) End_Function Function HasField String sField Returns Boolean Boolean bHasField Integer iItem Integer iCount String sValue Move False To bHasField Move (Lowercase(sField)) To sField Get Item_Count to iCount For iItem From 0 To (iCount-1) Get Value item iItem to sValue If (Lowercase(sValue)=sField) Begin Move True To bHasField Move iCount To iItem End Loop Function_Return bHasField End_Function // Only for testing purposes. Procedure Debug_ShowContents Integer iC For iC From 0 To (Item_Count(Self)-1) Showln iC " " (Value(Self,iC)) End End_Procedure End_Class