FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Inserting a string with CRLF into a single-line TGet.
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 11:33 AM

Hi,

In the document, I select a line consisting of 2 parts separated by the characters CRLF or chr(10)

and copy it to the clipboard. Next, I want to paste the information from the clipboard into a one-line TGet.

However, only the first part of the phrase (before CRLF) will be inserted. How can I solve this problem?

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 02:29 PM

Just replace (using STRTRAN()) CRLF with a space or something else you like.

Posts: 151
Joined: Wed Oct 12, 2005 01:03 PM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 02:39 PM

Quiza con la funcion AT

cCAD="abcdfe"+crlf+"12345"

cCAD2=SUBSTRING(cCAD,1,AT(CHR(10),cCAD)-1)

Marco Augusto Rodriguez Manzo

FWH January 2020 Xharbour 1.2.3

MySQL 5.0.19 Fastreport



PERZO SOFT

Sistemas Personalizados
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 05:05 PM
Marco Augusto wrote:Quiza con la funcion AT

cCAD="abcdfe"+crlf+"12345"

cCAD2=SUBSTRING(cCAD,1,AT(CHR(10),cCAD)-1)
Can you provide a working sample?
Regards



G. N. Rao.

Hyderabad, India
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 06:45 PM
Algo asi?
Code (fw): Select all Collapse
#include "FiveWin.ch"

FUNCTION Main()

   LOCAL cText, cVar

   cText := "Teste1 " + CHR( 10 ) + " Teste2" + CHR( 9 ) + " Teste3 " + ;
            CHR( 25 ) + CHR( 13 ) + CHR( 10 )

   ? LEN( cText )

   ? cText

   cText := ClearString( cText )

   ? LEN( cText )

   ? cText

   cVar := StrTran( HardCR(  AllTrim( cText ) ), Hb_EOL() )

   ? cVar

   cVar := SUBST( cText, 1, AT( CHR(10), cText )-1 )

   ? cVar

RETURN NIL

FUNCTION ClearString( cString )

   LOCAL cNewString
   LOCAL n

   cNewString := ""

   FOR n := 1 TO LEN( cString )

      IF asc( substr( cString, n, 1 ) ) == 9 // TAB

         cNewString += CHR( 32 )

      ELSEIF asc( substr( cString, n, 1 ) ) >= 32

         cNewString += substr( cString, n, 1 )

      ENDIF

   NEXT n

RETURN cNewString

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 07:44 PM
All this is ok, as long as you know the text.
And substitution by itself is a simple one line code.

The user copies some text from some other window or application or a webpage by pressing Ctrl-C or by selecting Copy from the context
And as a programmer you do not know what text the user will copy.

And when the user wants to paste in the Get, he presses Ctrl-V or selects "Paste" from the right-click context menu.
Then the TGet class calls:
Code (fw): Select all Collapse
CallWindowProc( ::nOldProc, ::hWnd, WM_PASTE, 0, 0 )
Now the Windows OS reads the text from the Clipboard and Pastes in the Get buffer. While doing so the Windows OS truncates the string from CRLF onwards.

How and when do you apply to what text your logic of substituting CRLF or TAB ?
So, no point giving program to replace CRLF.
Give a program where if I copy whatever text which includes CRLF and paste in the Get, I will get all the text excepting the CRLF.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 08:00 PM
Natter wrote:Hi,

In the document, I select a line consisting of 2 parts separated by the characters CRLF or chr(10)
and copy it to the clipboard. Next, I want to paste the information from the clipboard into a one-line TGet.
However, only the first part of the phrase (before CRLF) will be inserted. How can I solve this problem?
I suggest this quick solution for your immediate use.
You need to write it for each Get.

Sample logic:
Code (fw): Select all Collapse
   DEFINE DIALOG oDlg SIZE 400,400 PIXEL TRUEPIXEL

   @ 20,20 GET oGet1 VAR cVar1 SIZE 300,24 PIXEL OF oDlg
   oGet1:bKeyDown := { |k| If( k == ASC("V") .and. GetKeyState( VK_CONTROL ), CheckCRLF(), ) }

   // other code

//--------------------

function CheckCRLF()

   local cText := FW_GetClipboardData()

   if ValType( cText ) == "C"
      cText := StrTran( StrTran( cText, CRLF, " " ), Chr(10), " " )
   endif
   FW_CopyToClipboard( cText )

return nil
We are peeking into the ClipBoard and putting back modified string again into the clipboard just before the Windows OS reads it. Now Windows OS reads the modified string.



Note:
Limitations:
1. This is working with ANSI gets only. Not working reliably with Unicode gets. We are looking into it.
2. This works if the user pastes by pressing Ctrl-V. Does not work if the user pastes by selecting "Paste" menu option in the popup context menu. This needs modification of HandleEvent method of TGet class.

Hope this works for now.
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Mon Dec 11, 2023 08:19 PM

Yes, you are right. I did not consider the "paste" problem, sorry.

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Tue Dec 12, 2023 07:47 AM

Thank you, Rao, a good solution !

Please explain such points:

  1. Why write oGet1:bKeyDown :={ |k|If( k == ASC("V") .and. GetKeyState(VK_CONTROL ), Check CRL F(), ) }

for each control if the method can be modified :KeyDown via Override ?

  1. Will this function work when entering data from the clipboard via the context menu ? Can use :bChange and check which way to make these changes ?
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Tue Dec 12, 2023 10:49 AM
1. Why write oGet1:bKeyDown :={ |k|If( k == ASC("V") .and. GetKeyState(VK_CONTROL ), Check CRL F(), ) }
for each control if the method can be modified :KeyDown via Override ?
With override, the change applies to all Gets and we need not write this for each Get.
If you like, you can override the method till next version. t
2. Will this function work when entering data from the clipboard via the context menu ?
For this, we need to modify/override the method HandleEvent.
Can use :bChange and check which way to make these changes ?
No use at all. By this time, Windows OS has already read the Clipboard contents and completed the paste operation truncating the text from CRLF onwards. We have no way to know what is the original text.
Regards



G. N. Rao.

Hyderabad, India
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Inserting a string with CRLF into a single-line TGet.
Posted: Tue Dec 12, 2023 12:47 PM
Code (fw): Select all Collapse
// C:\FWH/SAMPLES\CSTRING2.PRG By Mister Nages.

#include "FiveWin.ch"

#Define CLR_MSPURPLE   nRGB( 0,   120, 215 )

FUNCTION Main()

   LOCAL oDlg, oGet, oFont, oFnt, cText1, cVar := SPACE(300)
   LOCAL oSay, cSayGet, oSalida

   SkinButtons()

   cText1 := "Teste1 " + Chr( 10 ) + " Teste2" + Chr( 9 ) + " Teste3 " + ;
      Chr( 25 ) + Chr( 13 ) + Chr( 10 )

   cVar    := cText1
   cSayGet := [USE CTRL+V PARA COPIAR O TEXTO OCULTO...]

   DEFINE FONT oFont  NAME "Ms Sans Serif"  SIZE 00, -16 BOLD
   DEFINE FONT oFnt   NAME "Ms Sans Serif"  SIZE 00, -14 BOLD

   DEFINE DIALOG oDlg SIZE 400, 400 PIXEL TRUEPIXEL

   oDlg:lHelpIcon := .F.

   // ASI, ES MEJOR:
   @ 50, 20 GET oGet VAR cVar SIZE 350, 50 PIXEL OF oDlg MEMO FONT oFont UPDATE

   // CTRL+V
   oGet:bKeyDown := {| k | If( k == Asc( "V" ) .AND. ;
        GetKeyState( VK_CONTROL ), CheckCRLF(), ) }

   // other code

   @ 120, 20 SAY oSay VAR cSayGet OF oDlg PIXEL FONT oFnt UPDATE SIZE 350, 20 ;
      COLORS CLR_BLACK, CLR_MSPURPLE

   @ 320, 160 BUTTON oSalida PROMPT "&Salida" SIZE 70, 30 OF oDlg PIXEL       ;
      ACTION( oDlg:End() ) CANCEL

   SET FONT OF oSalida TO oFnt

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()
   oFnt:End()

RETURN NIL

FUNCTION CheckCRLF()

   // LOCAL cText := FW_GetClipboardData()  //???? DEFINE DIALOG??
   LOCAL cText := SPACE(300)

   cText := [TEXTO A COPIAR PARA O GET EM DESTAQUE... ]

   IF ValType( cText ) == "C"

      cText := StrTran( StrTran( cText, CRLF, " " ), Chr( 10 ), " " )

   ENDIF

   FW_CopyToClipboard( cText )

RETURN NIL

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion