FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Prevent user pasting CR LF
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Prevent user pasting CR LF
Posted: Fri Oct 09, 2015 10:15 AM
Guys,

I occasionally come across in user's data, CRLF (\r\n) tacked at the end of the field value. Below is one such example


I suspect this occur when user copy and paste from documents such as Word or Excel into my FWH program. Is there any way to prevent this from happening?

TIA
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Prevent user pasting CR LF
Posted: Fri Oct 09, 2015 04:05 PM

Maybe use bChange to use a codeblock to strip out and CR and LFs?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Prevent user pasting CR LF
Posted: Fri Oct 09, 2015 05:11 PM
Hua:

At the moment I do not remember if there is a function to remove the CRLF,
any way you can try the following sample code:

Code (fw): Select all Collapse
cString := "This is a string + CRLF " + CRLF

MsgInfo(LEN(cString))
cString := STRTRAN(cString,CRLF,"")
MsgInfo(LEN(cString))


Please use this code in the VALID clause of your GET

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Prevent user pasting CR LF
Posted: Fri Oct 09, 2015 05:18 PM

I just found that there is a bPaste codeblock you should be able to use also. Unlike bChange or VALID this codeblock will only be called when pasting.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Prevent user pasting CR LF
Posted: Fri Oct 09, 2015 11:21 PM

Thanks Armando and James.

Armando, I don't think it's practical to modify the source to sanitize input at VALIDs. There are a lots of them because ideally all gets should strip any formatting information.

Thanks for pointing out bPaste James. Maybe I could try to customize TGet so all of my gets will sanitize pasted input using bPaste.

Antonio, I hope FWH can come up with a built-in mechanism to strip-off formatting when text is pasted. Much like how a text editor behave where whatever we pasted only the text sticks not the control characters/formatting.

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Prevent user pasting CR LF
Posted: Sat Oct 10, 2015 03:51 PM
Hua,

Antonio, I hope FWH can come up with a built-in mechanism to strip-off formatting when text is pasted. Much like how a text editor behave where whatever we pasted only the text sticks not the control characters/formatting.


I think it would have to be optional, since sometimes we want control characters and formatting, such as in multi-line text fields. It could be complicated in apps where you want both behaviors.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Prevent user pasting CR LF
Posted: Sat Oct 10, 2015 04:23 PM

Hua:

I agree with you when there are many GETs , it occurs to me to make a global function
with my suggestion and in each GET call that function.

Regards

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Prevent user pasting CR LF
Posted: Sat Oct 10, 2015 04:46 PM

Armando,

Depending on how many GETs you have, it would probably be easier to modify the TGet class by adding a CLASSVAR to trigger stripping the CR and LF characters. A CLASSVAR is like a static, so if you default it to .t. then all GETs will be stripped. If you need a GET to not be stripped, then you just reset the CLASSVAR before entering the GET and reset it again when leaving the GET. There would be no changes to your app code--you only have to link in the modified GET class.

The only issue is when the stock TGet class is modified, then you need to move your changes to the new class.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Prevent user pasting CR LF
Posted: Sat Oct 10, 2015 05:09 PM
James:

James Bott wrote:Armando,
Depending on how many GETs you have, it would probably be easier to modify the TGet class by adding a CLASSVAR to trigger stripping the CR and LF characters. A CLASSVAR is like a static, so if you default it to .t. then all GETs will be stripped. If you need a GET to not be stripped, then you just reset the CLASSVAR before entering the GET and reset it again when leaving the GET. There would be no changes to your app code--you only have to link in the modified GET class.
James

You're absolutely right.

James Bott wrote:
The only issue is when the stock TGet class is modified, then you need to move your changes to the new class.
James

This is why I do not like to modify the clases, but it depends on each developer


With best regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Prevent user pasting CR LF
Posted: Sun Oct 11, 2015 05:34 PM

Armando,

Another option is to create a TGet subclass. Then you would need to modify the FIVEWIN.CH file to call that subclass rather than the TGet class.

When a new version of FW comes out the only change you would have to make is to the CH file and probably that change would only be one word--the name of the TGet subclass.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Prevent user pasting CR LF
Posted: Mon Oct 12, 2015 02:56 PM

James:

I think It's the best option.

Thanks a lots

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero

Continue the discussion