|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Every example I've seen for accessing databases in C++ Builder uses visual components. What I'd like to do is work with dBase files (*.dbf) in a non-GUI way one record at a time, field by field. Is this doable?
For example, I have several *.dbf's all have the same name and structure, but are stored in separate city directories, C:\Dallas, C:\Detroit, C:\NewYork, etc. I want to create a new database that has some of the fields from each city.dbf and a new CityName field to store the associated city name as I read thru each city.dbf one record at a time and copy the desired field subset. At a lost, any ideas. Yes, I am new to the db features of C++ Builder. So please be kind, Rick ![]() |
|
#2
|
|||
|
|||
|
Okay, my problem was understanding what a TDataSet was. It's a parent class, from which TTable objects are derived. The methods Prior(), Next(), First(), and Last() are inherited from TDataSet and available for use in TTable objects.
I created a GUI form, but loaded it with data-ignorant objects ((other than a TDataSource & a TTable). Rick Sample source code follows: //------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Table1->DatabaseName = "C:\\dBase\\MailCenter\\"; Table1->TableName = "qwiklook.dbf"; Table1->Open(); lblRecordCount->Caption = IntToStr(Table1->RecordCount); lblRecordNumb->Caption = IntToStr(Table1->RecNo); Edit1->Text = Table1->FieldByName("PARTNO")->AsString; Edit2->Text = Table1->FieldByName("NAME")->AsString; Edit3->Text = Table1->FieldByName("DESCRP")->AsString; Edit4->Text = Table1->FieldByName("PRICE")->AsString; } //----------------------------------------------------------- void __fastcall TForm1::btnPriorRecordClick(TObject *Sender) { if (!Table1->Bof) { Table1->Prior(); lblRecordNumb->Caption = IntToStr(Table1->RecNo); Edit1->Text = Table1->FieldByName("PARTNO")->AsString; Edit2->Text = Table1->FieldByName("NAME")->AsString; Edit3->Text = Table1->FieldByName("DESCRP")->AsString; Edit4->Text = Table1->FieldByName("PRICE")->AsString; } } //------------------------------------------------------------- void __fastcall TForm1::btnNextRecordClick(TObject *Sender) { if (!Table1->Eof) { Table1->Next(); lblRecordNumb->Caption = IntToStr(Table1->RecNo); Edit1->Text = Table1->FieldByName("PARTNO")->AsString; Edit2->Text = Table1->FieldByName("NAME")->AsString; Edit3->Text = Table1->FieldByName("DESCRP")->AsString; Edit4->Text = Table1->FieldByName("PRICE")->AsString; } } //----------------------------------------------------------- void __fastcall TForm1::btnFirstRecordClick(TObject *Sender) { if (!Table1->Bof) { Table1->First(); lblRecordNumb->Caption = IntToStr(Table1->RecNo); Edit1->Text = Table1->FieldByName("PARTNO")->AsString; Edit2->Text = Table1->FieldByName("NAME")->AsString; Edit3->Text = Table1->FieldByName("DESCRP")->AsString; Edit4->Text = Table1->FieldByName("PRICE")->AsString; } } //------------------------------------------------------------- void __fastcall TForm1::btnLastRecordClick(TObject *Sender) { if (!Table1->Eof) { Table1->Last(); lblRecordNumb->Caption = IntToStr(Table1->RecNo); Edit1->Text = Table1->FieldByName("PARTNO")->AsString; Edit2->Text = Table1->FieldByName("NAME")->AsString; Edit3->Text = Table1->FieldByName("DESCRP")->AsString; Edit4->Text = Table1->FieldByName("PRICE")->AsString; } } //------------------------------------------------------------- ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Borland C++ Builder and dBase |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|