Page 1 of 1

issue with structure of array

Posted: Mon Mar 15, 2021 2:48 pm
by morosh
Hello:
I have problem with structure containing arrays, I can't assign array elements:

Code: Select all

Structure FICH1
  *vt.FICH_PTR
  fnum.b  
  fname.s  
  fnamebrf.s  
  nbart.l
  nbcol.w
  larg.a[50]
  flag.b[50]
  align.s[50]
  title.s[50]
  champ.s[50]
  largtot.l
  start.q
  largmax.a
  txt.s
  nocol_key.a
  nocol_tot1.a
  nocol_tot2.a
  nocol_color.a
  flag_find.a
EndStructure

Global Dim *ptrfich.FICH1(5)

*ptrfich(0)=AllocateMemory(SizeOf(FICH1))

Debug "aa"
*ptrfich(0)\fnum=35
Debug "bb="+Str(*ptrfich(0)\fnum)
*ptrfich(0)\larg[1]=5                   ; hang here
Debug "hh="+Str(*ptrfich(0)\larg[1])    ; nothing displayed
Debug "dd"

the program hang after: *ptrfich(0)\larg[1]=5, what's wrong?

any help is appreciated!

thank you

Re: issue with structure of array

Posted: Mon Mar 15, 2021 6:40 pm
by plouf
whats the reason of the pointer?
also wahts the reason for alocate memory? "dim" has allocate memory
(also dont think is any reason for non long variables since javascript do not support them anyway)

this one works ... if is what you want to do

Code: Select all

Structure FICH1
  *vt.FICH_PTR
  fnum.l
  fname.s 
  fnamebrf.s 
  nbart.l
  nbcol.l
  larg.l[50]
  flag.l[50]
  align.s[50]
  title.s[50]
  champ.s[50]
  largtot.l
  start.l
  largmax.l
  txt.s
  nocol_key.l
  nocol_tot1.l
  nocol_tot2.l
  nocol_color.l
  flag_find.l
EndStructure

Global Dim ptrfich.FICH1(5)

;ptrfich(0)=AllocateMemory(SizeOf(FICH1))

Debug "aa"
ptrfich(0)\fnum=35
Debug "bb="+Str(ptrfich(0)\fnum)
ptrfich(0)\larg[1]=5                   ; hang here
Debug "hh="+Str(ptrfich(0)\larg[1])    ; nothing displayed
Debug "dd"

Re: issue with structure of array

Posted: Tue Mar 16, 2021 9:22 am
by morosh
thanks for reply!
In fact, I'm converting an OOP program made with PB, this is a small extract identifying the problem, I need the pointer.
Dim ptrfich.FICH1(5) allocate memory, but Dim *ptrfich.FICH1(5) don't, it's a pointer.
I just liked to know what's wrong in my previous post.