AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 On 4/19/2022 at 4:33 PM, AntonioCuomo said: i need to copy the contents of unidbhtmlmemo and i tried the code proposed above but it doesn't work. With the testcase downloaded with uniedit it works but replacing it with the memo doesn't work. procedure TMainForm.UniFormCreate(Sender: TObject); begin spdCopy.ClientEvents.ExtEvents.Values['click']:='function click(sender, e, eOpts) '+ ' { '+ ' var textarea = document.getElementById("'+memo1.JSName+'_id-inputEl"); '+ ' textarea.select(); '+ ' try { '+ ' var successful = document.execCommand(''copy''); '+ ' if(successful) console.log(''Copied!''); '+ ' else console.log(''Unable to copy!''); '+ ' } catch (err) { '+ ' console.log(''Unsupported Browser!''); '+ ' } '+ ' }'; end; Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 Basically I want to copy the text displayed by dbhtmlmemo into a unimemo. if I do it manually with ctrl-A, ctrl-C and ctrl-V it works perfectly as I expected. the idea is to use a button to automate the operation, it can also be performed only on the server. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 4 hours ago, AntonioCuomo said: Basically I want to copy the text displayed by dbhtmlmemo into a unimemo. if I do it manually with ctrl-A, ctrl-C and ctrl-V it works perfectly as I expected. the idea is to use a button to automate the operation, it can also be performed only on the server. Hello, Sorry, is that a question? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 14 hours ago, Frederick said: Here is the testcase. Click on the TUniSpeedButton but there is no dialogue box displayed. The text in the TUniEdit control is copied to the clipboard however. ajaxreq.7z 54.55 kB · 1 download Hello, Yes, because you are reassigning the event here, and there is no ajaxRequest: procedure TMainForm.UniFormCreate(Sender: TObject); begin spdCopy.ClientEvents.ExtEvents.Values['click']:='function click(sender, e, eOpts) '+ ' { '+ ' var textarea = document.getElementById("'+edtTest.JSName+'_id-inputEl"); '+ ' textarea.select(); '+ ' try { '+ ' var successful = document.execCommand(''copy''); '+ ' if(successful) var text=''Copied!''; '+ ' else var text = ''Unable to copy!''; '+ ' } catch (err) { '+ ' var text = ''Unsupported Browser!''; '+ ' } '+ ' }'; end; Quote Link to comment Share on other sites More sharing options...
Frederick Posted April 22, 2022 Share Posted April 22, 2022 17 minutes ago, Sherzod said: Yes, because you are reassigning the event here, and there is no ajaxRequest: I dunno since I followed Hayri's reply in this post. Where should I put the code then? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 6 minutes ago, Frederick said: Where should I put the code then? For example like this: procedure TMainForm.spdCopyAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin //showmessage(EventName); if SameText(EventName, 'customEvent') then begin ShowMessage(Params['name'].AsString + ' ' + Params['width'].AsString); // sashow(sa, params['name'].AsString, NIL, atInfo, 'OK', '', 'Information'); end; end; procedure TMainForm.UniFormCreate(Sender: TObject); begin spdCopy.ClientEvents.ExtEvents.Values['click']:='function click(sender, e, eOpts) '+ ' { '+ ' var textarea = document.getElementById("'+edtTest.JSName+'_id-inputEl"); '+ ' textarea.select(); '+ ' try { '+ ' var successful = document.execCommand(''copy''); '+ ' if(successful) {var text=''Copied!''; ajaxRequest(sender, "customEvent", {name: text})} '+ ' else {var text = ''Unable to copy!''; ajaxRequest(sender, "customEvent", {name: text})} '+ ' } catch (err) { '+ ' var text = ''Unsupported Browser!''; ajaxRequest(sender, "customEvent", {name: text})'+ ' } '+ ' }'; end; Quote Link to comment Share on other sites More sharing options...
Frederick Posted April 22, 2022 Share Posted April 22, 2022 Thanks for adjusted code. I wouldn't in a million years figured how to create it. Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 i changed the code and it works (with tuniedit). On the form I added a Thtmlmemo and modified the code by changing the name from edttext to htmlmemo1. The event is not detected and the copy does not work. procedure TMainForm.spdCopyAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin //showmessage(EventName); if SameText(EventName, 'customEvent') then begin ShowMessage(Params['name'].AsString + ' ' + Params['width'].AsString); // sashow(sa, params['name'].AsString, NIL, atInfo, 'OK', '', 'Information'); end; end; procedure TMainForm.UniFormCreate(Sender: TObject); begin spdCopy.ClientEvents.ExtEvents.Values['click']:='function click(sender, e, eOpts) '+ ' { '+ ' var textarea = document.getElementById("'+htmlmemo1.JSName+'_id-inputEl"); '+ ' textarea.select(); '+ ' try { '+ ' var successful = document.execCommand(''copy''); '+ ' if(successful) {var text=''Copied!''; ajaxRequest(sender, "customEvent", {name: text})} '+ ' else {var text = ''Unable to copy!''; ajaxRequest(sender, "customEvent", {name: text})} '+ ' } catch (err) { '+ ' var text = ''Unsupported Browser!''; ajaxRequest(sender, "customEvent", {name: text})'+ ' } '+ ' }'; end; Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 with tunimemo run ok. with unidbhtmlmemo not run. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 12 minutes ago, AntonioCuomo said: with tunimemo run ok. with unidbhtmlmemo not run. Hello, Can you please make a simple testcase to check? Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 I attach simple test case ajaxreq (1).rar Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 Okay, thanks. I will try to check a bit later. Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 17 minutes ago, Sherzod said: Okay, thanks. I will try to check a bit later. thank Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 22, 2022 Share Posted April 22, 2022 J have modified the code with thtmlframe: procedure TMainForm.UniFormCreate(Sender: TObject); begin spdCopy.ClientEvents.ExtEvents.Values['click']:='function click(sender, e, eOpts) '+ ' { '+ ' var textarea = document.getElementById("'+ UniHTMLFrame1.JSName +'_id-iframeE1"); '+ //'_id-inputEl"); ' // ' textarea.select(); '+ ' try { '+ ' var successful = document.execCommand(''copy''); '+ ' if(successful) {var text=textarea.value; ajaxRequest(sender, "customEvent", {name: text})} '+ ' else {var text = ''Unable to copy!''; ajaxRequest(sender, "customEvent", {name: text})} '+ ' } catch (err) { '+ ' var text = ''Unsupported Browser!''; ajaxRequest(sender, "customEvent", {name: text})'+ ' } '+ ' }'; end; but display this message: Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 23, 2022 Share Posted April 23, 2022 5 hours ago, AntonioCuomo said: J have modified the code with thtmlframe: Hello, Sorry for the clarification again. What is your main goal, can you tell the sequence of actions? Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 23, 2022 Share Posted April 23, 2022 I have html text in Tunihtmlmemo and I want to copy it back to Tunimemo without the HTML tags. with the Keys Ctrl-A and Ctrl-V in Tunihtmlmemo and then with Ctrl-V in unimemo I get what I wanted. These operations must be performed by a Button event. scheme: Tunimemohtml.selectall; Tunimemohtml.copytoclipborad; Tunimemo.lines.loadfromclipboard; It doesn't matter if it runs server-side or client-side. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 23, 2022 Share Posted April 23, 2022 18 minutes ago, AntonioCuomo said: These operations must be performed by a Button event. Ok, I will check. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 23, 2022 Share Posted April 23, 2022 1 hour ago, AntonioCuomo said: Tunimemohtml.selectall; Tunimemohtml.copytoclipborad; Tunimemo.lines.loadfromclipboard; You can try this approach. 1. procedure TMainForm.UniButton1Click(Sender: TObject); begin with UniHTMLMemo1, UniHTMLMemo1.JSInterface do begin JSCall('relayCmd', ['selectAll']); JSCallDefer('relayCmd', ['copy'], 200); JSCode('Ext.defer(function(){ajaxRequest('+ JSName +', "getSelection", ["selectedText="+'+ JSName +'.getWin().getSelection().getRangeAt(0).toString()])}, 600);') end; end; 2. procedure TMainForm.UniHTMLMemo1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'getSelection' then UniMemo1.Lines.Text := Params.Values['selectedText'] end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 23, 2022 Share Posted April 23, 2022 Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 23, 2022 Share Posted April 23, 2022 Perfect. you are great, thank Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 26, 2022 Share Posted April 26, 2022 after saving in the clipboard tunihtmlmemo remains selected. Is it possible to deselect the text? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 26, 2022 Share Posted April 26, 2022 Hello, I will check. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 26, 2022 Share Posted April 26, 2022 45 minutes ago, AntonioCuomo said: after saving in the clipboard tunihtmlmemo remains selected. Is it possible to deselect the text? Try this: procedure TMainForm.UniButton1Click(Sender: TObject); begin with UniHTMLMemo1, UniHTMLMemo1.JSInterface do begin JSCall('relayCmd', ['selectAll']); JSCallDefer('relayCmd', ['copy'], 200); JSCode('Ext.defer(function(){ajaxRequest('+ JSName +', "getSelection", ["selectedText="+'+ JSName +'.getWin().getSelection().getRangeAt(0).toString()]); '+ JSName +'.getWin().getSelection().removeAllRanges()}, 600);'); end; end; Quote Link to comment Share on other sites More sharing options...
AntonioCuomo Posted April 26, 2022 Share Posted April 26, 2022 I made the change but am forced to reclick on unihtmlmemo to deselect the text Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 26, 2022 Share Posted April 26, 2022 I have tested. Works for me. Quote Link to comment Share on other sites More sharing options...
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.