FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FastReport Error: Workspace not used.
Posts: 243
Joined: Wed Sep 19, 2007 04:32 PM
FastReport Error: Workspace not used.
Posted: Sat Jan 25, 2014 12:42 AM
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 (fw): Select all Collapse
    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

Oscar A. Martinez
http://www.multisofthn.com
Honduras, Centro America
xHarbour Enterprise 1.2.2, Fivewin 13.06
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: FastReport Error: Workspace not used.
Posted: Sun Jan 26, 2014 06:39 AM

Try calling sysrefresh() before closing the database.

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 243
Joined: Wed Sep 19, 2007 04:32 PM
Re: FastReport Error: Workspace not used.
Posted: Mon Jan 27, 2014 03:57 AM

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.

Oscar A. Martinez
http://www.multisofthn.com
Honduras, Centro America
xHarbour Enterprise 1.2.2, Fivewin 13.06
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: FastReport Error: Workspace not used.
Posted: Mon Jan 27, 2014 05:02 PM
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 (fw): Select all Collapse
if ! used()
   // write to log file
else
   // run report
endif


James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: FastReport Error: Workspace not used.
Posted: Mon Jan 27, 2014 05:36 PM
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 (fw): Select all Collapse
// 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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 243
Joined: Wed Sep 19, 2007 04:32 PM
Re: FastReport Error: Workspace not used.
Posted: Thu Jan 30, 2014 02:52 PM

James, Thanks.

I'll try, your suggestion.

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

Oscar A. Martinez
http://www.multisofthn.com
Honduras, Centro America
xHarbour Enterprise 1.2.2, Fivewin 13.06
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: FastReport Error: Workspace not used.
Posted: Fri Jan 31, 2014 03:23 PM

Please let us know if that solves your problem.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion