Board index » cppbuilder » Re: Simple phonebook idea

Re: Simple phonebook idea


2007-11-30 05:08:02 AM
cppbuilder23
"Verne H. Bohlender" < XXXX@XXXXX.COM >wrote:
Quote

Does anyone have a simple phonebook idea using an Access
database and just for only about 5 names total if that?
It's not worth the effort or the overhead. Use a TStringList
which has a LoadFromFile and SaveToFile method. If you format
the data as such:
"Record0 Field0","Record0 Field1","Record0 Field2"
"Record1 Field0","Record1 Field1","Record1 Field2"
......
"Recordn Field0","Recordn Field1","Recordn Field2"
you can use it's CommaText property on a second TStringList to
parse each record. IOW, each string in the first list is the
entire record and after using CommaText, each string in the
second list is a seperate field for a particulare record.
For example:
TStringList *Records = new TStringList;
TStringList *Fields = new TStringList;
Records->LoadFromFile( "some valid name" );
for( int x = 0; x < Records->Count; ++x )
{
Fields->CommaText = Records->Strings[ x ];
for( int y = 0; y < Fields->Count; ++y )
{
ShowMessage( Fields->Strings[y] );
}
}
To build a record as shown above, if you're going to be using
the double quote within any of the text, it needs to be
escaped. The VCL has a native function that will do that for
you. The following is an example of building a list from a
TStringGrid:
//-------------------------------------------------------------
void __fastcall TForm1::GridSaveToFileClick(TObject *Sender)
{
if( SaveDialog1->Execute() )
{
TStringGrid* pGrid = StringGrid1;
char Quote = '"';
TStringList* pList = new TStringList;
for( int Row = pGrid->FixedRows; Row < pGrid->RowCount; ++Row )
{
String tmpString = "";
for( int Col = pGrid->FixedCols; Col < pGrid->ColCount; ++Col )
{
tmpString += AnsiQuotedStr( pGrid->Cells[ Col ][ Row ], Quote );
if( Col < pGrid->ColCount - 1 ) tmpString += ",";
}
pList->Add( tmpString );
}
pList->SaveToFile( SaveDialog1->FileName );
delete pList;
}
}
//-------------------------------------------------------------
And don't forget that TStringList has a Sorted property and a
CustomSort as well where you can provide as many different
sort functions as you like.
~ JD
 
 

Re:Re: Simple phonebook idea

Does anyone have a simple phonebook idea using an Access database
and just for only about 5 names total if that? Something really
simple.
I know how to do the Access bit and a little with VB but would
like to be able to do it with VCL as it does such a nice job.
Please!
Verne
 

Re:Re: Simple phonebook idea

Hi Verne
Verne H. Bohlender says:
Quote
Does anyone have a simple phonebook idea using an Access database
and just for only about 5 names total if that? Something really
simple.

I know how to do the Access bit and a little with VB but would
like to be able to do it with VCL as it does such a nice job.
If it is a database learning project You have going
You might have mor luck in one of the CppBuilde.Database
groups.
Kind regards
Asger
 

{smallsort}