On Thu, 7 Aug 2003 23:46:16 -0700, "Steve K" <[EMAIL PROTECTED]> wrote:
>
>I have read many a posts on this question, however, none seem to be working
>for me. I have attempted to simplify this with no results. I am no longer
>getting fatal exceptions, however nothing is happening.
>
>What is the key ingredient i'm missing here?
>static char* gPlateString =
>"PL3/16x\0PL1/4x\0PL5/16x\0PL3/8x\0PL1/2x\0PL5/8x\0";
The above doesn't work. The compiler knows that dquote strings end with \0
so there is nothing in the .o image after PL3/16x. If you want to do it that
way:
static char gPlateString[]={'P','L','3','/','1','6','x',0,'P'....
Putting this in the resource file as a StringTable would be easier though.
>static char** gListString;
>
>static Boolean PopulateList(void)
>{
> FormType* frmP = FrmGetActiveForm();
> ListType* lstP = (ListType*) FrmGetObjectPtr(frmP, lstDesc);
>
> gListString = (char**) MemPtrNew(StrLen(gPlateString));
No. You have confused/combined two different methods:
With gPlateString re-stated as above, you are prepared
for SysFormPointerArrayToStrings(). This is all you do:
MemHandle h=SysFormPointerArrayToStrings(gPlateList,6);
ErrFatalDisplayIf(h==0,"SysFormPointerArrayToStrings failed");
gListString=MemHandleLock(h);
LstSetListChoices(lstP, gListString,6);
// when you are done with the list, unlock the handle and call MemHandle Free
// SysForm allocated it for you, disposal is your problem
If you are going to allocate yourself:
// this looks more complicated than it really is.
//declare the strings like this instead:
char *gPlateString[] ={"PL3/16x","PL1/4x","PL5/16x","PL3/8x","PL1/2x","PL5/8x"};
...in your function:
char *dst;
int i;
// you can get the count automatically
int cnt=sizeof(gPlateList)/sizeof(char*); //this will be 6
//you have 6 strings in your list
//so you need room for 6 char *
int amt = cnt*sizeof(char*);
//each of the elments is 7 characters long plus the terminating zero total(8)
amt += cnt*8;
gListString= MemPtrNew( amt ); //this is big enough for 6 char* + 6 strings of 7
chars
dst=(char*)(&gListString[cnt]); //point to first byte after the 6th char *
for(i=0; i<cnt; i++){
StrCopy(dst,gPlateString[i]); //copy in the text
gListString[i]=dst; //make gListString[i] point to the copied text
dst+=8; //adjust dst to point to the next byte after the
terminating zero.
//we could useStrLen(dst)+1..I'm just simplifying
}
// when you are done with this list, call MemPtrFree(gListString);
If we pretend that char* uses two bytes(for simplicity), you allocated 12+48=60 bytes
(3C)
Your allocated memory now looks like this (in hex)
>"PL3/16x\0PL1/4x\0PL5/16x\0PL3/8x\0PL1/2x\0PL5/8x\0";
These are the Char *'s (and they point to the data that follows):
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
0 2 4 6 8 A C E
0000: 000C 0014 001C 0024 002C 0034 'PL' '3/'
0010: '16' 'x'0 'PL' '1/' '4x' 0000 'PL' '5/'
0020: '16' 'x'0 'PL' '3/' '8x' 0000 'PL' '1/'
0030: '2x' 0000 'PL' '5/' '8x' 0000
We wasted four bytes by allocating 8 bytes per string
when four of them only had 7...but what the heck. If you
want, you can track the actual string lengths and call
MemPtrResize() with the final tally, but it's not worth the
trouble for a list this small.
> gListString = (char**) SysFormPointerArrayToStrings(gPlateString, 6);
Double No. SysFormPointerArrayToStrings allocates and return a Handle.
See above. Either allocate yourself, or use SysForm...not both
and the Handle that it returns needs to be locked before use in
LstSetListChoices.
>
> LstSetListChoices(lstP, gListString, 6);
> LstDrawList(lstP);
>
> return true;
>}
bullshark
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/