tdatabase Open or New ? : big doubt

Post Reply
User avatar
Silvio.Falconi
Posts: 7235
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 16 times

tdatabase Open or New ? : big doubt

Post by Silvio.Falconi »

Code: Select all | Expand

 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
User avatar
cnavarro
Posts: 6605
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 6 times
Been thanked: 8 times

Re: tdatabase Open or New ? : big doubt

Post by cnavarro »

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
User avatar
Silvio.Falconi
Posts: 7235
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 16 times

Re: tdatabase Open or New ? : big doubt

Post by Silvio.Falconi »

cnavarro wrote: 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
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

Code: Select all | Expand

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
Post Reply