 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
josuha Guest
|
Posted: Sun Dec 21, 2003 12:25 pm Post subject: string grids |
|
|
hi all,
anybody mind giving me tips on how do i do this (implement SaveToFile and
LoadFromFile functions in bc++)???
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Sun Dec 21, 2003 4:08 pm Post subject: Re: string grids |
|
|
"josuha" <mc_josh_vx (AT) yahoo (DOT) com> wrote:
| Quote: | [...] how do i do this (implement SaveToFile and LoadFromFile
functions
|
You can't - not directly. The Rows and Columns can be saved /
loaded using SaveToFile and LoadFromFile but on an individual
basis creating a file for each Row or Column.
What you want to do is to create a StringList with each string
representing a single Row of the grid and use SaveToFile and
LoadFromFile with it.
Loading the grid from the StringList is easy. Simply iterate
through the list and assign the string to the Row using
CommaText.
Building the list requires a little more consideration because
the cell may have charaters that CommaText interprets as a
delimeter. To avoid this problem you need to encompass each
cell within double quotes so that a string representing a Row
looks like this:
"Col 1 text","Col 2 text", .... "Last Col text"
The last thing that you need to worry about when building the
string is if there already is a double quote present in the
cell. If you use AnsiQuotedStr, you can handle two birds with
one function (untested):
char Quote = '"';
TStringList* pList = new TStringList;
TStringGrid* pGrid = StringGrid1;
for( int Row = 0; Row < pGrid->RowCount; ++Row )
{
String s = "";
for( int Col = 0; Col < pGrid->ColCount; ++Col )
{
s += AnsiQuotedStr( pGrid->Cells[ Col ][ Row ], Quote );
}
pList->Add( s );
}
pList->SaveToFile( some file );
delete pList;
~ JD
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Mon Dec 22, 2003 1:35 am Post subject: Re: string grids |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote:
I missed adding the comma to seperate the columns in the string.
It should look like this:
char Quote = '"';
TStringList* pList = new TStringList;
TStringGrid* pGrid = StringGrid1;
for( int Row = 0; Row < pGrid->RowCount; ++Row )
{
String s = "";
for( int Col = 0; Col < pGrid->ColCount; ++Col )
{
s += AnsiQuotedStr( pGrid->Cells[ Col ][ Row ], Quote );
// add the following line
if( Col < pGrid->ColCount - 1 ) s += ",";
}
pList->Add( s );
}
pList->SaveToFile( some file );
delete pList;
~ JD
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|