Marc,
OK, I see, you were just trying to update the DBF/DBT file structure to the current format.
I will be interested to hear how your conversion from TSBrowse to XBrowse goes.
James
Marc,
OK, I see, you were just trying to update the DBF/DBT file structure to the current format.
I will be interested to hear how your conversion from TSBrowse to XBrowse goes.
James
DATABASE oDbfklant
REDEFINE GET oDbfklant:Naam_1 ID 110 OF oDlg UPDATE on change oBtn1:enable()
REDEFINE GET oDbfklant:Naam_2 ID 120 OF oDlg UPDATE on change oBtn1:enable()
REDEFINE GET oDbfklant:Straat ID 130 OF oDlg UPDATE on change oBtn1:enable()
REDEFINE GET oDbfklant:Postcode ID 140 OF oDlg UPDATE on change oBtn1:enable()
REDEFINE GET oDbfklant:Gemeente ID 150 OF oDlg UPDATE on change oBtn1:enable()
REDEFINE GET oDbfklant:Tel_nr ID 160 OF oDlg UPDATE on change oBtn1:enable()
REDEFINE GET oDbfklant:Fax_nr ID 170 OF oDlg UPDATE on change oBtn1:enable()
///.....
//and for saving
function endklant(oDbfklant,oDlg)
if oDbfklant:modified()
if msgyesno("Gewijzigde gegevens bewaren")
oDbfklant:save()
If !dial->(dbseek(oDbfklant:tel_nr))
dial->(dbappend())
dial->tel = TrimTelFax(oDbfklant:tel_nr)
dial->firma = oDbfklant:naam_1
dial->code = oDbfklant:klant_nr
dial->type = "K"
dial->toestel = "T"
endif
If !dial->(dbseek(oDbfklant:fax_nr))
dial->(dbappend())
dial->tel = TrimTelFax(oDbfklant:fax_nr)
dial->firma = oDbfklant:naam_1
dial->code = oDbfklant:klant_nr
dial->type = "K"
dial->toestel = "F"
endif
endif
endif
return(.t.)Well, kudos, Marc. I'm glad to see you starting to try OOP.
I like to make the object names as much like real-world names as possible. And I try to make table objects plural so I can use a singular object of the same type later. For instance oCustomers and oCustomer. So, I would suggest for you to use oKlants now so you can use oKlant later. It seems that if you are using oKlants it is obvious that it is a DBF (or table).
And rather than opening the table using conventional syntax, I would create a subclass and open the database and indexes in that as I have shown before in other messages. Then it takes only one line of code to create the table object and if you need to change or add indexes you do that in the class for that object. It is a good rule to write each piece of code only once--not only for less work, but you only have to change it in one place.
oKlants := TKlants():new()
I recently calculated (for some very old code) that I could eliminate over 2000 lines of code that were used for opening files and their indexes, just by converting to database classes.
I am so glad to see you recognize that your function should be a method. And that you see how you can convert a little at a time instead of all or nothing.
Keep at it.
James
The code for changing the oDbfklant:tel_nr and oDbfklant:fax_nr could be changed into a new method from the save()
Class TKants from TDatabase
Method New()
Method Save()
Endclass
Method New()
...
Return Self
Method Save() Class TKants
::super:save() // call the parent save method
// add code to save phone numbers
// add code to save fax numbers
Return nilif msgyesno("Gewijzigde gegevens bewaren")
...
endifoCustomer:=TCustomer():New(cCustNo)
oEditCustomer:=TEditCustomer():New()
oEditCustomer:edit(oCustomer)Class MyBrowse from Xbrowse
Method New()
Method XB_Save()
Endclass
Method xB_save() Class MyBrowse
::super:save() // call the parent save method from xbrowse and let Xbrowse do all it normaly does.
// add code to save phone numbers
// add code to save fax numbers
Return nilMethod New() Class TKlants
::super():New(,"klant") // or whatever the filename is
::use()
::load()
Return self
Method Save() Class TKlants
msgInfo("Save method called")
Return nil oKlants := TKlants():New()
@ 0, 0 XBROWSE oBrw OF oWnd OBJECT oKlants
...function GetMail()
local oInMail
oWnd:SetMsg( "Geting Internet email..." )
oInMail = TPop3():New( "MycIp",110,"MyAccount", "MyPaswoord" ) // mail server IP
oInMail:lHeaderOnly:=.T.
oInMail:lDelMsgs := .F.
oInMail:bConnecting = { || oWnd:SetMsg( "Connecting to 194.224.203.2..." ) }
oInMail:bConnected = { || oWnd:SetMsg( "Connected" ) }
oInMail:bDone = { || ReadEmails( oInMail ) }
oInMail:GetMail()
return nil
//----------------------------------------------------------------------------//
function ReadEmails( oInMail )
local n
MsgInfo( "Total emails: " + Str( Len( oInMail:aMsgs ) ) )
for n = 1 to Len( oInMail:aMsgs )
MsgInfo( oInMail:aMsgs[ n ] )
next
return nil
//----------------------------------------------------------------------------//Marc,
I looked at the TPop3.prg and I don't see any problems with it.
I think the issue is that when you execute the getMail() routine it issues a "quit" when it is done, which is probably disconnecting from the server. Then your getEmails() function is trying to read emails from a disconnected server.
Did you try your browse with a customer class yet?
James
/*
Purpose : Customer class
Program : TKlants.prg
Author : James Bott
Date : 07/20/2017 10:09:18 AM
Company : Intellitech
Copyright:
Language : Fivewin/xHarbour
Updated :
Notes : For Marc Venken
*/
#include "fivewin.ch"
Function Main()
Local oKlants
Field klant_nr, naam_1
REQUEST DBFCDX
rddsetdefault( "DBFCDX" )
SET(_SET_AUTOPEN, .T. )
SET EXCLUSIVE OFF
// Test only
use Klant
index on klant_nr tag "klant_nr" to klant
index on naam_1 tag "naam_1" to klant
use
// End test
oKlants:= TKlants():New()
msgInfo( oKlants:naam_1, "Naam_1")
oKlants:end()
Return nil
//---------------------------------------------------------------------------//
// Customers database class
// Question, do the phone and fax numbers need to be loaded from the dial database?
// If so then a Load() method will also be needed.
Class TKlants from TDatabase
Data oDial
Method New()
Method Save()
Method TrimTelFax()
Method End()
endclass
Method New() Class TKlants
::super:new(,"klant")
::use()
::setOrder(1) // primary key index
::oDial:= TDial():New()
//::setOrder( ? ) // phone number index
Return Self
// Function endKlant made into TKlants:save() method
Method Save() Class TKlants
::super:save()
If ! ::oDial:seek(::tel_nr)
::oDial:append()
::oDial:tel = ::TrimTelFax(::tel_nr)
::oDial:firma = ::naam_1
::oDial:code = ::klant_nr
::oDial:type = "K"
::oDial:toestel = "T"
::oDial:save()
endif
If ! ::oDial:seek(::fax_nr)
::oDial:append()
::oDial:tel := ::TrimTelFax(::fax_nr)
::oDial:firma = ::naam_1
::oDial:code = ::klant_nr
::oDial:type = "K"
::oDial:toestel = "F"
::oDial:save()
endif
Return nil
Method End() Class TKlants
::oDial:close()
::super:close() // Because TDatabase doesn't have an End method
Return nil
Method TrimTelFax(cNumber) Class TKlants
// cNumber := ?
return cNumber
//---------------------------------------------------------------------------//
Class TDial from TDatabase
Method New()
Endclass
Method New() Class TDial
::super():New(,"dial")
::use()
//::setOrder( ? ) // the primary key index
Return self
//---------------------------------------------------------------------------//
// EOFThanks,
Will look into this in a fex days.
Marc