Jump to content

Copy & Paste Selected text in TUniMemo


dunham

Recommended Posts

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.

Link to comment
Share on other sites

  • 1 month later...

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...
  • 3 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...