FastReport Error: Workspace not used.

Post Reply
User avatar
Blessed
Posts: 243
Joined: Wed Sep 19, 2007 4:32 pm
Location: Honduras, C.A.
Contact:

FastReport Error: Workspace not used.

Post 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
_ A. Martinez
http://www.multisofthn.com
Honduras, Centro America
xHarbour Enterprise 1.2.2, Fivewin 13.06
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FastReport Error: Workspace not used.

Post by James Bott »

Try calling sysrefresh() before closing the database.
User avatar
Blessed
Posts: 243
Joined: Wed Sep 19, 2007 4:32 pm
Location: Honduras, C.A.
Contact:

Re: FastReport Error: Workspace not used.

Post 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.
_ A. Martinez
http://www.multisofthn.com
Honduras, Centro America
xHarbour Enterprise 1.2.2, Fivewin 13.06
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FastReport Error: Workspace not used.

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FastReport Error: Workspace not used.

Post 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
User avatar
Blessed
Posts: 243
Joined: Wed Sep 19, 2007 4:32 pm
Location: Honduras, C.A.
Contact:

Re: FastReport Error: Workspace not used.

Post by Blessed »

James, Thanks.

I'll try, your suggestion.

In fact it is very interesting how you handle temporary files.
_ A. Martinez
http://www.multisofthn.com
Honduras, Centro America
xHarbour Enterprise 1.2.2, Fivewin 13.06
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FastReport Error: Workspace not used.

Post by James Bott »

Please let us know if that solves your problem.

Regards,
James
Post Reply