[EDIT Oct-15-2016]
Now it works, had a fence post problem with comparing memory so changed the comparison to CompareMemory instead of loops anyway this one should finally work and be faster.
[EDIT Oct-12-2016]
My compiler was letting me get away with defining a memory space that was too small. I wonder if it is because my CPU is a XEON ( just blindly throwing darts ).
Thank you @Lord for helping me with this. I installed the same 5.42 LTS version on another computer and I see the memory error @Lord saw.
Anyway this code should work now.
This code should work with Unicode and ASCII for footer and it has the functionality of using "{nb}" or anything as a place holder for pages.
There is one extra step. In order for this procedure to work it has to be moved from its current location before
to after
this is not as bad as it sounds since both procedures are next to each other. This has to be done because
has to be declared so we can use it to test for ASCII font.
This works on Windows 7 64x with PB 5.42 LTS (x64)
here is the code, remember to move this procedure after pdf_init():
Code: Select all
Procedure MEM_DataReplace(*aData.MEM_DataStructure, aSource.s, aDest.s) ; MOVE THIS PROCEDURE TO BE AFTER pdf_Init()
Protected vSourceLen,vDestLen,vCurSize,vMaxSize,vCount,vFind,*tmp,vReturn,i,j,*vaSource
Protected vLen,*vaDest,vaDestString,fontU ; Needed for Unicode to ASCII
;MEM_DataStructure is ASCII so we have play a bit with footer fonts() is declared in pdf_Init(), plan accordingly
fontU= fonts()\unicode ; find out if Unicode or ASCII FONT
vLen = SizeOf(Character) ; find out if Unicode or ASCII program
vSourceLen = StringByteLength(aSource); changed to StringByteLength for Unicode
*vaSource = AllocateMemory(vSourceLen); created a temp buffer for Unicode
If fontU=0
PokeS(*vaSource,aSource,vSourceLen,#PB_String_NoZero|#PB_Ascii); font is ASCII
Else
PokeS(*vaSource,aSource,vSourceLen,#PB_String_NoZero);saved Unicode string to mem to compare mem not string ;
vSourceLen - 1
EndIf
;ShowMemoryViewer(@asource,vSourceLen)
; CallDebugger
; ShowMemoryViewer(*vaSource,vSourceLen)
; CallDebugger
If vlen=1 Or fontU=0
vSourceLen=(vSourceLen/vlen); ASCII font or ASCII program, resize source
EndIf
vDestLen = StringByteLength(aDest) ; changed to StringByteLength
If fontU=0 And vlen=2
vDestLen=(vDestLen/vlen)+1 ;ASCII font Unicode program
EndIf
*vaDest=AllocateMemory(vDestLen)
If fontU=0
PokeS(*vaDest,aDest,vDestLen,#PB_Ascii|#PB_String_NoZero) ; ASCII FONT
Else
PokeS(*vaDest,aDest,vDestLen,#PB_Unicode|#PB_String_NoZero); Unicode
EndIf
vCurSize = *aData\lCursize
vMaxSize = *aData\lMaxsize
vFind = 0
vReturn = #True
If (vDestLen > vSourceLen)
For i = vCurSize To 0 Step -1
vCount= 0
If CompareMemory(*aData\pData + i - vSourceLen,*vaSource,vSourceLen)
vFind = vFind + 1
Break
EndIf
Next
If (vFind > 0)
vReturn = MEM_DataInit(*aData, vMaxSize + (vFind*(vDestLen - vSourceLen))) ; = #False
EndIf
EndIf
If vReturn = #True
*tmp = AllocateMemory((vDestLen + vCurSize) - vSourceLen)
If *tmp
For i = vCurSize To 0 Step -1
If CompareMemory(*aData\pData + i - vSourceLen,*vaSource,vSourceLen)
CopyMemory(*aData\pData + i, *tmp, *aData\lCurSize - i)
CopyMemory(*vaDest, *aData\pData + i - vSourceLen , vDestLen ) ;
CopyMemory(*tmp, *aData\pData + (i-fontU) - vSourceLen + vDestLen, *aData\lCurSize - i) ; COPY according to ASCII or UNICODE font
*aData\lCurSize = *aData\lCurSize + (vDestLen-vSourceLen)
Break
EndIf
Next
FreeMemory(*tmp)
Else
vReturn = #False
EndIf
EndIf
FreeMemory(*vaSource) ; used to search as memory and not string
FreeMemory(*vaDest) ; Temp change to ASCII
ProcedureReturn vReturn
EndProcedure
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari