alogrep 0 Posted April 19, 2023 Hi I have an httpserver (synapse), which among other things print a short but rather complex . report. Therefore in the Execute part I have put a Critical section Acquire;/Release block (when rinting is required.) I cannot use a Printer:=Tprinter.create in the Execute block because the report creation and printing functions are used also by external EXE (and I cannot figure out to tell the function for the report to use th Printer created inside the thread or the vcl global Printer when it is called by gh external program). After I print a few times i get this error First chance exception at $75B98FC2. Exception class EAccessViolation with message 'Access violation at address 671A7B65 in module 'madExcept32.dll'. Read of address 8BF455D7'. Process Posserver.exe (2480) Is this an error of madexcept of of my program? And if it is from my program would anybody have an idea as ti what i am doing wrong and how to fix it? I hqve attached the log of the entire error message. log.txt Share this post Link to post
programmerdelphi2k 237 Posted April 20, 2023 I think that "madExcept" is showing that YOUR APP raised an exception in your thread XXXX. Quote Thread Start: Thread ID: 2808. Process Posserver.exe (2480) Process Start: C:\HMXE_A\posserver\fi\Win32\Release\Posserver.exe. for more details, it's necessary see your code. Share this post Link to post
alogrep 0 Posted April 20, 2023 Thcode.txtcode.txtanks. It's quite a long code. I triend to avoid tall unnecessary lines... Share this post Link to post
alogrep 0 Posted April 20, 2023 The problem seems to be that Thread ID: 16172 that I do not now where it comes from IN the log of the Thread.Execute it dows now show (I log every threadId with GetCurrentThreadid()). Thread Start: Thread ID: 980. Process Posserver.exe (13768) Thread Start: Thread ID: 16172. Process Posserver.exe (13768) Thread Exit: Thread ID: 16172. Process Posserver.exe (13768) Module Load: PRNFLDR.dll. No Debug Info. Base Address: $53A00000. Process Posserver.exe (13768) Module Unload: PRNFLDR.dll. Process Posserver.exe (13768) Thread Exit: Thread ID: 980. Process Posserver.exe (13768) First chance exception at $76D98FC2. Exception class EAccessViolation with message 'Acc...... The proper way should be is like this: Thread Start: Thread ID: 812. Process Posserver.exe (13768) Module Load: PRNFLDR.dll. No Debug Info. Base Address: $53A00000. Process Posserver.exe (13768) Module Unload: PRNFLDR.dll. Process Posserver.exe (13768) Thread Exit: Thread ID: 812. Process Posserver.exe (13768) But then that Thread ID: 16172 gets in the way and messes things up. Share this post Link to post
programmerdelphi2k 237 Posted April 20, 2023 @alogrep I didn't understand much of your code, however, I see that you're mixing "thread" with "UI" to expect a response from the print processing of the received data and the user's response, right? I think you shouldn't mix these three tasks, for the simple fact that the thread is an autonomous entity (as if it were another application inside your application), so when you try to interrupt the execution to wait for the response from the print or the user, this can cause a major obstacle in your process. I think you should use the thread to receive the data, only, and, in the "OnTerminate" event, that is, after the task of the thread finished, you could process the other actions: sending the received data to the printer, and, or wait for the user to give some response. This way, your thread will do its job: receiving the data. And in the end, you decide what to do with that data. I think you should better partition your code, that is, better divide the tasks, and not try to do everything in the same procedure. Thus, it will be easier to understand and find a possible problem. I don't know about Synapse so I don't know how to help with it. With regards to choosing or checking which default printer to use, I think you should do it before any processing in the thread or after it, that way you will send extra work. You are creating a new form for the user to make some choices, etc... This should only be done at some point outside the thread, never inside it, because, again, the thread continues to run, however the user is responding to some action on the form. Thread + UI not combined, unless you can "stop/pause" thread processing and then "resume the process", however, you will have to adopt another usage strategy. Normally, you will have to use "TEvent" in your Thread, etc... something a little more complex and needs some more knowledge about this area. Share this post Link to post
alogrep 0 Posted April 20, 2023 I do not do anything that requires user intervention inside the Thread. I guess you were misguided by the "PayForm_UNIT". I named it so for mnemonic reasons, but is a UNIT not a FORM. Anyway I guess I found the problem (I used a printer handle that was freed and not set to NIL). Share this post Link to post