Migrating TDatabase to FWH19.03's from FWH11.08
Posted: Thu May 02, 2019 9:13 am
1. This is my existing code to use dbfs as database objects with unique aliases.
2. The first error I got when trying to upgrade this to Harbour+FWH19.03 is direct assignment to :cFile is no longer allowed. So I tweaked
4. At this point RTE still occur. Now it's because :nArea is 0.
How can I set :nArea without using :SetArea()? I do not wish to use :SetArea() because it assigns :cAlias and :cFile with the same value when in my case it's not.
:cAlias is some randomly generated unique alias name while :cFile is the name of the physical dbf.
TIA
Code: Select all
method activate(cAccnFrom, cAccnTo, dFrom, dCOD, oDbCgl, lPrintable) class XBrwGL
local oldarea := select(), dTo, cStr, a_
local oDlg, oBrw, oFntTitl, oMFont1, oImg, bInit, oSay, oBtnCgl, nWidth, lTaxCodeAlreadyOpened, cTAccn
local aDbfs := { ;
{"oDbHgl", "hgl", "hgl2"}, ;
{"oDbSaleman" , "saleman" , "saleman1"}, ;
{"oDbJnlhis" , "jnlhis", "jnlhis2"} ;
}
cursorWait()
if !OpenODbfs(aDbfs,,self)
select (oldarea)
return nil
endif
//------------------------------------------------------------------------------------
function OpenODbfs(a_, lExcl, o)
/* open dbf with unique alias
a_ must be in the format { {<oDb name>, <dbf name>, <ntx1>, <ntx2>,..., <ntxn>} }
*/
local lRet := .t., i, nlen := len(a_), j
local aOpened := {}, oldarea := select()
default lExcl := .f.
for i := 1 to nLen
if net_use(a_[i,2], lExcl,, cGetNewAlias( 'TDF' ))
aadd(aOpened, select())
if len(a_[i]) > 2
for j := 3 to len(a_[i])
ordListAdd(a_[i,j])
next
set order to 1
endif
o:&(a_[i,1]) := TDataBase():new()
o:&(a_[i,1]):cFile := a_[i,2]
o:&(a_[i,1]):setBuffer(.f.)
else
lRet := .f.
exit
endif
next
// fail? then close those opened so far
if !lRet
aeval(aOpened, {|x| (x)->(dbCloseArea())})
endif
select (oldarea)
return lRet
too:&(a_[i,1]) := TDataBase():new()
o:&(a_[i,1]):cFile := a_[i,2]
3. Then I get other RTE errors. After debugging, I determined it's because :cAlias is empty. So I tweaked the code further too:&(a_[i,1]) := TDataBase():new(,a_[i,2])
Code: Select all
for i := 1 to nLen
cAlias := cGetNewAlias( 'TDF' )
if net_use(a_[i,2], lExcl,, cAlias)
...
o:&(a_[i,1]) := TDataBase():new(cAlias, a_[i,2])
...
endif
next
How can I set :nArea without using :SetArea()? I do not wish to use :SetArea() because it assigns :cAlias and :cFile with the same value when in my case it's not.
:cAlias is some randomly generated unique alias name while :cFile is the name of the physical dbf.
TIA