OK, here is a sample program showing how easy it is to create and use database objects. We are not using TDatabase directly, but rather creating a customer class which inherits from TDatabase. Later I will show you how to create multiple database objects that eliminate repetitive code. -James
/*
Purpose : Sample OOP using TDatabase
Program : Test05.prg
Author : James Bott, <!-- e --><a href="mailto:jbott@compuserve.com">jbott@compuserve.com</a><!-- e -->
Date : 10/04/2018 04:49:55 PM
Company : Intellitech
Copyright: Copyright © 2017 Intellitech. All rights reserved.
Language : Fivewin/xHarbour
Updated :
Notes : Use the customer.dbf in the FWH\samples directory
*/
#include "fivewin.ch"
Function Main()
Local oCustomer
// Houekeeping
REQUEST DBFCDX
rddsetdefault( "DBFCDX" )
SET EXCLUSIVE OFF
SET(_SET_AUTOPEN, .T. )
SET default to ".\"
// Opens the dbf shared
// New workarea is automaticlly selected
// Loads all fields of the first record into an array
// No scatter/gather routines needed
oCustomer:= TCustomer():New()
msgInfo(oCustomer:First)
// Replace the data in the array for this field
oCustomer:First := "Silvio"
// lock record, save buffer, and unlock
// oCustomer:save()
msgInfo(oCustomer:First)
oCustomer:skip()
msgInfo(oCustomer:First)
oCustomer:end()
Return nil
//---------------------------------------------------------------------------//
CLASS TCustomer from TDatabase
Method New()
Endclass
Method New() CLASS TCustomer
Super:New(,"customer","DBFCDX",.t.)
::use()
// Note: Since you are using DBFCDX, the index file is automatically opened
// and the first index is selected and it is at the first record.
Return self
//---------------------------------------------------------------------------//
// EOF