Hi,
I'm using LabWindows CVI V5.5 on Windows 98 to read data from a file
into a table. I use the List functions from the programmer's toolbox
to first store all the file data in memory before filling an
appropriate range of cells using the SetTableCellRangeVals function,
because this is much faster than using SetTableCellVal with individual
values from large files. Everything works fine for doubles, but I'm
having problems with strings. If I run the following test code, I get
a repetition of one element of the string array in column 5 as
expected:
ListType CellStrings = ListCreate(sizeof(char) * MAX_STRING_LEN);
....
// code to gather strings from file using ListInsertItem here - this
works
....
// (table already formatted to accept strings)
SetTableCellVal (data_p, DATA_PANEL_TABLE, MakePoint(5, FirstDataRow),
ListGetPtrToItem (CellStrings, 1)); // this works
//The following should fill a range of cells, but I get a general
//protection fault instead...
SetTableCellRangeVals (data_p, DATA_PANEL_TABLE,
MakeRect(FirstDataRow, 5, DataRows, 1), ListGetDataPtr(CellStrings),
VAL_COLUMN_MAJOR);
// The following works but I shouldn't need to do this...
int items = ListNumItems(CellStrings), index, errorflag = FALSE;
char **Buf;
if ((Buf = malloc(items * sizeof(*Buf))) == NULL)
errorflag = TRUE; //memory allocation error
else
for (index = 0; index < items; index++)
if ((Buf[index] = malloc(MAX_STRING_LEN * sizeof(Buf))) == NULL)
errorflag = TRUE; //memory allocation error
else strcpy(Buf[index], ListGetPtrToItem (CellStrings, index));
if (!errorflag )
{
SetTableCellRangeVals (data_p, DATA_PANEL_TABLE,
MakeRect(FirstDataRow, MaxCols, DataRows, 1), Buf, VAL_COLUMN_MAJOR);
....
// other code to free memory and lists here...
}
-------
I've tried casting - (char **) ListGetDataPtr(CellStrings),in the
SetTableCellRangeVals function to avoid having to malloc temporary
storage, but I still get a general protection fault.
Any clarification on the use of ListGetDataPtr with
SetTableCellRangeVals for strings would be appreciated.
Thanks,
John.