Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbChr command

Author
Message
Dimension
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 20th Jul 2010 10:23 Edited at: 20th Jul 2010 11:33
I am trying to use this function but for some reason it won't display anything. What am I doing wrong?

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Jul 2010 13:59 Edited at: 20th Jul 2010 14:00
Chr(5) cannot be displayed as there is no symbol for it:


Also, by using it like you are doing you are causing a memory leak. You must always call 'delete[]' on any strings which a GDK function returns, once you have finished using them.

You probably want 'dbStr' not 'dbChr'



[b]
RedFlames
16
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 20th Jul 2010 14:00 Edited at: 20th Jul 2010 14:03
"dbChr()" is the same as the DBP Function "Chr$()" and takes an ASCII-Value as it's argument. You'll have to take a look at the values, for example here:

[Edit: Image is the same as the one in Diggsey's Post]
http://www.papuaweb.org/info/tek/ascii-000-127.gif

(remember that the first column is Decimal, the others are Hex./Oct. The red column is the actual character)

As you can see ASCII-Character Nr. 5 is some control character, not an actual symbol. Numbers "0" through "9" for example would be ASCII-values 48-57, just look up the values in the table if you need a special character.
For example Chr(13) + Chr(10) is a CR+LF (Carriage return + line Feed) which is the standard way to start a new line in a textfile / anywhere else ( equals pressing Enter ) under Windows.

Edit: damn...! cheers Diggsey
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Jul 2010 14:01
lol

[b]
Dimension
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 20th Jul 2010 14:30
"You probably want 'dbStr' not 'dbChr'" thanks for catching that, I been getting a little confused because I've been switching between a few different languages.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 21st Jul 2010 02:05
Quick question.

Would type casting the third parameter in dbText cause a memory leak?

Like so:


http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 21st Jul 2010 11:05 Edited at: 21st Jul 2010 11:11
What it would cause is a crash. By this typecasting you pass a pointer to memory location 65 which contains heaven knows what and your program doesn't have access rights to it anyway, so it will trigger an access violation error.

Converting 65 to a character works only if you pass that value to a char variable (not a char pointer) or if you assign it to one location in a char array, e.g. like this:



To Dimension's original question: the easiest way to display a number on screen in text format is still sprintf with a char array. Then you don't need to worry about deleting the return string and you can insert the number within other text if necessary.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Jul 2010 13:36 Edited at: 21st Jul 2010 13:37
Strings in C++ are simply pointers to an array of characters, terminated by a null character. Hence why they have the type 'char*' (pointer to char).

Each character in the array is a byte specifying the ASCII code of that character. An ASCII code of 0 is a null character.

A pointer is a memory address, so casting 65 to a (char*) will make a pointer pointing to whatever memory is at address 65. This is certainly outside the memory region of you application, and so will cause a crash.

Dealing with arrays can be time consuming, so luckily C++ provides a number of built in functions for dealing with them.
http://www.cplusplus.com/reference/clibrary/cstring/

The easiest thing to do is use the std::string class, which hides all this detail from you. However, you will still need to delete any strings returned by DarkGDK after using them.

Here is a function which will make your life a lot easier:


To use it, add '#include <string>' to the top of your header file, and then paste that code into the header file. It will automatically free any GDK strings after converting them to a std::string.

Whenever you use a GDK function which returns a string, put ToStr() around it. Use std::string for all string variables, and when you need to pass a string to a GDK command, you will need to call 'myVar.c_str()' to convert it back to the type of string which GDK understands.

Example:


Not difficult as long as you remember

[b]

Login to post a reply

Server time is: 2024-07-04 09:26:44
Your offset time is: 2024-07-04 09:26:44