Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 28th, 2003, 10:51 PM
Rick9845 Rick9845 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Michigan
Posts: 3 Rick9845 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Borland C++ Builder and dBase

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

Reply With Quote
  #2  
Old December 2nd, 2003, 08:13 PM
Rick9845 Rick9845 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Michigan
Posts: 3 Rick9845 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Borland C++ Builder & dBase access

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;
}
}
//-------------------------------------------------------------

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Borland C++ Builder and dBase


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT