Page 1 of 1

Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 11:33 am
by Natter
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?

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 2:29 pm
by Enrico Maria Giordano
Just replace (using STRTRAN()) CRLF with a space or something else you like.

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 2:39 pm
by Marco Augusto
Quiza con la funcion AT

cCAD="abcdfe"+crlf+"12345"

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

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 5:05 pm
by nageswaragunupudi
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?

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 6:45 pm
by karinha
Algo asi?

Code: Select all | Expand

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

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 7:44 pm
by nageswaragunupudi
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: Select all | Expand

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.

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 8:00 pm
by nageswaragunupudi
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: Select all | Expand

   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.

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Mon Dec 11, 2023 8:19 pm
by Enrico Maria Giordano
Yes, you are right. I did not consider the "paste" problem, sorry.

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Tue Dec 12, 2023 7:47 am
by Natter
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 ?
2. 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 ?

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Tue Dec 12, 2023 10:49 am
by nageswaragunupudi
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.

Re: Inserting a string with CRLF into a single-line TGet.

Posted: Tue Dec 12, 2023 12:47 pm
by karinha

Code: Select all | Expand

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