Page 1 of 1

Errsysw

Posted: Fri Aug 24, 2007 7:20 am
by PeterHarmes
Hi,

When i wrote my app using 16bit version of fivewin, i modified errsysw.prg so that it wrote to a diferent filename instead of overwriting error.log Also i was getting a problem with the errsysw if i had a lot of databases open and i assumed that the variable cErrorlog was getting too big, so i changed the method of writing the file error.log so that it wrote the details in sections (build the details of the error, application write to file, build the details of the dbfs write the file etc)

Since converting to 32bit i occaisionally get a recursive error, which i think means that the errsysw is actually erroring, so i removed my errsysw.

I'm now going to start to look at this problem and was going to get the latest version of errsysw and make the same changes as i initially made to the latest version and wanted to know if there is a problem if the cErrorLog string got too big?

Also, has anyone else made a similar change to errorsysw where it writes to a diferent file each time and are willing to show me how they did it, so i can compare code and see if i can improve what i'm doing?

Thanks in advance

Pete

Posted: Fri Aug 24, 2007 7:32 am
by Antonio Linares
Peter,

> if there is a problem if the cErrorLog string got too big?

As we are in 32 bits, cErrorLog can be as big as 4 Gb. You will not have any problems managing strings below that limit.

> it writes to a diferent file each time

You can use FWH function cTempFile( cPath, cExtension ) --> cUniqueFileName

Posted: Fri Aug 24, 2007 8:48 am
by PeterHarmes
Thanks for the quick reply Antonio.

I forgot to ask another question:

In my modified Errsysw i wanted to write which user got this error message, which in my app is stored as a public variable. If i want to use the errsysw in another app, i have to remember to declare this variable or have a diferent version of errsysw. I would rather have one version, so is there a way to check if a public variable exists before trying to write this to the file?

Thanks in advance

Pete

Posted: Fri Aug 24, 2007 9:15 am
by demont frank
Peter

Me too has changed errsysw.prg
1) filename : Date + time
2) User was stored in a GLOBAL EXTERNAL aBediende

Code: Select all

#ifdef FRANKDEMONT
local cErFile 
cErFile := "ERRORS\Er" + DTOS(DATE()) + "." + CharOnly("0123456789",Time()) + ".log"
....
# ifdef FRANKDEMONT
	cErrorLog += "   Bediende : " + aBediende[1] + CRLF
# endif
Frank

Posted: Fri Aug 24, 2007 9:25 am
by Antonio Linares
Peter,

varname = "UserName"

MsgInfo( Type( "varname" ) ) // you get "C" if varname is assigned and "U" if it isn't

Posted: Fri Aug 24, 2007 10:08 am
by PeterHarmes
If i do a type() on a variable that doesnt exist i get an error - variable does not exist ...

my errsysw has been modified to include:

cErrorLog += "Operator: " + cOperator

so i need to check if the variable cOperator has been declared Publically/Locally before doing this line - is this possible?

Posted: Fri Aug 24, 2007 10:20 am
by Antonio Linares
Peter,

Please notice that the name of the variable has to be inside quotes "varname"

You can only check for publics or privates as they are the only ones that have an entry in the symbols table. Locals and static don't have a symbol name and are not located at the symbols table.

Posted: Fri Aug 24, 2007 10:26 am
by PeterHarmes
My mistake.. Works a treat now! Thanks Antonio

Posted: Fri Aug 24, 2007 4:41 pm
by James Bott
Peter,

A better way to store user info is to put in into a function as a static var. Here is an example:

// Set/Get function example
static function getOption(nNewOption)
local nReply
static nOldOption:=1
nReply:= nOldOption
if nNewOption != nil
nOldOption:= nNewOption
endif
return nReply

You could just change the fucntion name to user().

Better yet is to create a user class and then store the oUser object in the user function. You can create a user class with DATA such as user name, password, rights, etc. Also, you could add methods for load(), save(), and edit(), so you can create a user object and save and restore it.

Then you can do this:

oUser:= TUser():new()

oUser:edit()
oUser:save()

user( oUser )

msgInfo( user():name )

msgInfo( user():rights )

etc...

You could also modify the set/get user() function to automatically return a new blank oUser if a user object was not passed and there isn't one already stored as a static.

Regards,
James