cDicObj Issue

Started by Richard Kelly, May 14, 2026, 06:52:33 PM

Previous topic - Next topic

Richard Kelly

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?


José Roca

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 "--------------"

hajubu

#2
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.
'#####################################