Click here to Skip to main content
15,888,239 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 362K   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

 
GeneralRe: How to add Memo filed? Pin
Member 31190526-May-03 23:29
Member 31190526-May-03 23:29 
GeneralRe: How to add Memo filed? Pin
Alexey27-May-03 0:39
Alexey27-May-03 0:39 
GeneralRe: How to add Memo filed? Pin
Member 31190527-May-03 15:27
Member 31190527-May-03 15:27 
GeneralRe: How to add Memo filed? Pin
Member 31190527-May-03 17:31
Member 31190527-May-03 17:31 
GeneralUpdating .cdx files Pin
gisraelsson22-May-03 4:04
gisraelsson22-May-03 4:04 
GeneralRe: Updating .cdx files Pin
Alexey22-May-03 19:59
Alexey22-May-03 19:59 
Generaladding a memo field in a new table Pin
manito3-May-03 17:59
manito3-May-03 17:59 
GeneralAddNew() memo field Pin
btorrey5-Mar-03 13:02
btorrey5-Mar-03 13:02 
Hi Alexey, Thanks for posting this code. I'm linking the AlxBASE classes as a library in an app I'm writing. I'm trying to AddNew records with a memo field to a dbf/dbt file. When I comment out my code that writes the memo, it works fine. But when I write the memo field to the dbf, I get the pop-up dialog:

Microsoft Visual C++ Debug Library
Debug Assertion Failed!
Program: c:\temp\hqstn.exe
File: dbgheap.c
Line: 1044
Expression: _CrtIsValidHeapPointer(pUserData)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts
(Press Retry to debug the application)
Abort Retry Ignore

**The debug window show:

First-chance exception in HQSTN.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
First-chance exception in HQSTN.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
HEAP[HQSTN.exe]: Heap block at 06641660 modified at 066416C8 past requested size of 60
HEAP[HQSTN.exe]: Invalid Address specified to RtlValidateHeap( 00320000, 06641668 )

**In a try/catch block, my code is basically:
CDBFTableDef myDatabase;
CDatabase sqlDatabase;
CODBCRecordset inputSet(&sqlDatabase);
sqlDatabase.Open(valid params);
inputSet.Open(valid select statement);
outputSet.Open("C:\\data\\email.dbf");
outputSet.AddNew();
outputSet.SetFieldValue(index, inputSet.Field(index));
outputSet.Update();
outputSet.Close();
inputSet.Close();
sqlDatabase.Close();

Any ideas what is causing this?

Thanks,
-Brian

GeneralRe: AddNew() memo field Pin
Alexey6-Mar-03 1:29
Alexey6-Mar-03 1:29 
GeneralRe: AddNew() memo field Pin
btorrey6-Mar-03 5:15
btorrey6-Mar-03 5:15 
GeneralRe: AddNew() memo field Pin
Alexey6-Mar-03 19:27
Alexey6-Mar-03 19:27 
GeneralRe: AddNew() memo field Pin
btorrey11-Mar-03 12:07
btorrey11-Mar-03 12:07 
GeneralRe: AddNew() memo field Pin
Alexey11-Mar-03 19:35
Alexey11-Mar-03 19:35 
GeneralCreating a Memo Field in an existent Table Pin
Crercio O. Silva28-Feb-03 7:46
Crercio O. Silva28-Feb-03 7:46 
GeneralRe: Creating a Memo Field in an existent Table Pin
Alexey2-Mar-03 19:51
Alexey2-Mar-03 19:51 
GeneralRe: Creating a Memo Field in an existent Table Pin
Crercio O. Silva6-Mar-03 3:21
Crercio O. Silva6-Mar-03 3:21 
GeneralCreating a new Table Pin
Crercio O. Silva27-Feb-03 6:42
Crercio O. Silva27-Feb-03 6:42 
GeneralRe: Creating a new Table Pin
Alexey27-Feb-03 19:20
Alexey27-Feb-03 19:20 
GeneralRe: Creating a new Table Pin
Crercio O. Silva28-Feb-03 6:08
Crercio O. Silva28-Feb-03 6:08 
GeneralRe: Creating a new Table Pin
Alexey2-Mar-03 19:38
Alexey2-Mar-03 19:38 
GeneralRe: Creating a new Table Pin
Crercio O. Silva6-Mar-03 2:33
Crercio O. Silva6-Mar-03 2:33 
GeneralRe: Creating a new Table Pin
Alexey6-Mar-03 2:57
Alexey6-Mar-03 2:57 
GeneralALXGrid Not loaded Pin
LinoSaur16-Feb-03 17:48
LinoSaur16-Feb-03 17:48 
GeneralRe: ALXGrid Not loaded Pin
Alexey17-Feb-03 2:39
Alexey17-Feb-03 2:39 
GeneralField Names Pin
PPLouis30-Nov-02 4:30
PPLouis30-Nov-02 4:30 

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.