dunham Posted December 15, 2015 Posted December 15, 2015 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; Quote
Sherzod Posted December 15, 2015 Posted December 15, 2015 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. Quote
dunham Posted January 20, 2016 Author Posted January 20, 2016 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; Quote
dunham Posted January 20, 2016 Author Posted January 20, 2016 here is the test -demo project www.solidfiles.com/d/e522ff67cc/ http://www.solidfiles.com/d/e522ff67cc/ Quote
dunham Posted January 20, 2016 Author Posted January 20, 2016 does someone can help me please to get this code working for firefox ? Quote
Sherzod Posted January 20, 2016 Posted January 20, 2016 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 Quote
dunham Posted January 21, 2016 Author Posted January 21, 2016 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 Quote
guswid Posted December 20, 2017 Posted December 20, 2017 hello dunham..probably u still need the answer.please try this simple way. I tried , and working wellUses Clipbrd; // and use thisClipboard.AsText := 'whatever string you want'; Quote
Oliver Morsch Posted December 20, 2017 Posted December 20, 2017 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! Quote
ALFEU Posted September 17, 2020 Posted September 17, 2020 Como faço para capturar parecido com delphi? UniImage1.Picture.Assign(Clipboard) ; Quote
ALFEU Posted September 18, 2020 Posted September 18, 2020 preciso copiar o UniHTMLMemo para imagem bmp Quote
Sherzod Posted September 18, 2020 Posted September 18, 2020 2 hours ago, ALFEU said: preciso copiar o UniHTMLMemo para imagem bmp Hello, Can you please explain what you are asking in English? Quote
ALFEU Posted September 18, 2020 Posted September 18, 2020 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 Quote
TI.ME Posted January 12, 2021 Posted January 12, 2021 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? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.