Board index » cppbuilder » Using TStringGrid with user defined class

Using TStringGrid with user defined class


2004-03-02 12:05:26 AM
cppbuilder51
Hello
I'm trying to get a pointer to the data in a TStringGrid into a class. At
the
moment I'm doing it like this but there must be a better way to get the
data in.
My problem is I can't find out the name of the "data" attached to a
TStringGrid
from the Borland documentation.... (I can do this fine with TListBox)
Bill
calling code-----------------
TStringList *TestPoints[50]; // The maximum number of test points on an
Xcel - change code to linked list
memset (TestPoints, '\0', sizeof (TestPoints));
try {
for (int i = 1; i < TestPointList->RowCount; i++) {
TStringList *TestPointDetails = new TStringList;
TestPointDetails->Assign(TestPointList->Rows[i]);
TestPoints[i] = TestPointDetails;
}
FirstIn = CurrResultSet->LoadFromBinary(TestPoints);
if (!FirstIn) {
TStringList **TPptr = &TestPoints[1];
for (int i = 1; i < TestPointList->RowCount; i++) { // This is
part of a BUG see resultset.cpp
TestPointList->Cells[ 2 ][ i ] = (*TPptr)->Strings[ 2 ]; // Date
TestPointList->Cells[ 3 ][ i ] = (*TPptr)->Strings[ 3 ]; // Time
TestPointList->Cells[ 6 ][ i ] = (*TPptr)->Strings[ 6 ]; //
Result
TPptr++;
}
}
class code----------------
int ResultSet::LoadFromBinary (TStringList **TestPointList)
{
// n.b. this doesn't work when the test point list has been
// changed - results are reloaded against wrong test points
// note that the return values are used to indicate whether results
// exist for the sample plan.
char filename[256];
sprintf (filename, "Persist\\%s\\%s\\%s.bin", this->Company, this->Site,
this->SamplePlan);
FILE *fp =fopen (filename, "rb");
if (fp) {
fread (this->FileDate, 10, 1, fp);
fread (this->FileTime, 8, 1, fp);
TStringList **TPptr = &TestPointList[1];
while (*TPptr) {
char Input[32];
fread (Input, 10, 1, fp);
Input[10] = '\0';
(*TPptr)->Strings[2] = Input;
fread (Input=, 8, 1, fp);
Input[8] = '\0';
(*TPptr)->Strings[3] = Input;
fread (Input, 6, 1, fp);
Input[6] = '\0';
(*TPptr)->Strings[6] = Input;
TPptr++;
}
fclose (fp);
return (FALSE);
}
return (TRUE);
}
 
 

Re:Using TStringGrid with user defined class

< XXXX@XXXXX.COM >wrote in message news:opr36xncs8r0xjkd@localhost...
Quote
I'm trying to get a pointer to the data in a TStringGrid into
a class. At the moment I'm doing it like this but there must
be a better way to get the data in.
It is unclear where the problem actually is. What exactly is the problem?
Please clearify.
Quote
TStringList **TPptr = &TestPoints[1];
You don't need to do that, you can access the array directly in your for()
loop:
for(int i = 1; i < TestPointList->RowCount; i++)
{
TestPointList->Cells[ 2 ][ i ] = TestPoints[i]->->Strings[ 2 ]; //
Date
TestPointList->Cells[ 3 ][ i ] = TestPoints[i]->->Strings[ 3 ]; //
Time
TestPointList->Cells[ 6 ][ i ] = TestPoints[i]->->Strings[ 6 ]; //
Result
}
Quote
while (*TPptr) {
I do not recommend you go that approach. If you happen to have 50
TStringList entries in your array,that condition will never succeed, and
worse case scenerio your code will blow up when it tries to access beyond
the array. You should change LoadFromBinary() to accept a second parameter
that indicates the actual number of entries in the array that you are passin
in. That way, the loop knows exactly how many times it needs to execute.
Gambit
 

Re:Using TStringGrid with user defined class

On Mon, 1 Mar 2004 10:46:33 -0800, Remy Lebeau (TeamB)
< XXXX@XXXXX.COM >wrote:
Quote

< XXXX@XXXXX.COM >wrote in message
news:opr36xncs8r0xjkd@localhost...

>I'm trying to get a pointer to the data in a TStringGrid into
>a class. At the moment I'm doing it like this but there must
>be a better way to get the data in.

It is unclear where the problem actually is. What exactly is the
problem?
Please clearify.

My problem is that I am trying to implement a class distinct from the
graphical front
end that carries out my processing. A similar idea is expressed in the
article found at
community.borland.com/article/0,1410,30011,00.html. I can't find
out from the
documentation what class exactly the Cells in a TStringGrid are. This
means I have no
way of accessing them directly in my Instrument class as I can't pass in a
reference
to them. The "not particularly good" approach I took initially was to
Assign them to an
array of TStringList pointers which get edited in the class and them
copied back over the
Cells on return. For an example on a "1 dimensional" drop down list I can
do this -
MeasuringInstrument->TakeMeasure(TestPointList->Rows[TestPointList->Row]);
to get the
details of one line into my class but I don't know how to pass in the "2
dimensional" data
from the TStringGrid.
Quote
>TStringList **TPptr = &TestPoints[1];

You don't need to do that, you can access the array directly in your
for()
loop:

for(int i = 1; i < TestPointList->RowCount; i++)
{
TestPointList->Cells[ 2 ][ i ] = TestPoints[i]->->Strings[ 2 ];
//
Date
TestPointList->Cells[ 3 ][ i ] = TestPoints[i]->->Strings[ 3 ];
//
Time
TestPointList->Cells[ 6 ][ i ] = TestPoints[i]->->Strings[ 6 ];
//
Result
}

>while (*TPptr) {

I do not recommend you go that approach. If you happen to have 50
TStringList entries in your array,that condition will never succeed, and
worse case scenerio your code will blow up when it tries to access beyond
the array. You should change LoadFromBinary() to accept a second
parameter
that indicates the actual number of entries in the array that you are
passin
in. That way, the loop knows exactly how many times it needs to execute.


Gambit


This is true and I intended to correct when the basics are right...
Thanks so far...
Bill
--
Using M2, Opera's revolutionary e-mail client: www.opera.com/m2/
 

{smallsort}

Re:Using TStringGrid with user defined class

< XXXX@XXXXX.COM >wrote in message news:opr38cguzfr0xjkd@localhost...
Quote
I can't find out from the documentation what class exactly the Cells in a
TStringGrid are.
If you look at the VCL documentation and look up the TStringGrid class
itself, you will see a link to its Properties, from which you can then see
that the Cells[][] property is merely an array of AnsiString values:
__property AnsiString Cells[int ACol][int ARow] = {read=GetCells,
write=SetCells};
Quote
The "not particularly good" approach I took initially was to Assign
them to an array of TStringList pointers which get edited in the class
and them copied back over the Cells on return.
You still have not explained what EXACTLY you are trying to accomplish in
general. Please provide more details.
Quote
I don't know how to pass in the "2 dimensional" data from the TStringGrid.
You cannot.
Gambit
 

Re:Using TStringGrid with user defined class

On Tue, 2 Mar 2004 10:48:25 -0800, Remy Lebeau (TeamB)
< XXXX@XXXXX.COM >wrote:
Quote

< XXXX@XXXXX.COM >wrote in message
news:opr38cguzfr0xjkd@localhost...

>I can't find out from the documentation what class exactly the Cells in
>a
TStringGrid are.

If you look at the VCL documentation and look up the TStringGrid class
itself, you will see a link to its Properties, from which you can then
see
that the Cells[][] property is merely an array of AnsiString values:

__property AnsiString Cells[int ACol][int ARow] = {read=GetCells,
write=SetCells};

>The "not particularly good" approach I took initially was to Assign
>them to an array of TStringList pointers which get edited in the class
>and them copied back over the Cells on return.

You still have not explained what EXACTLY you are trying to accomplish in
general. Please provide more details.

I am trying to get at the data that belongs to a graphical display item so
I can use it in a class. Have a look at the article mentoned. I don't
want to select data from a database in the user interface code. I want to
load the user interface with data from a seperate class.
Quote
>I don't know how to pass in the "2 dimensional" data from the
>TStringGrid.

You cannot.
I suspected as much as this has been a feature of almost _every_ 4GL system
I have used. Windows 4GL would let you do this particular thing with it's
ArrayObjects
but other bits of data were "secret".
Quote


Gambit


--
Using M2, Opera's revolutionary e-mail client: www.opera.com/m2/
 

Re:Using TStringGrid with user defined class

< XXXX@XXXXX.COM >wrote in message news:opr4cjiryfr0xjkd@localhost...
Quote
I am trying to get at the data that belongs to a graphical display
item so I can use it in a class. Have a look at the article mentoned.
I don't want to select data from a database in the user interface
code. I want to load the user interface with data from a seperate class.
Then you should be utilizing the TStringGrid's Objects[][] property to
associate user-defined data with each cell, which you can then access in the
OnDrawCell event to help you decide how to draw each cell. Put your
processing into a separate class, and then store dynamic instances into the
Objects[][] property as needed. When the OnDrawCell event is triggered, you
can access the class instance for that cell, query its data, render the cell
however you want, etc.
Gambit