I'm mostly at the end of my rope. I have a cDicObj object that contains a custom udt. I can add it successfully and the first retrieval works. On the second retrieval of the same key, it fails. Nothing happened between the two retrievals.
The object oPageCanvasList is in my class private space as a cDicObj.
Adding code
Private SUB cPDF.CreateCanvas(BYREF uCanvas As PageCanvas)
DIM dv AS DVARIANT
DIM sCanvasID AS DWSTRING
sCanvasID = "C" + FORMAT(oPageCanvasList.Count + 1)
dv.PutBuffer(@uCanvas, SIZEOF(uCanvas))
oPageCanvasList.Add(sCanvasID,dv)
oPageStreamList.Add("")
End Sub
The retrieval code (with some prints so I could see what is going on) is:
Private SUB cPDF.GetCanvas(BYVAL nIndex AS LONG, BYREF uCanvas AS PageCanvas)
DIM dv AS DVARIANT
DIM sCanvasID AS DWSTRING
sCanvasID = "C" + FORMAT(nIndex)
dv = oPageCanvasList.Item(sCanvasID)
print "GetCanvas, ID=" + sCanvasID
dv.ToBuffer(@uCanvas, SIZEOF(uCanvas))
print "Get Canvas Error Info=" + dv.GetErrorInfo(-1)
sleep
End Sub
Running console results:
GetCanvas, ID=C1
Get Canvas Error Info=The operation completed successfully.
Getting Canvas
Width=612
Height=792
LeftMargin=18
TopMargin=18
RightMargin=18
BottomMargin=18
DrawingHeight=756
DrawingWidth=576
Orientation=1
ObjectNumber=0
StreamObject=0
StreamComplete=false
GetCanvas, ID=C1
Get Canvas Error Info=The operation completed successfully.
GetCanvas, ID=C1
Get Canvas Error Info=Error &h80070057
The parameter is incorrect.
What is going on here?
I don't see anything wrong in the posted code, bt I can't test it.
I have made a quick test and it works no matter how many times I call GetUdt.
TYPE Foo
x AS long
y as long
b as WSTRING * 260
END type
' // Creates an instance of the CDicObj class
DIM SHARED pDic AS CDicObj
SUB GetUdt(BYREF tFoo2 AS Foo)
DIM dws AS DWSTRING = "Foo2"
'DIM dws AS DWSTRING = "Foo" + WSTR(2)
'DIM dws AS DWSTRING = "Foo" + FORMAT(2)
DIM dvFoo2 AS DVARIANT
'dvFoo2 = pDic.Item("Foo2")
dvFoo2 = pDic.Item(dws)
dvFoo2.ToBuffer(@tFoo2, SIZEOF(tFoo2))
print dvFoo2.GetErrorInfo(-1)
END SUB
'' // Creates an instance of the Foo type
'DIM t AS Foo = (12345, 72727, "Test string")
'' // Assigns it to a DVARIANT
'DIM dv AS DVARIANT
'dv.PutBuffer(@t, SIZEOF(t))
'' // Adds the type to the dictionary
'pDic.Add "Foo1", dv
' // Creates another instance of the Foo type
DIM t2 AS Foo = (111111, 22222, "Test string 2")
' // Assigns it to a DVARIANT
DIM dv2 AS DVARIANT
dv2.PutBuffer(@t2, SIZEOF(t2))
' // Adds the type to the dictionary
pDic.Add "Foo2", dv2
'' // Gets Foo1 from the dictionary
'DIM dvFoo1 AS DVARIANT
'dvFoo1 = pDic.Item("Foo1")
'' // Assigns it to a DVARIANT
'DIM tFoo1 AS Foo
'dvFoo1.ToBuffer(@tFoo1, SIZEOF(tFoo1))
'print dvFoo1.GetErrorInfo(-1)
'' // DIsplay the values
'print tFoo1.x
'print tFoo1.y
'print tFoo1.b
'' // Gets Foo2 from the dictionary
'DIM dvFoo2 AS DVARIANT
'dvFoo2 = pDic.Item("Foo2")
'' // Assigns it to a DVARIANT
'DIM tFoo2 AS Foo
'dvFoo2.ToBuffer(@tFoo2, SIZEOF(tFoo2))
'print dvFoo2.GetErrorInfo(-1)
'' // DIsplay the values
'print tFoo2.x
'print tFoo2.y
'print tFoo2.b
DIM tFoo2 AS Foo
GetUdt(tFoo2)
print tFoo2.x
print tFoo2.y
print tFoo2.b
tFoo2.x = 0
tFoo2.y = 0
tFoo2.b = ""
print "--------------"
GetUdt(tFoo2)
print tFoo2.x
print tFoo2.y
print tFoo2.b
tFoo2.x = 0
tFoo2.y = 0
tFoo2.b = ""
print "--------------"
GetUdt(tFoo2)
print tFoo2.x
print tFoo2.y
print tFoo2.b
print "--------------"
hi, i tried to follow your sample.
here a flattened type model with your subs.
--> see console output for the repeating calls.
OK: nindex=1 ; NOK: nindex <> 1
error result is then : Error &h80070057
!! SAME AS YOURS
I suppose you are using a nested model ? in a private class space.
( there might some pitfalls , where one could stumble in)
Even in my flat model the 'oPageCanvasList (cdicobj)' has to be static or shared .
I couldn't see in your sample how you did the initialization .
Hope you will succeed.
b.r. Hans (hajubu)
'CdicO_rk_problem
#include once "AfxNova\CdicObj.inc"
USING AFXNOVA
? " ------------ type / class / objects ----------------------"
type PageCanvas
Width as long : Height as long : LeftMargin as long
TopMargin as long : RightMargin as long : BottomMargin as long
DrawingHeight as long : DrawingWidth as long : Orientation as long
ObjectNumber as long : StreamObject as long :StreamComplete as boolean
end type
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim uCanvas as PageCanvas
with uCanvas
.Width=612 : .Height=792 : .LeftMargin=18
.TopMargin=18 : .RightMargin=18 : .BottomMargin=18
.DrawingHeight=756 : .DrawingWidth=576 : .Orientation=1
.ObjectNumber=0 : .StreamObject=0 : .StreamComplete=false
end with
'------------------------------------------------------
declare SUB cPDF_CreateCanvas(BYREF uCanvas As PageCanvas )
declare SUB cPDF_GetCanvas(BYVAL nIndex AS LONG, BYREF uCanvas AS PageCanvas)
dim shared as long i,j = 0: ' helper-vars
? "------start of prolog---(for type + init uvar )----"
With uCanvas
? using " ## - init-var - ucanvas.Height= ##### .... .StreamComplete= &"; _
12; .Height; .StreamComplete
'for j =2 to SIZEOF(uCanvas)/4 -1 : ? "."; : next : ?
End With
? "'dim share' OR 'Static shared' 'uvar as CdicObj'"
Static shared oPageCanvasList as CdicObj
? using "-> oPageCanvasList.count {###}";oPageCanvasList.Count
? !"------end of prolog---------"
'-------------------------------------------------------
Private SUB cPDF_CreateCanvas(BYREF uCanvas As PageCanvas )
DIM dvin AS DVARIANT
DIM sCanvasID AS DWSTRING
? "------------create now -------------------"
? using " sub CanvasList.count { # }";oPageCanvasList.Count
sCanvasID = "C" + str(oPageCanvasList.Count + 1) 'FORMAT()
? using " sCanvasID='C _& count+1 { & }" ; sCanvasID
dvin.PutBuffer(@uCanvas, SIZEOF(uCanvas))
oPageCanvasList.Add(sCanvasID,dvin)
? "------------ created -------------------"
End Sub
'-------------------------------------------------------
Private SUB cPDF_GetCanvas(BYVAL nIndex AS LONG, BYREF uCanvas AS PageCanvas)
DIM dvx AS DVARIANT
DIM sCanvasID AS DWSTRING
i=i+1 : sCanvasID = "C" + str(nIndex) 'Format()
dvx = oPageCanvasList.Item(sCanvasID)
dvx.ToBuffer(@uCanvas, SIZEOF(uCanvas))
? using !"GetCanvas, ID= & with Info(#)= &";sCanvasID;i;dvx.GetErrorInfo(-1)
End Sub
'-----------------------------------------------------
? !"\nscope of oPageCanvasList must be shared/static/ "
cPDF_CreateCanvas(uCanvas )
? "------------getting now -------------------"
? !":first__call" : cPDF_GetCanvas(1,uCanvas)
? !":second__call": cPDF_GetCanvas(1,uCanvas)
'Get Canvas Error Info=Error &h80070057
? !":oth__x__call w. nindex <> 1 -> error &h80070057 - parameter error\n"
? !":oth__3__call w. nindex = 0" : cPDF_GetCanvas(0,uCanvas)
? !":oth__4__call w. nindex = 2" :cPDF_GetCanvas(2,uCanvas)
''-------------------------------------------------------
sleep
'##################console output#################
'------------ type / class / objects ----------------------
'-----start of prolog---(for type + init uvar )----
'12 - init-var - ucanvas.Height= 792 .... .StreamComplete= false
''dim share' OR 'Static shared' 'uvar as CdicObj'
'> oPageCanvasList.count { 0}
'-----end of prolog---------
'
'scope of oPageCanvasList must be shared/static/
'-----------create now -------------------
'sub CanvasList.count { 0 }
'sCanvasID='C & count+1 { C1 }
'----------- created -------------------
'-----------getting now -------------------
':first__call
'GetCanvas, ID= C1 with ErrorInfo(1)= Der Vorgang wurde erfolgreich beendet.
'
':second__call
'GetCanvas, ID= C1 with ErrorInfo(2)= Der Vorgang wurde erfolgreich beendet.
'
':oth__x__call w. nindex <> 1 --> error &h80070057 - generic parameter error
'
':oth__3__call w. nindex = 0
'GetCanvas, ID= C0 with ErrorInfo(3)= Error &h80070057
'Falscher Parameter.
'
':oth__4__call w. nindex = 2
'GetCanvas, ID= C2 with ErrorInfo(4)= Error &h80070057
'Falscher Parameter.
'#####################################
This is the definition in my cPDF class.
Type cPDF Extends Object
Private:
oPageCanvasList AS CDicObj
I tried adding another namespace and defining stuff there without success
Namespace cPDFClassStatic
DIM SHARED oPageCanvasList AS CDicObj
End Namespace
Additionally, I found the same behavior with variable size arrays.
Not sure what is the next step. Far fetched perhaps...have we found a FB bug?
hi,
will trying it later with your 'Namespace-sample' as an inc-file (did now)
1. del line 30 :'Static shared "oPageCanvasList" as CdicObj
2. add as new line 4 :#include ".\rk_cpdf_space.inc
!!! RUNS FINE !!! with sucess for repeated Get_Canvas :: Get Canvas Error Info=The operation completed successfully.
?? NOK: for other then nindex=1 !
::
------------ created -------------------
------------getting now -------------------
:first__call --> GetCanvas, ID= C1 with Info(1)=The operation completed successfully.
:second__call --> GetCanvas, ID= C1 with Info(2)= The operation completed successfully.
:oth__x__call w. nindex <> 1 -> error &h80070057 - parameter error
Get Canvas Error Info=Error &h80070057 --> The parameter is incorrect.
------------------
:::
'rk_cpdf_space.inc
Namespace cPDFClassStatic
DIM SHARED oPageCanvasList AS CDicObj
End Namespace
using cPDFClassStatic
'''''''''''''''''''''''''''''''''''''''
'Namespaces implicitly have public access and this is not modifiable.
'A variable declared inside a namespace is always implicitly static
'and visible throughout the entire program even if the
'declaration modifier Shared is not specified (static and shared are optional,
' but this may improve code readability).
P.S. The sample 'Type cPDF Extends Object' , we cannot use without further complete structure behind.
I assume you are loosing the scope / access of the private declaration :: my hint ->
check for Type(UDT) ( Nested / Named / Anonymous / inheritance :: not initialized !?)
b.r. Hans (Hajubu)
I spent 6 hours looking for scope issues without success. So, I replaced the problematic cDicObj with variable length arrays. There were still some similiar issues so I decided to reorder my declarations and put them all first, and to my surprise, success. I do not know why and now I can begin to actually continue development and begin unit testing my PDF creation class.
Here are the declarations.
Private:
Type PDFPaper
sPaperName AS WSTRING * 30
nPaperHeight AS DOUBLE
nPaperWidth AS DOUBLE
End Type
Type PDFStringID
sStringID AS DWSTRING
sStringText AS DWSTRING
End Type
Type FontIDWidths
sFontID AS DWSTRING
sFontWidths AS DWSTRING
End Type
Type PDFFontID
sFontID AS DWSTRING
uFont AS FontDescriptor
End Type
arPlaceHolder(ANY) AS PlaceHolderText
arCanvas(ANY) AS PageCanvas
arStringID(ANY) AS PDFStringID
arFontID(ANY) AS PDFFontID
arFontWidths(ANY) AS FontIDWidths
hZlib AS HMODULE
pZlibCompress AS FARPROC
nCurrentObjectNumber AS LONG
nDefaultFontSize AS LONG = 12
nDefaultFontColor AS LONG = RGB_BLACK
nBezierMagic AS DOUBLE = ((SQR(2) - 1) / 3) * 4
nPDF_ZOOM AS LONG = PDF_ZOOM_FULLPAGE
nPDF_LAYOUT AS LONG = PDF_LAYOUT_SINGLE
nCurrentPaperID AS LONG = PDF_PAPER_LETTER
nCurrentPaperOrientation AS LONG = PDFPAGE_PORTRAIT
nCurrentWidth AS DOUBLE = 612
nCurrentHeight AS DOUBLE = 792
nCurrentTopMargin AS DOUBLE = PDF_ONE_QUARTER_INCH
nCurrentLeftMargin AS DOUBLE = PDF_ONE_QUARTER_INCH
nCurrentBottomMargin AS DOUBLE = PDF_ONE_QUARTER_INCH
nCurrentRightMargin AS DOUBLE = PDF_ONE_QUARTER_INCH
nPageCharacterSpacing AS DOUBLE = ITEM_IGNORE
nPageWordSpacing AS DOUBLE = ITEM_IGNORE
nPageHorizontalScaling AS WORD = 100
nPageTextLeading AS DOUBLE = ITEM_IGNORE
PI AS DOUBLE = 3.141592653589793
nPageRenderingMode AS LONG = TEXTRENDERING_FILL
nNextStringID AS LONG = 1
nPDF_VIEWER_USE_THUMBNAILS AS LONG = 0
nPDF_VIEWER_HIDEMENUBAR AS LONG = 0
nPDF_VIEWER_HIDETOOLBAR AS LONG = 0
nPDF_VIEWER_SHOWTITLE AS LONG = 0
nPDF_VIEWER_HIDEWINDOWUI AS LONG = 0
nPDF_VIEWER_CENTER_WINDOW AS LONG = 0
nPDF_VIEWER_FIT_WINDOW AS LONG = 0
nTotalFonts AS LONG = 0
CRLF AS DWSTRING = CHR(13, 10)
CR AS DWSTRING = CHR(13)
LF AS DWSTRING = CHR(10)
sPDFStream AS DWSTRING
sTempStream AS DWSTRING
sProducer AS DWSTRING = "cPDF with José Roca AfxNova"
sAuthor AS DWSTRING
sCreator AS DWSTRING
sSubject AS DWSTRING
sTitle AS DWSTRING
sKeywords AS DWSTRING
sDefaultFontID AS DWSTRING = "F1"
sCurrentPaperName AS DWSTRING = "Letter"
oObjectOffsetList AS DVarList
oPageStreamList AS DWStrList
oOutlineList AS DWStrList
oImageDescriptor AS CDicObj
oImageStream AS CDicObj
oPageTextList AS CDicObj
oPageMultiTextList AS CDicObj
oPageRectangleList AS CDicObj
oPageLineList AS CDicObj
oPaperList AS CDicObj