Why wont this work?

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Velvis on Sat Mar 17, 2001 8:32 pm

I am trying to turn on & off bitmaps using an increment/decrement using Ccontrols.
I have 6 bitmaps defined h1-h6.
I have a add button and a subtract button.
I would like to be able to add/remove individually the h1-h6 bitmaps.

heres the code:
temp="h"+(string)counter;// make temp = h1,h2,h3...

When I call Cdraw normally (ie Cdraw(h1); it works fine) but I'd like to have the number part variable so it can automatically draw based on counter. So I assumed converting it to a string would work.
However it never draws the control. (no errors or crashes)

Any ideas?
Posts: 226
Joined: Mon Dec 11, 2000 2:32 am

Postby Vilmos on Sun Mar 18, 2001 12:47 am

Your string will indeed be say h1, but when you CDraw(h1) you are telling it to use the information at the address of a pointer named h1. That information isn't in the string.

An easy way to do what you want is to put all of your variables in an array.

<pre id=code><font face=courier size=2 id=code>
pointer Pictures[6];
then call them from your routine.

</font id=code></pre id=code>

Just access each element of the array as you would an individual Chandle. Remember that a CHandle is just a pointer. All CControls does is define them to be the same thing.

Posts: 174
Joined: Tue Dec 05, 2000 6:13 pm
Location: Canada

Postby Velvis on Sun Mar 18, 2001 11:48 am

Thanks. I knew I was doing it a strange way, thanks for explaining why it didnt work and showing me how to do it correctly. I appreciate it.
Posts: 226
Joined: Mon Dec 11, 2000 2:32 am

Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 2 guests