Click here to Skip to main content
15,861,125 members
Articles / Desktop Programming / MFC
Article

The alxBase classes for work with DBF files

Rate me:
Please Sign up or sign in to vote.
5.00/5 (22 votes)
5 Nov 20021 min read 358.7K   3.8K   57   106
The alxBase classes for work with dbf files.

Image 1

Introduction

This classes is useful for work with dbf files. The current version supports formats: FoxPro, Visual FoxPro, dBASEIII - dBASE 5.x, Clipper and HiPer-SIx. The memo fields also are supported. CDBFRecordset provides all the useful functions for navigation and modification in table. CDBFCursorset it is possible to use for work only with the selected records. CDBFTableDef it is used for creation and updating of structure of the table.

Create/Update table structure

For creation/updating of structure of the table are available functions:

    <li><code>CreateTable
    
  • ModifyTable
  • AddField
  • InsertField
  • ModifyField
  • MoveField
  • DeleteField
  • UpdateTable

For cancels any pending updates you may call function CanselUpdateTable().

</p>

try
{
	CDBFTableDef mNewTable;
	// begin create
	mNewTable.CreateTable(szFileName);

	// add field
	FIELD_REC FieldRec;
	memset(&FieldRec, 0, sizeof(FIELD_REC));
	memcpy(FieldRec.field_name, szFieldName, 10);
	FieldRec.field_type = FLD_TYPE_CHARACTER;
	FieldRec.len_info.char_len = 20;
	mNewTable.AddField(&FieldRec);

	// ...

	// end create
	mNewTable.UpdateTable();
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Navigation

For navigation are supported functions:

    <li><code>Move
    
  • MoveNext
  • MovePrev
  • MoveFirst
  • MoveLast
  • SetAbsolutePosition

You also may use functions: IsEOF(), IsBOF(),

GetRecordCount()
, GetAbsolutePosition().

try
{
	CDBFRecordset m_Set;
	m_Set.Open("test.dbf");
	while(!m_Set.IsEOF())
	{
		// ...
		m_Set.MoveNext();
	}
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Append/Edit record

For addition, changes of record are functions:

    <li><code>AddNew
    
  • Edit
  • SetFieldValue
  • Delete
  • Undelete
  • Update

You also may use functions: LockRecord(), UnlockRecord(),

GetFieldvalue()
.

try
{
	m_Set.Edit();
	m_Set.SetFieldValue("Key",varKey);
	m_Set.SetFieldValue("NAME",varName);
	m_Set.SetFieldValue("PHONE",varPhone);
	m_Set.Update();
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Find Functions

For find are supported functions:

    <li><code>FindFirst
    
  • FindNext
  • FindLast
  • FindPrev
try
{
	BOOL bFind = m_Set.FindFirst("LIKE('*Club*', NAME)");
	while(bFind)
	{
		// ...
		bFind = m_Set.FindNext();
	}
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Parameter of functions: FindFirst(), FindLast(), ... string expression of dBASE language.

Filter

For the filter SetFilter function is used:

    <li><code>SetFilter
    
try
{
	m_Set.SetFilter("LIKE('*Club*', NAME)");
	m_Set.Requery()
	// ...
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

This function is supported only in classes CDBFCursorset and CDBFMemCursorset.

DBFView Demo

Image 2

This sample shows some opportunities of library alxBASE.

More information about the product can be found at <a href="http: www.alxsoft.narod.ru"="">http://www.alxsoft.narod.ru.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
Year of birth - 1974.
Eeducation - was ended by Kaliningrad State University in 1997.
Now I work as the engineer-programmer in Kaliningrad (RUSSIA).

Comments and Discussions

 
Questionbrought me a great help on lockrecord Pin
markus_20109-Jun-21 2:18
markus_20109-Jun-21 2:18 
QuestionAssertion Failed! Pin
Goa3-Jul-07 7:36
Goa3-Jul-07 7:36 
AnswerRe: Assertion Failed! Pin
Goa4-Jul-07 5:18
Goa4-Jul-07 5:18 
QuestionalxBase without mfc Pin
joviens19-Dec-06 5:44
joviens19-Dec-06 5:44 
AnswerRe: alxBase without mfc Pin
S Mario26-Oct-09 18:08
S Mario26-Oct-09 18:08 
Generalfield content Pin
Joao Araujo21-Jan-06 15:51
Joao Araujo21-Jan-06 15:51 
GeneralDelete records Pin
pgiustinoni7-Jul-05 6:49
pgiustinoni7-Jul-05 6:49 
GeneralGood work But... Pin
ali TEKE11-Apr-05 3:37
ali TEKE11-Apr-05 3:37 
GeneralProblem in adding new records Pin
Mr.V.Stephen29-Jan-05 23:04
Mr.V.Stephen29-Jan-05 23:04 
GeneralRe: Problem in adding new records Pin
EndlessWinter10-Feb-05 16:18
EndlessWinter10-Feb-05 16:18 
GeneralIts really a very nice project Pin
Mr.V.Stephen21-Jan-05 23:37
Mr.V.Stephen21-Jan-05 23:37 
GeneralUsing the FindFirst function Pin
Alex Evans1-Nov-04 11:14
Alex Evans1-Nov-04 11:14 
GeneralRe: Using the FindFirst function Pin
EndlessWinter10-Feb-05 16:23
EndlessWinter10-Feb-05 16:23 
GeneralConverted library for Windos CE Pin
Alex Evans2-Oct-04 21:53
Alex Evans2-Oct-04 21:53 
GeneralUsing this with Windows CE Pin
Alex Evans1-Oct-04 20:51
Alex Evans1-Oct-04 20:51 
GenerallockRecord() Pin
thangoftin29-Aug-04 18:18
thangoftin29-Aug-04 18:18 
GeneralUsing the FindFirst function Pin
Alex Evans1-Nov-04 11:17
Alex Evans1-Nov-04 11:17 
QuestionHow can i insert/update/delete image file? Pin
Mr.Ahn7-Jul-04 1:21
Mr.Ahn7-Jul-04 1:21 
QuestionHow to pack deleted record Pin
simranjeet11-Jun-04 3:08
simranjeet11-Jun-04 3:08 
AnswerRe: How to pack deleted record Pin
Alexey14-Jun-04 19:28
Alexey14-Jun-04 19:28 
QuestionHow to pack deleted record Pin
simranjeet11-Jun-04 3:02
simranjeet11-Jun-04 3:02 
QuestionSample db files? Pin
Huisheng Chen13-Apr-04 15:21
Huisheng Chen13-Apr-04 15:21 
GeneralGreat!! - one question Pin
BlackDice29-Mar-04 3:30
BlackDice29-Mar-04 3:30 
GeneralRe: Great!! - one question Pin
Alexey29-Mar-04 18:33
Alexey29-Mar-04 18:33 
Generalcan't write header info correctly Pin
BlackDice18-Mar-04 7:10
BlackDice18-Mar-04 7:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.