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


Groups > comp.lang.clipper.visual-objects > #7623 > unrolled thread

Why does ANSI character convert after a function returns is?

Started byD.J.W. van Kooten <vankooten@removethis.ic2.com>
First post2014-12-17 21:03 +0100
Last post2014-12-22 16:09 +0100
Articles 15 — 4 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  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

#7623 — Why does ANSI character convert after a function returns is?

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2014-12-17 21:03 +0100
SubjectWhy does ANSI character convert after a function returns is?
Message-ID<oon39ap05d9juuor4vl76939fvftd08aou@4ax.com>
This is very weird....I open a HTML source document and replace a
couple of phrases (which I use as fields) in it. As a test, I store
the output on disk:

FUNCTION LoadModelDoc (....) as string
cSource:=StrTran(cSource,cSearch,cReplace,1)
WriteString2File("c:\temp\test1.htm",cSource,FALSE)
RETURN cSource

Open test1.htm in a webbrowser I correctly see the German
sz-character:

Straße 3

The calling code is like this:

cSource:=LoadModelDoc(....)
WriteString2File("c:\temp\test2.htm",cSource,FALSE)

However, without any changes, simply returning the value, the sz
character changes to a character looking as a question mark in a
diamond when I open test2.htm in a browser:

Stra"-??e 3

So no dbf storage, just returning a string cSource which is still
correct in the function called  just before returning it's value
...and it is changed directly after!

How could this happen be and how can I prevent it?

Dick

[toc] | [next] | [standalone]


#7624

From"Valery N." <mustangsoftcom@gmail.com>
Date2014-12-17 12:34 -0800
Message-ID<640b98c3-24f4-42a1-b1e5-dcb953f5ae4e@googlegroups.com>
In reply to#7623
It is very likely that you have problems with the coding. For some reason Browser reads that your .html contains a text slice with the unreadable coding. Most likely, the error arises in case of file recording (changeover of part of the text). It is necessary that coding .html and the writeable text matched.

Easy way: to make the correct .html and to compare to that at you turns out. Then directly it will become clear, where an error.

[toc] | [prev] | [next] | [standalone]


#7626

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2014-12-17 22:58 +0100
Message-ID<cvu39a1d29lqs588bojos8dhvuvodij5ut@4ax.com>
In reply to#7624
On Wed, 17 Dec 2014 12:34:55 -0800 (PST), "Valery N."
<mustangsoftcom@gmail.com> wrote:

Hello Valery,

>It is very likely that you have problems with the coding. 
>For some reason Browser reads that your .html contains a text slice with the unreadable coding. 

But that doesn't explain why everything looks 100% ok at the end of
the function I call, but is wrong after the value is returned to the
calling method.

>Or you accidental make record not in that place (offset of a code)...

No records, no browser, no dbf. Just cSource:=LoadModeldoc() - at the
end of this method it's still correct, directly afterwards it isn't
anymore.

That is what amazes me...

Dick

[toc] | [prev] | [next] | [standalone]


#7627

From"Valery N." <mustangsoftcom@gmail.com>
Date2014-12-17 14:42 -0800
Message-ID<b1e83e7e-eb7e-44f7-8621-10acb13f6af6@googlegroups.com>
In reply to#7626
LoadModelDoc is from http://mapbuilder.sourceforge.net?

I ask forgiveness for a carelessness. Your example inexact as doesn't show cSource variable type (LOCAL, GLOBAL, STATIC?). To understand, I will specify your example:

FUNCTION LoadModelDoc (...) AS STRING

	LOCAL cSource AS STRING

	cSource:=StrTran(cSource,cSearch,cReplace,1)
	WriteString2File("c:\temp\test1.htm",cSource,FALSE) // Good
	RETURN cSource

FUNCTION Test()

	LOCAL cSource AS STRING

	cSource:=LoadModelDoc(...)
	WriteString2File("c:\temp\test2.htm",cSource,FALSE) // Error
	RETURN 0L 

The error can arise either by transmission of the cSource variable or in function WriteString2File(), if the cSource variable not of "LOCAL". Also, the error can arise from problems with memory of the computer or violation in a repository (CA-VO) (=> reindex).

[toc] | [prev] | [next] | [standalone]


#7634

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2014-12-18 23:58 +0100
Message-ID<01n69apb7skqeik9jqm9vl0bvb9nfjkp8s@4ax.com>
In reply to#7627
On Wed, 17 Dec 2014 14:42:41 -0800 (PST), "Valery N."
<mustangsoftcom@gmail.com> wrote:

Hello Valery,
>
>I ask forgiveness for a carelessness. 

Carelessness? <g> I am glad you took the time to think about this
weird problem.

>
>The error can arise either by transmission of the cSource variable or in function WriteString2File(), if the cSource variable not of "LOCAL". 
>Also, the error can arise from problems with memory of the computer or violation in a repository (CA-VO) (=> reindex).

Very interesting. Also Robert wrote something must happen in
WriteString2File. LoadModelDoc is no longer the suspect, but
Writestring2file is; see my reply to Robert where I posted the
function. Still not sure what could cause it with both your
explanations.

Dick

[toc] | [prev] | [next] | [standalone]


#7637

From"Valery N." <mustangsoftcom@gmail.com>
Date2014-12-19 02:06 -0800
Message-ID<8e7f1b46-48a8-4709-9504-07e66371feb3@googlegroups.com>
In reply to#7634
IF lCreate
	hFile := FCreate2( cFile, FC_ARCHIVED )
ELSE
	hFile := FxOpen( cFile, OF_READWRITE + OF_SHARE_EXCLUSIVE, NULL_STRING )
ENDIF
IF .NOT. hFile == INVALID_HANDLE_VALUE // F_ERROR

	FWrite3( hFile, pszText, nSize )

	FClose( hFile )
	hFile := NULL_PTR
ENDIF

[toc] | [prev] | [next] | [standalone]


#7625

From"Valery N." <mustangsoftcom@gmail.com>
Date2014-12-17 12:44 -0800
Message-ID<e3af9172-f30e-4283-a0be-f4e937712bb9@googlegroups.com>
In reply to#7623
Or you accidental make record not in that place (offset of a code)...

[toc] | [prev] | [next] | [standalone]


#7628

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2014-12-18 07:42 +0100
Message-ID<cffba2Fit07U1@mid.individual.net>
In reply to#7623
Hi Dick,

> This is very weird....I open a HTML source document and replace a
> couple of phrases (which I use as fields) in it. As a test, I store
> the output on disk:

it depends from what functions do you use to read/write the file.

Some of the VO functions do ansi/oem caracter conversion.

This is a comment from the VO help:

"FWrite() and FWrite3 are assumed to handle raw binary data and are not
dependent upon the status of SetAnsi().  FWriteText() and FWrite4(), on
the other hand, are dependent upon SetAnsi()."


Wolfgang

> 
> FUNCTION LoadModelDoc (....) as string
> cSource:=StrTran(cSource,cSearch,cReplace,1)
> WriteString2File("c:\temp\test1.htm",cSource,FALSE)
> RETURN cSource
> 
> Open test1.htm in a webbrowser I correctly see the German
> sz-character:
> 
> Straße 3
> 
> The calling code is like this:
> 
> cSource:=LoadModelDoc(....)
> WriteString2File("c:\temp\test2.htm",cSource,FALSE)
> 
> However, without any changes, simply returning the value, the sz
> character changes to a character looking as a question mark in a
> diamond when I open test2.htm in a browser:
> 
> Stra"-??e 3
> 
> So no dbf storage, just returning a string cSource which is still
> correct in the function called  just before returning it's value
> ...and it is changed directly after!
> 
> How could this happen be and how can I prevent it?
> 
> Dick



-- 

[toc] | [prev] | [next] | [standalone]


#7629

FromRobert van der Hulst <robert@heliks.nl>
Date2014-12-18 08:54 +0100
Message-ID<5492881F.4030905@heliks.nl>
In reply to#7623
Dick,

I think your function WriteString2File() does something with the cSource 
parameter that causes this.
Can you show what this function does ?

Robert
> This is very weird....I open a HTML source document and replace a
> couple of phrases (which I use as fields) in it. As a test, I store
> the output on disk:
>
> FUNCTION LoadModelDoc (....) as string
> cSource:=StrTran(cSource,cSearch,cReplace,1)
> WriteString2File("c:\temp\test1.htm",cSource,FALSE)
> RETURN cSource
>
> Open test1.htm in a webbrowser I correctly see the German
> sz-character:
>
> Straße 3
>
> The calling code is like this:
>
> cSource:=LoadModelDoc(....)
> WriteString2File("c:\temp\test2.htm",cSource,FALSE)
>
> However, without any changes, simply returning the value, the sz
> character changes to a character looking as a question mark in a
> diamond when I open test2.htm in a browser:
>
> Stra"-??e 3
>
> So no dbf storage, just returning a string cSource which is still
> correct in the function called  just before returning it's value
> ....and it is changed directly after!
>
> How could this happen be and how can I prevent it?
>
> Dick
> .
>


-- 
Robert van der Hulst
robert@heliks.nl

[toc] | [prev] | [next] | [standalone]


#7633

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2014-12-18 23:45 +0100
Message-ID<gpl69a1b1t8jfaarqiill6dc3h4htdl9d7@4ax.com>
In reply to#7629
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

[toc] | [prev] | [next] | [standalone]


#7636

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2014-12-19 08:25 +0100
Message-ID<cfi27rF9pjbU1@mid.individual.net>
In reply to#7633
Hi Dick,

please use never this function:

> 		FWriteText(ptrHandle, cString,SLen(cString)) //

it depends from SetAnsi() and IMHO if you are writing binary files and
you are handling conversions yourself, a function should never depend
from such a setting.
The string in your program will be ANSI, I think, and in an email the
text should be quoted printable (the special caracters), or if HTML,
with the HTML codes (&szlig; for the german ?). Never use 8 bit
caracters in the mail body itself...

Wolfgang

-- 

[toc] | [prev] | [next] | [standalone]


#7638

From"Valery N." <mustangsoftcom@gmail.com>
Date2014-12-19 02:14 -0800
Message-ID<207910b9-0ea2-4bef-84ac-ad58eb52f3d3@googlegroups.com>
In reply to#7636
Yes. In the help and it is written:

FWriteText() Function

Purpose:
Write a string to an open file, with SetAnsi() dependency.
 
Description:
FWriteText() is the same as FWrite() except that an ANSI to OEM conversion is made if SetAnsi() is FALSE.

[toc] | [prev] | [next] | [standalone]


#7639

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2014-12-19 12:04 +0100
Message-ID<v4t79al5trav8mjrnoedmeppsflfcfnml0@4ax.com>
In reply to#7636
On Fri, 19 Dec 2014 08:25:48 +0100, "Wolfgang Riedmann"
<wriedmann@gmail.com> wrote:

Hello Wolfgang,
>
>please use never this function:
>
>> 		FWriteText(ptrHandle, cString,SLen(cString)) //
>
>it depends from SetAnsi() and IMHO if you are writing binary files and
>you are handling conversions yourself, a function should never depend
>from such a setting.


I have added this on purpose (not sure why but there was a situation
where it required these ANSI settings); the ANSI setting is part of
the function and follows the global policy of my program 

I do admit that this specific function somewhere caused the starnge
behaviour but that still doesn't explain to me why it works the first
time and not the second. SetAnsi I set is reset at the end.

>The string in your program will be ANSI, I think, and in an email the
>text should be quoted printable (the special caracters), or if HTML,
>with the HTML codes (&szlig; for the german ?). Never use 8 bit
>caracters in the mail body itself...
>

In our e-mail program, users create HTML source documents in which
codes are then replaced. Then the HTML is 'fed' to the Chilkat object.
Chilkat selects the best encoding automatically.

This source document gave problems, first because of the use of a css
and second because the German characters ended up wrong. The
oCKEmail:Charset:="iso-8859-1" solved that. 

I do not use the WriteString2File function for the e-mails but here I
only used it to see where it went wrong.

Dick

[toc] | [prev] | [next] | [standalone]


#7641

FromRobert van der Hulst <robert@heliks.nl>
Date2014-12-19 13:17 +0100
Message-ID<5494174C.1090603@heliks.nl>
In reply to#7633
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

[toc] | [prev] | [next] | [standalone]


#7648

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2014-12-22 16:09 +0100
Message-ID<0dcg9apg5jminltmonpisu2v1us1idfl6v@4ax.com>
In reply to#7641
On Fri, 19 Dec 2014 13:17:16 +0100, Robert van der Hulst
<robert@heliks.nl> wrote:

Hello Robert,

>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.


Everywhere in my application where I I use SetAnsi, it ends with:

IF ReturnVar("LUSEADS") // Correct SetAnsi for ADS
	SetAnsi(FALSE)
ENDIF

Also here. Before the first exit point, SetAnis hasn't been set.
Before the second it is reset to FALSE for ADS and that is also done
before return number 3+4.

I use this function everywhere in my program and the moment it would
ot  return FALSE when using ADS I would get all  kind of problems.
Hence I am sure it always returns false in a ADS environment.

But it must have something to do with this function, I agree with
that. Still I would expect it to go wrong the first time and not only
the 2nd time (it doesn't flip the value of something). I also agree
that I would write these functions quite different nowadays than 11
years ago.

Although it remains a bit of a mystery why it works (or didn't work)
like I expected I thank for thinking with me.

Dick

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web