BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

string grids

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
josuha
Guest





PostPosted: Sun Dec 21, 2003 12:25 pm    Post subject: string grids Reply with quote



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





PostPosted: Sun Dec 21, 2003 4:08 pm    Post subject: Re: string grids Reply with quote




"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





PostPosted: Mon Dec 22, 2003 1:35 am    Post subject: Re: string grids Reply with quote




"JD" <nospam (AT) nospam (DOT) com> wrote:
Quote:


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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.