Application exception using iQxml and StringTheory to include a file (C9.1)

Hi all,

I need to embed a PDF within a XML invoice. This works fine for the first time. The second or third time the application crashes with the message:

Exception occurred at address 01ECF153
Exception code C0000005: Access Violation
Process PID=15260  Image: C:\Clarion9\Apps\Pafin\Pafin.exe
Thread 2  Handle=00000494  TID=16764

Exception parameters:
00000000
12AD1000

I suspect I forgot to deallocate memory somewhere?

Regards,
Henk

Here my code:

      st.Start
      LOC:FileName = st.FileNameOnly(pPDF,True)
      st.LoadFile(pPDF)
      st.base64NoWrap = True
      st.Base64Encode()
      XML:CreateParent('ram:AdditionalReferencedDocument')
        XML:AddParent()
        XML:AddElement('ram:IssuerAssignedID',INV:Number)
        XML:AddElement('ram:TypeCode',916)
        XML:AddElement('ram:Name',CLIP(LOC:FileName))
        XML:CreateParent('ram:AttachmentBinaryObject')
        XML:CreateAttribute('filename',CLIP(LOC:FileName))
        XML:CreateAttribute('mimeCode','application/pdf')
        XML:AddParent(True,st.GetValue())
      XML:CloseParent()
      st.Free

And the output (shortened):

<cac:AdditionalDocumentReference>
<cbc:ID>Invoice65006.pdf</cbc:ID>
<cbc:DocumentType>PrimaryImage</cbc:DocumentType>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="application/pdf">JVBERi0xLjMNJeLjz9MNCjEgMCBvYmoNCjw8gvHg</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>

Hi Henk

your exception message does not give much detail so it is hard to know where things went wrong. See this thread:

as mentioned in that thread, use the debug runtime dll and make sure you have compiled all your code in debug mode. You should then be able to see exactly where your code is crashing.

I know a lot about StringTheory but very little about iQxml but will help if I can. Having said that, a while ago I did help Nikola get around a 4MB output string limit by replacing a CSTRING(4096000) with a SringTheory object - see near the end of this topic:

I would suggest using that version of iQxml (if you are not already) - it may or may not be related to your current problem but it could save you grief down the track. Again, make sure you compile it in debug mode.

and one final thing: where you have

  st.base64NoWrap = True
  st.Base64Encode()

change that to

  st.Base64Encode(st:noWrap)

as (at least in vers 3.70 which is the current version) it looks as if the st.base64NoWrap property is not respected in this context. Looking back at earlier versions it was OK in 3.10 but a bug entered in 2019 in vers 3.11 when other options were introduced and it seems no-one has noticed until now!

hth and cheers

Geoff R

#Edit I just fixed that issue in st.Base64Encode() and have sent it off to Bruce for possible inclusion in a future version so if you are reading this some time in the future and have a version > 3.70 that last comment may no longer apply (but the suggested change will still work so best to change it now).

Hi Geoff,

Thanks for debug information. I’m going to work on that.

Regards Henk.

An C0000005: Access Violation would usually indicate an attempt to access memory at Address Zero (or in the first 4 Kb).

This would typically be a Null Pointer. Probably a reference to a &Class or &Queue that did not get NEW.

It worked the first time, then was DISPOSE so Null and not NEW in the 2nd time code. So you did “deallocate” but did not “reallocate”.