Page 1 of 1

Pointer and PB 5.11

Posted: Thu Jun 13, 2013 10:21 am
by nicolaus
Hi all,

can any one plz help me with the crasy and not BASIC functionality since PB 5.11?
The follow code works very well in PB 5.00, it was easy to understand and it is working.
Since PB 5.11 the follow sample is not longer working. No sample code is showing in the installation folder of PB 5.11 for the new functionality. There is no sample or detailed "how to" in the help file.

I have try to test different combinations in PB 5.11 but nothing is working for me.

So can you show my, based on my sample, how i must change it to bring it up to work in PB 5.11?

Code: Select all

Procedure test_1(*test1.s)
   strTest.s = "Hello"
   *test1 = strTest
EndProcedure
Procedure Test_2()
   Protected myText.s
   myText = Space(1024)
   test_1(@myText)
   Debug myText
EndProcedure

Test_2()
@PB-Team
Please bring samplers for stuff like this with PB installation and also a detailed help sample.

Re: Pointer and PB 5.11

Posted: Thu Jun 13, 2013 11:28 am
by Neil
nicolaus wrote:

Code: Select all

Procedure test_1(*test1.s)
Alexi wrote:Poke it. :D

Code: Select all

Procedure test_1(*test1)
Also note error in Line 1 "Native types can't be used with pointers"

Re: Pointer and PB 5.11

Posted: Thu Jun 13, 2013 11:50 am
by ts-soft
This one works on all versions of pb!

Code: Select all

Procedure test_1(*test1.String)
  strTest.s = "Hello"
  *test1\s = strTest
EndProcedure
Procedure Test_2()
  Protected myText.String
  myText\s = Space(1024)
  test_1(@myText)
  Debug myText\s
EndProcedure

Test_2() 

Re: Pointer and PB 5.11

Posted: Fri Jun 14, 2013 1:42 am
by buddymatkona
Here is another POKE-like option.

Code: Select all

Procedure test_1(*test1)
   strTest.s = "Hello"
   CopyMemory(@strTest, *Test1, StringByteLength(strTest)) ; 
EndProcedure
Procedure Test_2()
   Protected myText.s
   myText = Space(1024)
   test_1(@myText)
   Debug myText
EndProcedure

Test_2()

Re: Pointer and PB 5.11

Posted: Fri Jun 14, 2013 6:25 am
by nicolaus
ts-soft wrote:This one works on all versions of pb!

Code: Select all

Procedure test_1(*test1.String)
  strTest.s = "Hello"
  *test1\s = strTest
EndProcedure
Procedure Test_2()
  Protected myText.String
  myText\s = Space(1024)
  test_1(@myText)
  Debug myText\s
EndProcedure

Test_2() 
Thanks @ts-soft!
i think this change from PB5.00 to PB5.11 is a step back.
In my opinion, this is from BASIC to COMPLEX.

Re: Pointer and PB 5.11

Posted: Fri Jun 14, 2013 6:40 am
by skywalk
I disagree.
As ts-soft said, the structure method would have worked in PB versions going way back before v5.0. Same with Poke().
So, really, it is just a Basic "misunderstanding" given the documentation is not as thorough as this forum. :idea:

Re: Pointer and PB 5.11

Posted: Fri Jun 14, 2013 8:10 am
by helpy
nicolaus wrote:The follow code works very well in PB 5.00, ...
It can be, that the example code works will, but the use of *variable.s sometimes cuase unpredictable results, errors or crash of an program.

Here a little test code:

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_Debugger = #False
	Procedure ErrorHandler()
		MessageRequester("OnError test", "The following error happened: " + ErrorMessage())
	EndProcedure
	OnErrorCall(@ErrorHandler())
CompilerEndIf

Procedure test_1(*test1.s)
	Static count
	Protected strTest.s
	count = count + 1
	strTest.s = "Hello " + RSet(Str(count), 10, "0")
	*test1 = strTest
	ProcedureReturn count
EndProcedure
Procedure Test_2(*test2.s)
	Protected count
	Protected myText.s
	myText = Space(1024)
	count = test_1(@myText)
	*test2 = myText
	ProcedureReturn count
EndProcedure


Define i, test.s, count, sLength

MessageRequester("","TEST START")

sLength = Len( "Hello 0123456789" )
For i = 1 To 1000000
	test.s = Space(1024)
	count = Test_2(@test) 
	; 	Debug test
	If Len(test) <> sLength
		MessageRequester( "", "ERROR at loop " + Str(count) )
		End
	EndIf
Next i

MessageRequester("","TEST DONE")
Results in Windows 8 64 Bit with PureBasic 5.00:
  • PureBasic 5.00 x86 with debugger: wrong result at loop 6
  • PureBasic 5.00 x86 without debugger: wrong result at loop 6
  • PureBasic 5.00 x64 with debugger: program crashes and debugger returns message: "The debugged executable quit unexpectedly"
  • PureBasic 5.00 x64 without debugger: program crashes without any message
Conclusion: The use of *variable.s is leads to unstable programs

cu,
guido