Prev: Spinners
Next: Exchange
From: Geoff Schaller on
Woerdie,

Let's try and do this. The following code works for me:

METHOD GenereerArtDbf2(cOutput, cSortGang, cFile) CLASS FacturenBrowse

LOCAL nCurrentRecno AS WORD
LOCAL oWin AS PrintProgress
LOCAL n, y AS WORD
LOCAL aDBStructure AS ARRAY
LOCAL oOutput AS Facturen
LOCAL oFacturen AS Facturen

oFacturen:=Facturen{}
IF !oFacturen:CreateOutputDBF()
// report an error creating the DBF and take evasive action
ENDIF
oFacturen:Close() // but you don't have to if you need to use the
data...

oOutput:=Facturen{"OUTPUT"} // Open the DBF
// use oOutput
oOutput:Close()

RETURN NIL

METHOD CreateOutputDBF() CLASS Facturen

LOCAL aStruct AS ARRAY
LOCAL lReturn AS LOGIC

aStruct := SELF:DBFStructure

// create a new DBF with the same structure but different name
lReturn :=
DBCREATE("OUTPUT",aStruct,"BDBFCDX",TRUE,__UniqueAlias("OUTPUT"))

DBCLOSEAREA() // flush to disk and close

RETURN lReturn



Now let's get one thing clear first: you have a DBServer class generated
with the DBServer editor... yes? Good. Because of this, we can use that
class for the input and output DBF in our code. We just pass the name of
the DBF (NOT NOT PASS .DBF WITH THIS NAME) to the instantiation clause
and it will pick up the correct DBF. I have not passed in the working
folder path with the name but of course you can do this too.

You can also create an output class to use like this:

CLASS OutputFacturen INHERIT Facturen

Now it will work.

Cheers,

Geoff



From: Stephen Quinn on
Woerdie

> DBCREATE(oSystem:Workdir +
> "\FACTUREN.DBF",aDBStructure,"DBFCDX",true,"oOutput")

You do realise that hardcoding a TEMP filename will cause you headaches with
multiple users don't you.
User 2 won't be able to create the file because User 1 is using it (unless
it's a single User app!)

Use a temp filename for temporary DBFs, delete DBF when finished with.

CYA
Steve


From: Woerdie on
On 3 apr, 01:50, "Geoff Schaller" <geo...(a)softxwareobjectives.com.au>
wrote:
> Woerdie,
>
> Let's try and do this. The following code works for me:
>
> METHOD GenereerArtDbf2(cOutput, cSortGang, cFile) CLASS FacturenBrowse
>
>         LOCAL nCurrentRecno     AS WORD
>         LOCAL oWin                      AS PrintProgress
>         LOCAL n, y                      AS WORD
>         LOCAL aDBStructure      AS ARRAY
>         LOCAL oOutput           AS Facturen
>         LOCAL oFacturen                 AS Facturen
>
>         oFacturen:=Facturen{}
>         IF !oFacturen:CreateOutputDBF()
>                 // report an error creating the DBF and take evasive action
>         ENDIF
>         oFacturen:Close()       // but you don't have to if you need to use the
> data...
>
>         oOutput:=Facturen{"OUTPUT"}  // Open the DBF
>         // use oOutput
>         oOutput:Close()
>
>         RETURN NIL
>
> METHOD CreateOutputDBF() CLASS Facturen
>
>         LOCAL aStruct AS ARRAY
>         LOCAL lReturn AS LOGIC
>
>         aStruct := SELF:DBFStructure
>
>         // create a new DBF with the same structure but different name
>         lReturn :=
> DBCREATE("OUTPUT",aStruct,"BDBFCDX",TRUE,__UniqueAlias("OUTPUT"))
>
>         DBCLOSEAREA()    // flush to disk and close
>
>         RETURN lReturn
>
> Now let's get one thing clear first: you have a DBServer class generated
> with the DBServer editor... yes? Good. Because of this, we can use that
> class for the input and output DBF in our code. We just pass the name of
> the DBF (NOT NOT PASS .DBF WITH THIS NAME) to the instantiation clause
> and it will pick up the correct DBF. I have not passed in the working
> folder path with the name but of course you can do this too.
>
> You can also create an output class to use like this:
>
> CLASS OutputFacturen INHERIT Facturen
>
> Now it will work.
>
> Cheers,
>
> Geoff

Ok Geoff, thanks for your support, the create of the temp file works,
now i think the problem is somewhere else, error is on line:

// oOutput:=FACTUREN{"OUTPUT"} // Open the DBF (your suggested code)
oOutput:=FACTUREN{oSystem:Workdir + "\FACTUREN.DBF"} // Open the
DBF (my code)


Error message:
--------------
Error Code: 21 [ OPEN ERROR ]
Subsystem: DBFCDX
Error Subcode: 1101 (Open database)
Function: INIT
Filename: ......
CallStack:
MYOWNSERVER:INIT (Line:14)
FACTUREN:INIT (Line:65)
FACTURENBROWSE:GENEREERARTDBF2 (Line:17)
FACTURENBROWSE:PRINTFACTURENOPENSTAAND (Line:13)
PRINTSETTING:BUTTONOK (Line:49)

Error Object created:
--------------------
SubSystem :DBFCDX
SubCode :1101
GenCode :Open error
OsCode :3
ArgType :NIL
FuncPtr :0x00000000
ArgNum :0
FuncSym :INIT
Severity :2
CanDefault :.F.
CanRetry :.T.
CanSubstitute :.F.
Operation :
Description :
FileName :D:\..........\TEMP\FACTUREN.DBF
Tries :1
FileHandle :0
SubCodeText :Open database
Arg :
ArgTypeReq :NIL
MaxSize :0
SubstituteType :NIL
CallFuncSym :
--------------------

The MYOWNSERVER is:
CLASS MYOWNSERVER INHERIT DBSERVER
METHOD Close() CLASS MYOWNSERVER

self:Commit()

RETURN SUPER:Close()
METHOD init(oFileSpec, lShareMode, lReadOnlyMode, cDriver, lMerge,
lTemp) CLASS MYOWNSERVER
LOCAL cFile as STRING
LOCAL cPath as STRING

default lShareMode to true
default lReadOnlyMode to FALSE
default lMerge to FALSE
default lTemp to FALSE

cFile := oFileSpec:FileName
cPath := oFileSpec:Path
oFileSpec:Path := AllTrim(oSystem:PRGDatadir) + "\" +
AllTrim(oFileSpec:Path)

SUPER:init(oFileSpec, lShareMode, lReadOnlyMode, cDriver)

self:ConcurrencyControl := CCNONE
// SELF:ConcurrencyControl := CCOPTIMISTIC

RETURN self
METHOD RLOCK(nRecord) CLASS MYOWNSERVER
LOCAL lRetVal as LOGIC
LOCAL oWarningBox as Warningbox

IF !SUPER:RLOCK(nRecord)

// Laat een messagebox zien voor locking
oWarningBox := WarningBox{,"Locking probleem"+" "+
AllTrim(self:ALIAS), "Deze gegevens zijn momenteel door iemand anders
in gebruik !" }
oWarningBox:Type := BOXICONEXCLAMATION + BUTTONOKAYCANCEL
oWarningBox:Show()
lRetVal := FALSE
ELSE
lRetVal := true
ENDIF

RETURN lRetVal
From: Woerdie on
On 3 apr, 12:12, Woerdie <woerde...(a)gmail.com> wrote:
> On 3 apr, 01:50, "Geoff Schaller" <geo...(a)softxwareobjectives.com.au>
> wrote:
>
>
>
> > Woerdie,
>
> > Let's try and do this. The following code works for me:
>
> > METHOD GenereerArtDbf2(cOutput, cSortGang, cFile) CLASS FacturenBrowse
>
> >         LOCAL nCurrentRecno     AS WORD
> >         LOCAL oWin                      AS PrintProgress
> >         LOCAL n, y                      AS WORD
> >         LOCAL aDBStructure      AS ARRAY
> >         LOCAL oOutput           AS Facturen
> >         LOCAL oFacturen                 AS Facturen
>
> >         oFacturen:=Facturen{}
> >         IF !oFacturen:CreateOutputDBF()
> >                 // report an error creating the DBF and take evasive action
> >         ENDIF
> >         oFacturen:Close()       // but you don't have to if you need to use the
> > data...
>
> >         oOutput:=Facturen{"OUTPUT"}  //Openthe DBF
> >         // use oOutput
> >         oOutput:Close()
>
> >         RETURN NIL
>
> > METHOD CreateOutputDBF() CLASS Facturen
>
> >         LOCAL aStruct AS ARRAY
> >         LOCAL lReturn AS LOGIC
>
> >         aStruct := SELF:DBFStructure
>
> >         // create a new DBF with the same structure but different name
> >         lReturn :=
> > DBCREATE("OUTPUT",aStruct,"BDBFCDX",TRUE,__UniqueAlias("OUTPUT"))
>
> >         DBCLOSEAREA()    // flush to disk and close
>
> >         RETURN lReturn
>
> > Now let's get one thing clear first: you have a DBServer class generated
> > with the DBServer editor... yes? Good. Because of this, we can use that
> > class for the input and output DBF in our code. We just pass the name of
> > the DBF (NOT NOT PASS .DBF WITH THIS NAME) to the instantiation clause
> > and it will pick up the correct DBF. I have not passed in the working
> > folder path with the name but of course you can do this too.
>
> > You can also create an output class to use like this:
>
> > CLASS OutputFacturen INHERIT Facturen
>
> > Now it will work.
>
> > Cheers,
>
> > Geoff
>
> Ok Geoff, thanks for your support, the create of the temp file works,
> now i think the problem is somewhere else, error is on line:
>
> // oOutput:=FACTUREN{"OUTPUT"}  //Openthe DBF  (your suggested code)
>    oOutput:=FACTUREN{oSystem:Workdir + "\FACTUREN.DBF"}  //Openthe
> DBF (my code)
>
> Error message:
> --------------
> Error Code:  21 [OPENERROR ]
> Subsystem: DBFCDX
> Error Subcode: 1101 (Opendatabase)
> Function: INIT
> Filename: ......
> CallStack:
> MYOWNSERVER:INIT (Line:14)
> FACTUREN:INIT (Line:65)
> FACTURENBROWSE:GENEREERARTDBF2 (Line:17)
> FACTURENBROWSE:PRINTFACTURENOPENSTAAND (Line:13)
> PRINTSETTING:BUTTONOK (Line:49)
>
> Error Object created:
> --------------------
> SubSystem       :DBFCDX
> SubCode         :1101
> GenCode         :Openerror
> OsCode          :3
> ArgType         :NIL
> FuncPtr         :0x00000000
> ArgNum          :0
> FuncSym         :INIT
> Severity        :2
> CanDefault      :.F.
> CanRetry        :.T.
> CanSubstitute   :.F.
> Operation       :
> Description     :
> FileName        :D:\..........\TEMP\FACTUREN.DBF
> Tries           :1
> FileHandle      :0
> SubCodeText     :Opendatabase
> Arg             :
> ArgTypeReq      :NIL
> MaxSize         :0
> SubstituteType  :NIL
> CallFuncSym     :
> --------------------
>
> The MYOWNSERVER is:
> CLASS MYOWNSERVER INHERIT DBSERVER
> METHOD Close() CLASS MYOWNSERVER
>
>         self:Commit()
>
> RETURN SUPER:Close()
> METHOD init(oFileSpec, lShareMode, lReadOnlyMode, cDriver, lMerge,
> lTemp) CLASS MYOWNSERVER
> LOCAL cFile as STRING
> LOCAL cPath as STRING
>
>         default lShareMode              to true
>         default lReadOnlyMode   to FALSE
>         default lMerge                  to FALSE
>         default lTemp                   to FALSE
>
>         cFile := oFileSpec:FileName
>         cPath := oFileSpec:Path
>         oFileSpec:Path := AllTrim(oSystem:PRGDatadir) + "\" +
> AllTrim(oFileSpec:Path)
>
>         SUPER:init(oFileSpec, lShareMode, lReadOnlyMode, cDriver)
>
>         self:ConcurrencyControl := CCNONE
> //      SELF:ConcurrencyControl := CCOPTIMISTIC
>
> RETURN self
> METHOD RLOCK(nRecord) CLASS MYOWNSERVER
> LOCAL lRetVal as LOGIC
> LOCAL oWarningBox as Warningbox
>
>         IF !SUPER:RLOCK(nRecord)
>
>                 // Laat een messagebox zien voor locking
>                 oWarningBox := WarningBox{,"Locking probleem"+" "+
> AllTrim(self:ALIAS),  "Deze gegevens zijn momenteel door iemand anders
> in gebruik !"  }
>                 oWarningBox:Type := BOXICONEXCLAMATION + BUTTONOKAYCANCEL
>                 oWarningBox:Show()
>                 lRetVal := FALSE
>         ELSE
>                 lRetVal := true
>         ENDIF
>
> RETURN lRetVal

Oeps!, found out that the Init of MYOWNSERVER was:
AllTrim(oSystem:PRGDatadir) + "\" + > AllTrim(oFileSpec:Path) here
goes something wrong, investigating now...
From: Woerdie on
On 3 apr, 16:00, Woerdie <woerde...(a)gmail.com> wrote:
> On 3 apr, 12:12, Woerdie <woerde...(a)gmail.com> wrote:
>
>
>
> > On 3 apr, 01:50, "Geoff Schaller" <geo...(a)softxwareobjectives.com.au>
> > wrote:
>
> > > Woerdie,
>
> > > Let's try and do this. The following code works for me:
>
> > > METHOD GenereerArtDbf2(cOutput, cSortGang, cFile) CLASS FacturenBrowse
>
> > >         LOCAL nCurrentRecno     AS WORD
> > >         LOCAL oWin                      AS PrintProgress
> > >         LOCAL n, y                      AS WORD
> > >         LOCAL aDBStructure      AS ARRAY
> > >         LOCAL oOutput           AS Facturen
> > >         LOCAL oFacturen                 AS Facturen
>
> > >         oFacturen:=Facturen{}
> > >         IF !oFacturen:CreateOutputDBF()
> > >                 // report an error creating the DBF and take evasive action
> > >         ENDIF
> > >         oFacturen:Close()       // but you don't have to if you need to use the
> > > data...
>
> > >         oOutput:=Facturen{"OUTPUT"}  //Openthe DBF
> > >         // use oOutput
> > >         oOutput:Close()
>
> > >         RETURN NIL
>
> > > METHOD CreateOutputDBF() CLASS Facturen
>
> > >         LOCAL aStruct AS ARRAY
> > >         LOCAL lReturn AS LOGIC
>
> > >         aStruct := SELF:DBFStructure
>
> > >         // create a new DBF with the same structure but different name
> > >         lReturn :=
> > > DBCREATE("OUTPUT",aStruct,"BDBFCDX",TRUE,__UniqueAlias("OUTPUT"))
>
> > >         DBCLOSEAREA()    // flush to disk and close
>
> > >         RETURN lReturn
>
> > > Now let's get one thing clear first: you have a DBServer class generated
> > > with the DBServer editor... yes? Good. Because of this, we can use that
> > > class for the input and output DBF in our code. We just pass the name of
> > > the DBF (NOT NOT PASS .DBF WITH THIS NAME) to the instantiation clause
> > > and it will pick up the correct DBF. I have not passed in the working
> > > folder path with the name but of course you can do this too.
>
> > > You can also create an output class to use like this:
>
> > > CLASS OutputFacturen INHERIT Facturen
>
> > > Now it will work.
>
> > > Cheers,
>
> > > Geoff
>
> > Ok Geoff, thanks for your support, the create of the temp file works,
> > now i think the problem is somewhere else, error is on line:
>
> > // oOutput:=FACTUREN{"OUTPUT"}  //Openthe DBF  (your suggested code)
> >    oOutput:=FACTUREN{oSystem:Workdir + "\FACTUREN.DBF"}  //Openthe
> > DBF (my code)
>
> > Error message:
> > --------------
> > Error Code:  21 [OPENERROR ]
> > Subsystem: DBFCDX
> > Error Subcode: 1101 (Opendatabase)
> > Function: INIT
> > Filename: ......
> > CallStack:
> > MYOWNSERVER:INIT (Line:14)
> > FACTUREN:INIT (Line:65)
> > FACTURENBROWSE:GENEREERARTDBF2 (Line:17)
> > FACTURENBROWSE:PRINTFACTURENOPENSTAAND (Line:13)
> > PRINTSETTING:BUTTONOK (Line:49)
>
> > Error Object created:
> > --------------------
> > SubSystem       :DBFCDX
> > SubCode         :1101
> > GenCode         :Openerror
> > OsCode          :3
> > ArgType         :NIL
> > FuncPtr         :0x00000000
> > ArgNum          :0
> > FuncSym         :INIT
> > Severity        :2
> > CanDefault      :.F.
> > CanRetry        :.T.
> > CanSubstitute   :.F.
> > Operation       :
> > Description     :
> > FileName        :D:\..........\TEMP\FACTUREN.DBF
> > Tries           :1
> > FileHandle      :0
> > SubCodeText     :Opendatabase
> > Arg             :
> > ArgTypeReq      :NIL
> > MaxSize         :0
> > SubstituteType  :NIL
> > CallFuncSym     :
> > --------------------
>
> > The MYOWNSERVER is:
> > CLASS MYOWNSERVER INHERIT DBSERVER
> > METHOD Close() CLASS MYOWNSERVER
>
> >         self:Commit()
>
> > RETURN SUPER:Close()
> > METHOD init(oFileSpec, lShareMode, lReadOnlyMode, cDriver, lMerge,
> > lTemp) CLASS MYOWNSERVER
> > LOCAL cFile as STRING
> > LOCAL cPath as STRING
>
> >         default lShareMode              to true
> >         default lReadOnlyMode   to FALSE
> >         default lMerge                  to FALSE
> >         default lTemp                   to FALSE
>
> >         cFile := oFileSpec:FileName
> >         cPath := oFileSpec:Path
> >         oFileSpec:Path := AllTrim(oSystem:PRGDatadir) + "\" +
> > AllTrim(oFileSpec:Path)
>
> >         SUPER:init(oFileSpec, lShareMode, lReadOnlyMode, cDriver)
>
> >         self:ConcurrencyControl := CCNONE
> > //      SELF:ConcurrencyControl := CCOPTIMISTIC
>
> > RETURN self
> > METHOD RLOCK(nRecord) CLASS MYOWNSERVER
> > LOCAL lRetVal as LOGIC
> > LOCAL oWarningBox as Warningbox
>
> >         IF !SUPER:RLOCK(nRecord)
>
> >                 // Laat een messagebox zien voor locking
> >                 oWarningBox := WarningBox{,"Locking probleem"+" "+
> > AllTrim(self:ALIAS),  "Deze gegevens zijn momenteel door iemand anders
> > in gebruik !"  }
> >                 oWarningBox:Type := BOXICONEXCLAMATION + BUTTONOKAYCANCEL
> >                 oWarningBox:Show()
> >                 lRetVal := FALSE
> >         ELSE
> >                 lRetVal := true
> >         ENDIF
>
> > RETURN lRetVal
>
> Oeps!, found out that the Init of MYOWNSERVER was:
> AllTrim(oSystem:PRGDatadir) + "\" + > AllTrim(oFileSpec:Path) here
> goes something wrong, investigating now...

Yes, that was it! Up and running now!
Thank you all for your contribution, I am now going to clean all the
clipper stuff.....
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Spinners
Next: Exchange