Page 1 of 1
TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 9:58 am
by jicorral
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: Select all
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)
Re: TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 11:37 am
by jicorral
A workarround:
Code: Select all
__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: Select all
__clsAddMsg(TTxtFile():ClassH, 'AppLine', 'AppendLn', HB_OO_MSG_MESSAGE,, HB_OO_CLSTP_EXPORTED)
Re: TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 12:23 pm
by ukoenig
Code: Select all
// 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
Re: TTxtFile and missing method AppLine
Posted: Wed Mar 11, 2009 3:09 pm
by jicorral
Uwe,
Thx but that doesn't work. SetValue seek the section (OPTIONS) and add the pair label=value. Anyway, know do it:
Code: Select all
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: Select all
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