Matthew,
You can create a table with the maximum number of columns you'll ever need,
and in the code rearrange column widths. For example:
if (needTwoColumns) {
TblSetColumnWidth (tableP, 0, 79);
TblSetColumnWidth (tableP, 1, 79);
TblSetColumnUsable (tableP, 1, true);
}
else {
TblSetColumnWidth (tableP, 0, 158);
TblSetColumnWidth (tableP, 1, 0);
TblSetColumnUsable (tableP, 1, false);
}
Works without problems for me.
Regards
Bozidar
> -----Original Message-----
> From: Matthew D Moss [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 22, 1999 4:58 AM
> To: Palm-Dev-Forum List
> Subject: Changing number of columns
>
>
> I'd like to change the number of columns in a table dynamically. Since
> there's no API for this, and I can't use Dynamic UI API to create
> tables, I
> thought I'd try something like this:
>
> static void GiveTableColumns(Word numColumns)
> {
> TablePtr table = (TablePtr) GetObjectPtr(MainXTable);
> Err error;
>
> if (!savedOriginal) {
> savedOriginal = true;
> originalAttributes = table->columnAttrs;
> }
> else {
> error = MemPtrFree((VoidPtr) table->columnAttrs);
> ErrNonFatalDisplayIf(error != 0, "can't free table column attrs");
> }
>
> VoidPtr mem = MemPtrNew(numColumns * sizeof(TableColumnAttrType));
> ErrNonFatalDisplayIf(mem == NULL, "can't allocate new memory");
>
> table->columnAttrs = (TableColumnAttrType*) mem;
> MemSet(mem, numColumns * sizeof(TableColumnAttrType), 0);
>
> for (Word c = 0; c < numColumns; c++) {
> TableColumnAttrType& cattr = table->columnAttrs[c];
> cattr.width = 160 / numColumns;
> }
>
> table->numColumns = numColumns;
> if (table->currentColumn >= numColumns)
> table->currentColumn = numColumns-1;
>
> InitTable(table);
> }
>
>
> InitTable() does things like setting item styles, custom draw routines,
> enabling rows & columns, etc. originalAttributes and savedOriginal are
> globals of the proper types, and they are cleaned up when the form closes.
>
> First time this routine is reached, everything works fine. Second attempt
> goes berserk. I've seen font, menu, and bus errors (all in POSE), which
> suggests I'm corrupting something or accessing things I shouldn't.
> Suggestions?
>
> ---- --- -- -
> Matthew D Moss
> [EMAIL PROTECTED]
>
>
>
>