Uniface User Forum

 View Only
  • 1.  Clipboard

    PARTNER
    Posted 05-28-2019 18:02

    Hello everyone,

    Is it possible to copy a text from a editbox to the windows clipboard?

    I'd like to create a button that copies the content to the clipboard.



  • 2.  RE: Clipboard

    Posted 05-28-2019 18:18

    Yes, this is possible 🙂
    But I can't tell you the exact way, 'cause I don't have access to our model at this very moment
    It was somthing with macro "CTRL-C" where CTRL-C is to replace by the proper keynumbers

    Ingo



  • 3.  RE: Clipboard

    PARTNER
    Posted 05-28-2019 18:24

    Thanks for your answer 🙂 

     I've just found a different method, I don't know if it's the right one haha.

    I use the Output box, putting the message with the command $fieldhandle(Field)->$widgetoperation("addLine", "LineContent"). And then I use $prompt in this field and use the command macro "^Save".



  • 4.  RE: Clipboard

    Posted 05-29-2019 07:09

    It's a very old solution I use since U6 that only works on Unifields.
    As part of the umeFASTory package, I have encapsulated this in a separate U8Y_2CLIP component

    operation exec
    params
       string p_TextToClipboard : IN
    endparams
      unifield_output =  p_TextToClipboard
      edit/menu UNIFIELD_OUTPUT ; position on the unifield !
      return 0
    end
    
    trigger menu ;
    ; to make it work, the active field has to be a unifield
    	macro("^SELECT^TEXT^SAVE^accept")
    end; menu trigger

    Usage:

       if (X_SHOW_CODE.<$entname> != "")
          activate "U8Y_2CLIP".exec(X_SHOW_CODE.<$entname>)
       endif

    HIH, Uli




  • 5.  RE: Clipboard

    Posted 05-29-2019 08:15

    Field detail action: call ToClipboard(@$fieldName())

    (or button test: call ToClipboard('clipboardtext'))

    entry ToClipboard

    params

    string pc_text : IN

    endparams

    variables

    string oWScript

    endvariables

    $13 = "WScript.Shell"

    perform "OACreateObject"

    perform "OAShowError"

    oWScript = $12

    ;$12 = oWScript

    $13 = "Run"

    $14 = "s·;cmd /C echo %%pc_text%%%|CLIP·;i·;0·;i·;0"

    perform "OAInvoke"

    perform "OAShowError"

    $12 = oWScript

    perform "OADestroyObject"

    perform "OAShowError"

    end



  • 6.  RE: Clipboard

    Posted 05-29-2019 09:47

    Hi Vladimir,

    thanks for pointing to the CLIP.EXE and the nice and elegant solution
    as all code can be in just a little (global) proc .
    Shouldn't that work as well with a simple spawn "cmd /C echo %%pc_text%%%|CLIP"
    so we do not have to perform all these "OA..." executables?

    TIA, Uli


    Background:

    The CLIP.EXE is documented at https://www.c3scripts.com/tutorials/msdos/clip.html


    On https://superuser.com/questions/231023/windows-script-to-copy-some-text-to-the-clipboard there is a discussion how to avoid the additional Newline with:

    EDIT
    The main thing is that clip command but as pointed out by Asu, a line like echo abc will also send a \r\n (which is a new line). If you want to avoid that, then that's a very standard issue solved by replacing echo texttoecho, with echo|set/p=texttoecho So C:\>echo|set/p=texttoecho|clip


    On https://stackoverflow.com/questions/34934036/copying-to-clipboard-from-txt-file-via-bat-file there is a solution to handle multi-line texts with a temporary file as:

    However, please note that you should put double quotes around the filename, as your script will otherwise break if the filename contains spaces.

    Also not that you can also use input < in your code, which instead of piping output from another command, immediately puts the contents into a command. To conclude, the following codes will both work:

    @echo off
    clip < "c:\Users\Test user\Desktop\paste scripts\ProgramTemplate\ProgramTemplate.txt"
    

    or

    @echo off
    type "c:\Users\Test user\Desktop\paste scripts\ProgramTemplate\ProgramTemplate.txt" | clip
    


  • 7.  RE: Clipboard

    Posted 05-29-2019 10:25

    Spawn is OK, but I like OA... :)

    vd



  • 8.  RE: Clipboard
    Best Answer

    Posted 06-03-2019 12:18

    here are the points of the german jury

    CTRL-C:  call LP_MACRO("^FIRST^CHAR^SELECT^LAST^CHAR^SAVE")

    CTRL-V:  call LP_MACRO("^FIRST^INS_SELECT")

    CTRL-X:  call LP_MACRO("^FIRST^CHAR^SELECT^LAST^CHAR^REM_SELECT")

    Where LP_MARCO is a simple wrapper for "macro".
    UnifAce will leave a entry if you do a "macro", so with this wrapper, on e can gon on with code after "macro"

    Ingo