Jump to content

Recommended Posts

Posted

Hello,

 

i'm searching to copy selected text from a UniMemo1 to clipboard

 

and paste text from clipboard to Unimemo2.

 

can you give me a solution please ?

 

Thank you;

Posted

Hi,

 

I think, first of all, you need to analyze for example the following link:

http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript

 

Or, if I understand correctly you, try the following solution:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS(
    'var _input = '+ UniMemo1.JSName +'.inputEl.dom;'+
    UniMemo2.JSName + '.setValue('+ UniMemo2.JSName +'.getValue() + _input.value.substring(_input.selectionStart, _input.selectionEnd))'
  );
end;

Best regards.

  • 1 month later...
Posted

Hi,

 

I think, first of all, you need to analyze for example the following link:

http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript

 

Or, if I understand correctly you, try the following solution:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS(
    'var _input = '+ UniMemo1.JSName +'.inputEl.dom;'+
    UniMemo2.JSName + '.setValue('+ UniMemo2.JSName +'.getValue() + _input.value.substring(_input.selectionStart, _input.selectionEnd))'
  );
end;

Best regards.

 

this code works for internet explorer , actually not working with chrome/firefox

procedure TMainForm.BtnMemo1CopyClick(Sender: TObject);
begin
// copy to clipboard from Memo1
    UniSession.AddJS(
                     'var _input = '+ UniMemo1.JSName +'.inputEl.dom;' +
                     'var_text ='  + '_input.value.substring(_input.selectionStart, _input.selectionEnd);' +

                     //this code is working with internet explorer
                     'if( window.clipboardData && clipboardData.setData )'+
                     '{'+
                     'clipboardData.setData("Text", var_text);'+
                     ' } else { '+
                     //this code is not working with firefox/chrome
                     'unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  '+
                     'const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); '+
                     'clipboardHelper.copyString(var_text);'+
                     '}'

                     );
end;

here is my full code ( working only with Internet Explorer)


procedure TMainForm.BtnMemo1CopyClick(Sender: TObject);
begin
// copy to clipboard from Memo1
    UniSession.AddJS(
                     'var _input = '+ UniMemo1.JSName +'.inputEl.dom;' +
                     'var_text ='  + '_input.value.substring(_input.selectionStart, _input.selectionEnd);' +

                     //this code is working with internet explorer
                     'if( window.clipboardData && clipboardData.setData )'+
                     '{'+
                     'clipboardData.setData("Text", var_text);'+
                     ' } else { '+
                     //this code is not working with firefox/chrome
                     'unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  '+
                     'const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); '+
                     'clipboardHelper.copyString(var_text);'+
                     '}'

                     );
end;

procedure TMainForm.BtnMemo1PasteClick(Sender: TObject);
begin
// Paste from Clipboard to Memo1  (actually working only with internet explorer)
    UniSession.AddJS(
        'if( window.clipboardData && clipboardData.setData )'+
        '{'+
         UniMemo1.JSName +
         '.setValue(' +
         UniMemo1.JSName + '.getValue()'+
         '+"\n"+' +
         'window.clipboardData.getData("Text"));'+
         '}');
end;

procedure TMainForm.BtnMemo2CopyClick(Sender: TObject);
begin
// copy to clipboard from Memo2
    UniSession.AddJS('var _input = '+ UniMemo2.JSName +'.inputEl.dom;' +
                     'var_text ='  + '_input.value.substring(_input.selectionStart, _input.selectionEnd);' +

                     'if( window.clipboardData && clipboardData.setData )'+
                     '{'+
                     'clipboardData.setData("Text", var_text);'+
                     '}'+
                     'else'+
                     '{'+
                     'document.execCommand(''copy'');'+
                     '}');
end;

procedure TMainForm.BtnMemo2PasteClick(Sender: TObject);
begin
// Paste from Clipboard to Memo2  (actually working only with internet explorer)
    UniSession.AddJS(
        'if( window.clipboardData && clipboardData.setData )'+
        '{'+
         UniMemo2.JSName +
         '.setValue(' +
         UniMemo2.JSName + '.getValue()'+
         '+"\n"+' +
         'window.clipboardData.getData("Text"));'+
         '}');
end;

Posted

does someone can help me please to get this code working for firefox ?

 

 

Hi,

 

I think, first of all, you need to analyze for example the following link:

http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript

 

Or, if I understand correctly you, try the following solution:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS(
    'var _input = '+ UniMemo1.JSName +'.inputEl.dom;'+
    UniMemo2.JSName + '.setValue('+ UniMemo2.JSName +'.getValue() + _input.value.substring(_input.selectionStart, _input.selectionEnd))'
  );
end;

Best regards.

 

Hi,

 

Can you check again, this code works fine on FF.

 

Best regards

Posted

Hi,

 

Can you check again, this code works fine on FF.

 

Best regards

 

 

Thank you for the reply, 

 

this code works for copy and paste between two memos but this is not what i need.

 

i'm searching to copy a memo 1 to windows clipboard 

 

if the user need later to paste the content from clipboard : paste content from clipboard into a memo 

  • 1 year later...
Posted

hello dunham..
probably u still need the answer.

please try this simple way. I tried , and working well

Uses Clipbrd;

 

// and use this
Clipboard.AsText := 'whatever string you want';

Posted

hello dunham..

probably u still need the answer.

 

please try this simple way. I tried , and working well

 

Uses Clipbrd;

 

// and use this

Clipboard.AsText := 'whatever string you want';

 

This uses the clipboard on server side!

  • 2 years later...
  • 3 months later...
Posted
On 9/18/2020 at 9:11 AM, ALFEU said:

paste an image in UniHTMLMemo I need to save it in bmp, jpeg, base64 or another format to save and send, if anyone has an example

Did you get a solution for this case?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...