Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #7641

Re: Why does ANSI character convert after a function returns is?

Message-ID <5494174C.1090603@heliks.nl> (permalink)
Date 2014-12-19 13:17 +0100
Newsgroups comp.lang.clipper.visual-objects
From Robert van der Hulst <robert@heliks.nl>
Subject Re: Why does ANSI character convert after a function returns is?
References <oon39ap05d9juuor4vl76939fvftd08aou@4ax.com> <5492881F.4030905@heliks.nl> <gpl69a1b1t8jfaarqiill6dc3h4htdl9d7@4ax.com>

Show all headers | View raw


Dick,

I see a function with 4 different exit points (RETURNS) that changes the 
SetAnsi to TRUE and set it back to FALSE based on some conditions.
It does not save the original SetAnsi() setting at start and does not 
restore the SetAnsi() setting to the original value at the end.

Everything function should:
- have one and only one exit point (Because you have more that one exit 
point, you must also duplicate the ReturnVar("LUSEADS") code)
- Save and Restore the Global State (such as SetAnsi) when it exits
- Have a local error handler to make sure the Global State is ALWAYS 
restored


Btw: You also create a local pszBuff that is not used anymore...

I am not surprised that you have problems with character encoding if I 
see this.
I bet you have other functions in your code that manipulate SetAnsi as 
well, and somehow your app gets confused.


Robert

> On Thu, 18 Dec 2014 08:54:07 +0100, Robert van der Hulst
> <robert@heliks.nl> wrote:
>
> Hello Robert, Wolfgang, Valery,
>> I think your function WriteString2File() does something with the cSource
>> parameter that causes this.
>> Can you show what this function does ?
> You are right that WriteString2File must have caused something,
> because when I changed it to a more 'neutral' function, the files
> remained the same within the called function and after returning the
> value. I suspected the SetAnsi within the function but that seems
> unlikely because it is reset to the program's standard value False
> (for ADS) afterwards. Besides, it should have been gone wrong in the
> first call as well.
>
> My basic problem was not creating this file (that was test only) but a
> mail creation with Chilkat which did change German characters. We did
> finally solve it seems that with oCKEmail:Charset:="iso-8859-1" (for
> anyone interested). If you could see why the described behaviour
> happens like this I am definitely interested; I still can't explain
> it. The full function is the one below.
>
> Dick
>
>
> FUNCTION WriteString2File(cFile AS STRING,cString AS STRING,lAppend AS
> LOGIC) AS STRING
> //#s General method to write cString in cFile
> //#s
> //#
> //#x
> //#
> //#l Method->function 22-8-2003
> //#l
> //#l
> //#l
> //#
> //#p
> //#
> //#r
> //#
> //#e
> //#
> 	
>
> LOCAL pszBuff AS PSZ
> LOCAL ptrHandle AS PTR
> 	
>
> 	IF File(cFile)
> 		IF !lAppend
> 			IF .NOT. FErase(cFile) // Removed string2psz
> 14-12-2007
> 				RETURN  DosErrString(FError())
> 			ENDIF
> 		ENDIF
> 	ENDIF
> 	SetAnsi(TRUE) // Make sure we write aan ANSI string 24-2-2011
> 	pszBuff := String2Psz(cString) // psz converted data
> 	IF !File(cFile) // Create only if not already there = always
> in overwrite mode, only when new in lAppend mode
> 		ptrHandle := FCreate2(cFile, FC_NORMAL)
> 	ELSE // Already there, append
> 		ptrHandle := FOpen(cFile, FO_READWRITE + FO_COMPAT)
> 		FSeek (ptrHandle, 0, FS_END)
> 	ENDIF	
>
> 	IF ptrHandle != F_ERROR
> 		FWriteText(ptrHandle, cString,SLen(cString)) //
> Changed 27-6-2007
> 		// FWriteText(ptrHandle, pszBuff) // actively removes
> the length information that could allow the functions to continue
> after the  character zero.>NG 25-6-2007
> 	ELSE
> 		IF ReturnVar("LUSEADS") // Correct SetAnsi for ADS
> 			SetAnsi(FALSE)
> 		ENDIF				
> 		RETURN "ERROR"	
> 	ENDIF
> 	IF lAppend // On append: add new line 22-8-2005
> 		FWriteText(ptrHandle, String2Psz(crlf))
> 	ENDIF	
>
> 	IF ReturnVar("LUSEADS") // Correct SetAnsi for ADS
> 		SetAnsi(FALSE)
> 	ENDIF				
> 		
> 	IF !FClose(ptrHandle)
> 		RETURN DosErrString(FError())
> 	ENDIF
> RETURN "" // Means success: 25-2-2005
> .
>


-- 
Robert van der Hulst
robert@heliks.nl

Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why does ANSI character convert after a function returns is? D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2014-12-17 21:03 +0100
  Re: Why does ANSI character convert after a function returns is? "Valery N." <mustangsoftcom@gmail.com> - 2014-12-17 12:34 -0800
    Re: Why does ANSI character convert after a function returns is? D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2014-12-17 22:58 +0100
      Re: Why does ANSI character convert after a function returns is? "Valery N." <mustangsoftcom@gmail.com> - 2014-12-17 14:42 -0800
        Re: Why does ANSI character convert after a function returns is? D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2014-12-18 23:58 +0100
          Re: Why does ANSI character convert after a function returns is? "Valery N." <mustangsoftcom@gmail.com> - 2014-12-19 02:06 -0800
  Re: Why does ANSI character convert after a function returns is? "Valery N." <mustangsoftcom@gmail.com> - 2014-12-17 12:44 -0800
  Re: Why does ANSI character convert after a function returns is? "Wolfgang Riedmann" <wriedmann@gmail.com> - 2014-12-18 07:42 +0100
  Re: Why does ANSI character convert after a function returns is? Robert van der Hulst <robert@heliks.nl> - 2014-12-18 08:54 +0100
    Re: Why does ANSI character convert after a function returns is? D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2014-12-18 23:45 +0100
      Re: Why does ANSI character convert after a function returns is? "Wolfgang Riedmann" <wriedmann@gmail.com> - 2014-12-19 08:25 +0100
        Re: Why does ANSI character convert after a function returns is? "Valery N." <mustangsoftcom@gmail.com> - 2014-12-19 02:14 -0800
        Re: Why does ANSI character convert after a function returns is? D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2014-12-19 12:04 +0100
      Re: Why does ANSI character convert after a function returns is? Robert van der Hulst <robert@heliks.nl> - 2014-12-19 13:17 +0100
        Re: Why does ANSI character convert after a function returns is? D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2014-12-22 16:09 +0100

csiph-web