Just starting out? Need help? Post your questions and find answers here.
morosh
Posts: 27 Joined: Mon Feb 02, 2015 7:48 pm
Post
by morosh » Mon Mar 15, 2021 2:48 pm
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
plouf
Posts: 196 Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece
Post
by plouf » Mon Mar 15, 2021 6:40 pm
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"
Christos
morosh
Posts: 27 Joined: Mon Feb 02, 2015 7:48 pm
Post
by morosh » Tue Mar 16, 2021 9:22 am
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.