Enrico
What I have done is stored a complete document in a SQL Varchar(max) field .. what that does is stores the data exactically as it was put in .. for example, I have a complete letter with 3 paragraphs of text .. I can store it directly to the field like any other field where cLETTER is that variable that contains the formatted text using Notepad :
- Code: Select all Expand view
DO CASE
CASE cFIELD = "LETTER"
cFILENAME := "LETTER.TXT"
cREAD := cLETTER
IF empty( cREAD ) .or. empty( alltrim( cREAD) )
IF cMODE = "V"
SAYING := "Sorry .. No Letter Text here to View"
MsgInfo( SAYING )
RETURN(.F.)
ENDIF
cREAD := " "
ENDIF
OTHERWISE
RETURN(.F. )
ENDCASE
FERASE( xVOL+"\DBTMP\"+cFILENAME )
nHANDLE := FCREATE( xVOL+"\DBTMP\"+cFILENAME, 0 )
IF FERROR() <> 0
SAYING := "Error Creating file "+(xVOL+"\DBTMP\"+cFILENAME)+CHR(10)
SAYING += "Error "+STR(FERROR())+CHR(10)
MsgInfo( SAYING )
RETURN(.F.)
ENDIF
FWRITE( nHANDLE, cREAD ) // write out the file
FCLOSE( nHANDLE )
SysReFresh()
WAITRUN( "NOTEPAD " + xVOL+"\DBTMP\"+cFILENAME, 1 )
SysReFresh()
cFILE := xVOL+"\DBTMP\"+cFILENAME
// open file //
nHANDLE := FOpen( cFILE )
IF FERROR() <> 0
SAYING := "Error reading file "+cFILE+CHR(10)
SAYING += " "+STR(FERROR())+CHR(10)
FERASE( xVOL+"\DBTMP\"+cFILENAME )
MsgInfo( SAYING )
RETURN(.F.)
ENDIF
// get number of bytes in file
nBYTES := FSEEK( nHANDLE, 0,2 )
// pad the buffer nBytes+1
cBUFFER := SPACE(nBYTES+1)
FSeek( nHANDLE, 0, 0 )
nBytesRead := FRead( nHANDLE, @cBuffer, nBytes )
FClose( nHANDLE )
FERASE( xVOL+"\DBTMP\"+cFILENAME )
SysReFresh()
lOK := .F.
IF cMODE = "V"
ELSE
DO CASE
CASE cFIELD = "LETTER"
IF nBYTESREAD < 2 // blank file
cBUFFER := ""
lLETTER := .F.
lOK := .F.
cLETPROMPT := "LETTER Text [not found]"
oBtn3:cCAPTION := cLETPROMPT
oBtn3:SetColor( "R+/W*" )
oBtn3:ReFresh()
SysReFresh()
ELSE
lLETTER := .T.
lOK := .T.
cLETPROMPT := "LETTER Text [read me]"
oBtn3:cCAPTION := cLETPROMPT
oBtn3:SetColor( "G/W*" )
oBTN3:ReFresh()
SysReFresh()
ENDIF
cLETTER := cBUFFER
OTHERWISE
RETURN(.F. )
ENDCASE
cBUFFER := NIL
ENDIF
RETURN( lOK )
Once the binary data has been stored to cLETTER .. I can write it to the sql table like this oRs:Fields("letter"):Value := cLETTER
Then when I extract the data all I have to do is store the binary data to another variable like cLETTER := oRs:Fields("letter"):Value
NOW, cLETTER contains the complete formatted text just as it was typed in Notepad .. formatted correctly and in three paragraphs... and you can test this and look at the document like :
MsgInfo( cLETTER )
and it will look just like the letter formatted perfectically.
The problem I had was dumping the entire contents of cLETTER to the printer .. SAY and cmSay extract the entire variable and print one continious line on the page and it looks nothing like the document ..
That is why I had to parce up cLETTER into individual lines so I could get the entire document to print each line.
Hope that made sense ??
Thanks
Rick Lipkin