# Test if Close(Report) is SLOW on your System? – Mine 100x slower than C6

**URL:** <https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491>\
**Category:** tips\
**Tags:** report, bugs\
**Created:** [September 22, 2021, 2:35pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491 "2021-09-22T14:35:24Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [September 27, 2021, 9:46pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/21 "2021-09-27T21:46:15Z")

</div>

Tested on an ordinary corporate office network machine and see it taking 37 seconds to close a 1000 pages report. 37 seconds is longgggg time such that the user may think it hung.

It was taking so long I stopped so have to estimate it would take 20 seconds for a 500 page report which is still a long time when waiting.

 ![image](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/8/8c50a3804462a22c8426df37aa3744ef8f8a7b8f.png)

I have been running with this fix for 1+ years so these sites are not seeing these delays. This is an easy fix to make in Legacy and even easier in ABC. See [post #7 above](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/7) for details.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [September 27, 2021, 10:23pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/22 "2021-09-27T22:23:06Z")

</div>

Have you considered all of the people who used to be able to take a potty or coffee break before you came along? 🙂

---

<div class="post-metadata">

**Author:** ![jkuijt](https://clarionhub.com/user_avatar/clarionhub.com/jkuijt/32/6168_2.png) [@jkuijt](https://clarionhub.com/u/jkuijt)\
**Post date:** [September 28, 2021, 1:53pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/23 "2021-09-28T13:53:00Z")

</div>

Hi Carl,

I want to THANK YOU!!

I use the C10 Report Writer Engine DLL (ClaPRLB.dll) to print TXR Reports with a hook to my own previewer and I also noticed a huge delay after closing the Report Previewer window with a report of hundreds of pages. So before the Close (which takes place in EndReport()), I use your ReportCloseTempDeleteAPI, which is ultra fast. I am converting from C6.3 to C10 and in C6.3 everything was fast, so I wondered what was going on in C10. And then I read this article! Thanks again Carl!

```
IF SELF.PagesToPreview <> 0 THEN ReportCloseTempDeleteAPI(PrintPreviewQueue). !Use API DeleteFile that is fast !!!
SELF.EndReport() !must close report before freeing queue
IF SELF.PagesToPreview <> 0 THEN
  FREE(PrintPreviewQueue) !free preview queue
END

```

---

<div class="post-metadata">

**Author:** ![ACochran](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/df788c/32.png) [@ACochran](https://clarionhub.com/u/ACochran)\
**Post date:** [October 6, 2021, 7:06pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/24 "2021-10-06T19:06:46Z")

</div>

Has anybody tried using the DeleteFile call from within a CPCS report? Probably I am doing something wrong. This is a Multi-DLL ABC project. I went thru the steps to and added into one of my CPCS reports but when it gets to the DeleteFile(cWmfName) line, I get the following message: “This program has performed an illegal operation and will now end”. Below is the what I get once I click the Detail button.

## This program has performed an illegal operation and will now end.

Program : C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\UBSSql.exe  
Version : 14.02  
At : 14:03:36 on 2021/10/06  
Workstation: : AlanSurfaceBk2  
User Name: : Alan  
Reported error : EXCEPTION\_ACCESS\_VIOLATION - Error reading data at : 6C14B108h  
Windows : Win 10 , Tablet - 10.0.19043  
Clarion : 0.9  
Thread : 2 Field : 0 Event : 513 Keycode : 0  
Error at address : 06534871h no debug info, Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\UBSRPTS.dll  
Stack Trace  
[01] 06409A96h no debug info, Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\UBSRPTS.dll  
??? 019B7907h Line ?=19 no proc Src=iqxml017.clw Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\IQXML.dll 4.0.1.0  
??? 1307E509h Line ?=246 no proc Src=NetEnc.Clw Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\CLAnet.dll 12.26.0.0  
??? 01640000h Line ?=19 no proc Src=iqxml017.clw Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\IQXML.dll 4.0.1.0  
[02] 010CF9E7h no line number no proc Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 01148D00h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 01129CCEh Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
[03] 010CF4D1h no line number no proc Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 01129CE4h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 01148D00h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 01148D80h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 0113D2BCh Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 0113D2D0h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 0113D2ECh Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 0113D2E0h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 0113D308h Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
??? 0113D2FCh Line ?=47 no proc Src=wxeh.cpp Module=C:\Users\Alan\OneDrive\Apps\C11\UBSSQL\ClaRUN.dll 11.0.13372  
[04] 77B07A9Eh no debug info, Module=C:\WINDOWS\SYSTEM32\ntdll.dll 10.0.19041.1023 (WinBuild.160101.0800)  
[05] 77B07A6Eh no debug info, Module=C:\WINDOWS\SYSTEM32\ntdll.dll 10.0.19041.1023 (WinBuild.160101.0800)

Thanks for any insight on this issue.  
Alan

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [October 6, 2021, 7:11pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/25 "2021-10-06T19:11:42Z")

</div>

> [@ACochran](#):
>
> DeleteFile(cWmfName) line, I get the following message: “This program has performed an illegal operation

Show more code around that DeleteFile. Show the Declaration of cWmfName, it should be a CSTRING. Show the prototype for DeleteFile(). It must have RAW and PASCAL.

---

<div class="post-metadata">

**Author:** ![ACochran](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/df788c/32.png) [@ACochran](https://clarionhub.com/u/ACochran)\
**Post date:** [October 6, 2021, 7:20pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/26 "2021-10-06T19:20:09Z")

</div>

Sorry about that. Like I said, I am likely doing something wrong!!!

In the Declarion Section ! Priority 1300  
MAP  
ReportCloseTempDeleteAPI PROCEDURE(QUEUE RptPreviewQ)

```
  MODULE('API')
    DeleteFile(*CSTRING lpFileName ),BOOL,PROC,RAW,PASCAL,DLL(1),NAME('DeleteFileA') 
  END
END

```

Before calling Close(Report)

ReportCloseTempDeleteAPI(PrintPreviewQueue)  
Close(Report)

In the Local Procedure

ReportCloseTempDeleteAPI PROCEDURE(QUEUE RptPreviewQ)  
QX LONG,AUTO  
cName CSTRING(261),AUTO  
CODE  
LOOP QX=1 TO RECORDS(RptPreviewQ)  
GET(RptPreviewQ,QX)  
cName=CLIP(RptPreviewQ)  
DeleteFile(cName)  
END  
RETURN  
!------------------------------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [October 6, 2021, 8:14pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/28 "2021-10-06T20:14:24Z")

</div>

> [@ACochran](#):
>
> ```auto
> MODULE('API')
> DeleteFile(*CSTRING lpFileName ),BOOL,PROC,RAW,PASCAL,DLL(1),NAME('DeleteFileA') 
> END
> 
> ```

Jeff posted but I think deleted this… The DeleteFile declaration must be in the Global Map i.e. Global embeds

---

<div class="post-metadata">

**Author:** ![ACochran](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/df788c/32.png) [@ACochran](https://clarionhub.com/u/ACochran)\
**Post date:** [October 6, 2021, 8:20pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/29 "2021-10-06T20:20:14Z")

</div>

Got it… Thanks… Will report back if I still am having issues.

---

<div class="post-metadata">

**Author:** ![e\_mano\_e](https://clarionhub.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@e\_mano\_e](https://clarionhub.com/u/e_mano_e)\
**Post date:** [October 12, 2021, 8:18pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/30 "2021-10-12T20:18:32Z")

</div>

Carl,

have you reported this to PTSS?

If the Clarion REMOVE() function is used without the second parameter SV could call API DeleteFileA() instead of the slower API SHFileOperationA().

Jens

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [December 22, 2021, 5:34pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/31 "2021-12-22T17:34:02Z")

</div>

I created a GIST with my FileApiRemove() that can be used to replace calls to the RTL REMOVE(String) function. It calls the API DeleteFile(). It sets the RTL ErrorCode() and Error() so no other code changes are required. This is faster and safer.

```
  MODULE('ClaApi')
        !These Error functions have been in the RTL forever and appear in LibSrc but are not documented
        SetError(LONG ErrNumberToSet),NAME('Cla$SetError'),DLL(DLL_Mode)
        ClearError(),NAME('Cla$ClearError'),DLL(DLL_Mode) 
  END

FileApiRemove FUNCTION(STRING Fn2Delete),LONG,PROC !API Replacement 0=OK else GetLastError(). Can ignore sets RTL ErrorCode()

!===================================================================================================
! FileApiRemove() replacement for Clarion REMOVE() in that it sets the ErrorCode() and Error().
! This also returns the API GetLastError() or Zero for Success
!===================================================================================================  
FileApiRemove FUNCTION (STRING Fn2Delete)!,LONG,PROC !0=ok, else returns Error code, also sets RTL ERRORCODE() ERROR()  
cFN CSTRING(261),AUTO
ApiError LONG !GetLastError() when DeleteFile() fails
ClarionErr LONG !Api Error converted to matching Clarion Error number
    CODE
    cFN=clip(Fn2Delete)
    IF 0=DeleteFile(cFn) THEN !Return 0 = Failed to DeleteFile() see GetLastError() for why
       ApiError=GetlastError()
       IF ~ApiError THEN ApiError=1. !Return says Failed, but no error ... so set something, should never happen
       ClarionErr = ApiError !Most Clarion Error Numbers are the same as API Error Number
       CASE ApiError !Translate some unusual GLE to errors to Clarion 
       OF 32 ; ClarionErr = 52 !API ERROR_SHARING_VIOLATION 32 (0x20) The process cannot access the file because it is being used by another process.
                                        ! Clarion Help says Error 52 = File Already Open - An attempt to OPEN a file that has already been opened by this user.
       END
       SetError(ClarionErr) !Set Error in RTL so caller can use ERRORCODE() just like if used RTL REMOVE()        
    ELSE !non-zero return from DeleteFile() means it worked and file was deleted
       ClearError() !Delete worked set Error to Zero (close) in RTL so caller can use ERRORCODE()
    END    
    RETURN ApiError !Return is Optional (PROC) so caller can check API Error Code if desired
!--------------------------------------------
!Possible enhancement, if fails could Sleep(100) and retry 5 times, file may have 
!just been closed and Virus scanner is looking at it, or OS is catchng up to commit delete
!
!SQLite has notes about exactly this problem. 
! #define MX_DELETION_ATTEMPTS 5 
! do{
! DeleteFileA(zConverted);
! }while( ( ((rc = GetFileAttributesA(zConverted)) != INVALID_FILE_ATTRIBUTES)
! || ((error = GetLastError()) == ERROR_ACCESS_DENIED))
! && (++cnt < MX_DELETION_ATTEMPTS)
! && (Sleep(100), 1) );
!---------------------------------------------

```

> <https://gist.github.com/CarlTBarnes/e5d553a8ffe4287b0e19deac9c432202>

---

<div class="post-metadata">

**Author:** ![FoucheRabie](https://clarionhub.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@FoucheRabie](https://clarionhub.com/u/FoucheRabie)\
**Post date:** [September 12, 2025, 12:55pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/32 "2025-09-12T12:55:28Z")

</div>

> [@ACochran](#):
>
> ```auto
> MODULE('API')
> DeleteFile(*CSTRING lpFileName ),BOOL,PROC,RAW,PASCAL,DLL(1),NAME('DeleteFileA') 
> END
> 
> ```

Thank you Carl,  
Appreciate the !TODO steps.. Works well.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 25, 2026, 7:43pm UTC](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491/33 "2026-08-25T19:43:09Z")

</div>

Tested in the most recent Clarion 12.0.14204 Beta and this Slowness problem is fixed!

Results below now the RTL Close(Report) is a little faster than my workaround to call DeleteFile() first e.g. for 1000 pages 2.28 versus 2.53.

 ![image](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/6/6530e296da9acfa878d15ba8884925136d270862.png)

The last line checked RTL’s `Remove()` is no longer 100x slower. So a simple `Remove('One-File.xxx')` must be calling API `DeleteFile()`. Suppose should be tested for regressions using the 2nd parameter Options and wild cards.

There is new compiler flag `_USTRING_` that can be used to OMIT() the workaround code deleting the files before `Close(Report)`

[Previous page](https://clarionhub.com/t/test-if-close-report-is-slow-on-your-system-mine-100x-slower-than-c6/4491.md?page=1)
