Page 1 of 1

FastReport Error: Workspace not used.

Posted: Sat Jan 25, 2014 12:42 am
by Blessed
Hello forum friends

I think the temporary table in a UDF, generated the report.
After the UDF, I close the table.
Sometimes it shows the error, it is becoming more common, and not know why.

Code: Select all

    LOCAL aStruct  := {  { "FECHA",   "D",  8, 0 }, ;
                         { "DOCNUM",  "C",  8, 0 }, ;
                         { "TDOC",    "C",  3, 0 }, ;
                         { "OBS",     "C", 75, 0 }, ;
                         { "DEBE",    "N", 14, 2 }, ;
                         { "HABER",   "N", 14, 2 }, ;
                         { "SALDO",   "N", 14, 2 }  }
    PUBLIC oFrPrn

    DBCREATE( "TEMP\RC_EDCTA", aStruct, "DBFCDX", .t., "C_EDCTA" ) ; CargarDatosdesdeSQL()
        CrearReporte()
        SELECT C_EDCTA ; USE

        RETURN NIL

FUNCTION CrearReporte()

    SELECT C_EDCTA ; DBGOTOP() 
    AdjReport()
    oFrPrn:LoadFromFile(CurDrive()+":\"+CurDir() +"\REPS\Clientes Estados de Cuenta.fr3")

    oFrPrn:AddVariable("My Vars", "cTitulo", "'" + cTitulo + "'" )
    oFrPrn:AddVariable("My Vars", "cTitCta", "'" + ALLTRIM(cCliente) + "'" )
    oFrPrn:ShowReport()
    
    RETURN NIL

    
FUNCTION AdjReport()

    With Object oFrPrn
        :AddReport()
        :LoadLangRes( CurDrive()+":\"+CurDir() +"\REPS\spanish.xml" )
        :EngineOptions:SetTempDir( CurDrive()+":\"+CurDir()+"\TEMP\" )
        :PreviewOptions:SetModal(.F.)
        :PreviewOptions:SetRemoveReportOnClose(.T.)
        :SetWorkArea( ALIAS(), SELECT() )
    End

RETURN NIL

the Message

Image

Re: FastReport Error: Workspace not used.

Posted: Sun Jan 26, 2014 6:39 am
by James Bott
Try calling sysrefresh() before closing the database.

Re: FastReport Error: Workspace not used.

Posted: Mon Jan 27, 2014 3:57 am
by Blessed
James, thanks for answering

Forgiveness.
The error message occurs when seeing the same report on several occasions.
It's random, sometimes it appears sometimes not.

Re: FastReport Error: Workspace not used.

Posted: Mon Jan 27, 2014 5:02 pm
by James Bott
I understand. This is why I suggested using sysrefresh(). Sometimes a section of code is still running when another one stops.

I don't have much to go on, but it looks like the report is running before the database is visible. If this is the case, then calling sysrefresh() before the report will fix it. Try it as the first line of ClearReporte(). You have nothing to loose.

Or, the database may not be getting opened. You could be trying to generate the same temp file on more than one computer at a time (if this is a multiuser app). [In fact I see that your temp filename is fixed.] So, the second user's temp file doesn't get made. In this case you need to generate temp files with unique names and check to see if they are already existing and if so then generate a new temp name. You can do this by appending a number to the end of the filename, then checking to see if it exists, and if so, then increment the number and try again.

You should also check to make sure the file is opened. You should be doing this before calling the report (frreportmanager()). You can write the result to a log file so you can look at it after the error occurs.

Code: Select all

if ! used()
   // write to log file
else
   // run report
endif
James

Re: FastReport Error: Workspace not used.

Posted: Mon Jan 27, 2014 5:36 pm
by James Bott
Here is my code for generating a temp filename. You may want to change the name from tempFile() to GetTempFile() to be more consistent with other FW functions. You may also want to default to the Windows temp directory instead of the current directory. I used the prefix "AAA" for the filename so it shows at the top of Windows Explorer, thus you can easily see if there are leftover temp files.

You can see from the Clipper reference, how old this is.

James

Code: Select all

// Author: James Bott

#include "fivewin.ch"

function main()
   msgInfo( tempFile( "dbf" ) )
   msgInfo( tempFile( "ntx", getTempDir() ) )
   msgInfo( tempFile( indexExt() ) )
return nil


// Returns an unused filename with cExtension.
// cPath is optional. Defaults to current directory.
FUNCTION tempFile(cExtension,cPath)
   local cFile
   default cPath:=""
   if ! empty(cPath)
      if left(cPath,1) != "\"
          cPath:= cPath + "\"
      endif
   endif
   cExtension:= strtran(cExtension,".","")
   // loop until you find a name that doesn't exist
   do while .t.
      cFile:="AAA"+trim(str(seconds(),5,0))+"."+upper(cExtension)
      cFile:=strtran(cFile," ","0") // fix for hours between 00:00 & 01:00
       if .not. file( cPath + cFile )
         exit
      endif
   enddo
return (cPath + cFile)


#define MAX_PATH 260

// Returns the temp directory
// ( Fixes path returned from getTempPath() )
// Works with (x)Harbour. Won't crash under Clipper,
// but path is not right.
FUNCTION getTempDir()
    LOCAL cDir := SPACE( MAX_PATH )
    GETTEMPPATH( MAX_PATH, cDir )
    cDir = LEFT( cDir, AT( CHR( 0 ), cDir ) - 2 )
RETURN cDir


DLL32 FUNCTION GETTEMPPATH( nBufferLength AS DWORD, cBuffer AS LPSTR ) ;
   AS DWORD;
   PASCAL FROM "GetTempPathA" LIB "kernel32.dll"

// eof

Re: FastReport Error: Workspace not used.

Posted: Thu Jan 30, 2014 2:52 pm
by Blessed
James, Thanks.

I'll try, your suggestion.

In fact it is very interesting how you handle temporary files.

Re: FastReport Error: Workspace not used.

Posted: Fri Jan 31, 2014 3:23 pm
by James Bott
Please let us know if that solves your problem.

Regards,
James