FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TTxtFile and missing method AppLine
Posts: 47
Joined: Thu Jul 10, 2008 07:33 AM
TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 09:58 AM
Reviewing the code of TTxtFile.prg I can't find the method AppLine that is used in the inside the code. Neither the class nor the parent, TFile, has this method.

An example:
Code (fw): Select all Collapse
    oFich := TTxtFile():New('texto.txt', FC_NORMAL)

    if oFich:Open()
        oFich:SetValue('OPTIONS', 'Auto Index', 'Yes')
        oFich:End()
    endif


In runtime I get:

   Called from:  => __ERRRT_SBASE(0)
   Called from: source\rtl\tobject.prg => TTXTFILE:ERROR(0)
   Called from: source\rtl\tobject.prg => (b)HBOBJECT(0)
   Called from: source\rtl\tobject.prg => TTXTFILE:MSGNOTFOUND(0)
   Called from: source\rtl\tobject.prg => TTXTFILE:APPLINE(0)
   Called from: .\source\classes\TTxtFile.PRG => TTXTFILE:SETVALUE(279)
Jorge Ignacio Corral
Enjoy it :)
Posts: 47
Joined: Thu Jul 10, 2008 07:33 AM
Re: TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 11:37 AM
A workarround:

Code (fw): Select all Collapse
__clsAddMsg(TTxtFile():ClassH, 'AppLine', {|o,t| o:AppendLn(t)}, HB_OO_MSG_INLINE,, HB_OO_CLSTP_EXPORTED)


Is there a simpler way to change a class message with other? Something like that:

Code (fw): Select all Collapse
__clsAddMsg(TTxtFile():ClassH, 'AppLine', 'AppendLn', HB_OO_MSG_MESSAGE,, HB_OO_CLSTP_EXPORTED)
Jorge Ignacio Corral
Enjoy it :)
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 12:23 PM
Code (fw): Select all Collapse
// oFich:SetValue('OPTIONS', 'Auto Index', 'Yes')

FUNCTION TEXTNEW()
local aValue := {'OPTIONS', 'Auto Index', 'Yes'}
// If You don't delete the file, the next run will add the text
// can be used to reccord something to a textfile
IF FILE( "texto.txt" )
    DELETE FILE  "texto.txt"
ENDIF

oFich := TTxtFile():New( "texto.txt" )
IF oFich:Open()
   oFich:Add('OPTIONS')
   oFich:Add('Auto Index')
   oFich:Add('Yes') 
   oFich:Add('')  // Append empty line
   // You can use the array as well
   // i := 1
   // For i := 1 To 3
   //      oFich:Add( aValue[i] )
   // Next
ENDIF

RETURN NIL


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 47
Joined: Thu Jul 10, 2008 07:33 AM
Re: TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 03:09 PM
Uwe,

Thx but that doesn't work. SetValue seek the section (OPTIONS) and add the pair label=value. Anyway, know do it:

Code (fw): Select all Collapse
    oFich := TTxtFile():Create(cDir + cNom + FUEPROYEXT, FC_NORMAL)

    if oFich:Open()
        if oFich:Seek('[OPTIONS]', SEEK_FORWARD, SEEK_UPCASE)
        oFich:AppendLn('Auto Index=Yes')
...


I was only reporting a bug in TTxtFile: The method SetValue use the method AppLine that doesn't exist.

Code (fw): Select all Collapse
METHOD SetValue( cSection, cKeyword, xValue ) CLASS TTxtFile

     LOCAL cLine

     ::GoTop()

     IF !::Seek( "[" + cSection + "]" )
          ::AppLine( ""  )
          ::AppLine( "[" + cSection + "]"  )
          ::AppLine( ckeyword + "=" + cValToChar(xValue) )
          RETU NIL
     ENDIF

     cLine := ::cLine

     DO WHILE !::lEof() .AND. !(cLine ="[")
          IF cLine = cKeyword
               ::RepLine( ckeyword + "=" + cValToChar(xValue) )
               RETU NIL
          ENDIF
          ::Advance()
          cLine := ::cLine
     ENDDO

     IF !::lEof()
          ::InsLine( ckeyword + "=" + cValToChar(xValue) )
     ELSE
          ::AppLine( ckeyword + "=" + cValToChar(xValue) )
     ENDIF

RETURN NIL
Jorge Ignacio Corral
Enjoy it :)

Continue the discussion