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

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

Postby Natter » 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?
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

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

Postby Enrico Maria Giordano » Mon Dec 11, 2023 2:29 pm

Just replace (using STRTRAN()) CRLF with a space or something else you like.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby Marco Augusto » Mon Dec 11, 2023 2: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
User avatar
Marco Augusto
 
Posts: 144
Joined: Wed Oct 12, 2005 1:03 pm
Location: Cuernacava, Morelos Mexico

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

Postby nageswaragunupudi » Mon Dec 11, 2023 5: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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby karinha » Mon Dec 11, 2023 6:45 pm

Algo asi?

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7825
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

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

Postby nageswaragunupudi » Mon Dec 11, 2023 7: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: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby nageswaragunupudi » Mon Dec 11, 2023 8: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: Select all  Expand view
  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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby Enrico Maria Giordano » Mon Dec 11, 2023 8:19 pm

Yes, you are right. I did not consider the "paste" problem, sorry.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

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

Postby Natter » Tue Dec 12, 2023 7: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 ?
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 ?
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

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

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby karinha » Tue Dec 12, 2023 12:47 pm

Code: Select all  Expand view

// 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
User avatar
karinha
 
Posts: 7825
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 57 guests