FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour tdatabase Open or New ? : big doubt
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
tdatabase Open or New ? : big doubt
Posted: Mon Mar 10, 2025 09:48 PM
 METHOD New(  ncArea, cFile, cDriver, lShared, lReadOnly, cPassword )   
   METHOD Open( cAlias, cFile, cDriver, lShared, lReadOnly, cPassword )
when I must use Open and when I must use New ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: tdatabase Open or New ? : big doubt
Posted: Mon Mar 10, 2025 11:30 PM

Dear Silvio

Both methods return Self, so they allow you to create a TDatabase object

If you use New(), and the database is not open, you will have to call the Activate method that opens the file (this method call the Use() method that opens the table)

If you use Open(), it means that the table is not open, so the Open method performs the same functions as New and Activate together

I hope this helps

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: tdatabase Open or New ? : big doubt
Posted: Tue Mar 11, 2025 09:57 AM
cnavarro wrote: Dear Silvio
Both methods return Self, so they allow you to create a TDatabase object
If you use New(), and the database is not open, you will have to call the Activate method that opens the file (this method call the Use() method that opens the table)
If you use Open(), it means that the table is not open, so the Open method performs the same functions as New and Activate together
I hope this helps
I noticed this because in the file where I use to open the tables sometimes I use Open and sometimes I use New, however there is always the USE command example
CLASS TXData from TDatabase
      DATA cDbfPath   init ".\DATA\"  
    ENDCLASS

CLASS TCust from TXData
   METHOD New()
   ENDCLASS

METHOD New( lShared ) CLASS TCust
   Default lShared := .t.
   ::super:New(,::cDbfPath + "customers" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
   RETURN Self
up to now the procedures have not blocked, yesterday I noticed this problem because a dbf would not open for me but it was me who had entered the wrong name
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion