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]


Reply via email to