Jump to content

dbmemo.SelectAll and dbmemo.CopyToClipboard


mierlp

Recommended Posts

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;

 

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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;

image.png.9032e8d30742eb33e9905b6d7128f988.png

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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:

 

image.png.a9f5620de0d42b8358a3cf8e48b74f57.png

Link to comment
Share on other sites

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.

image.thumb.png.e431087518bc6c37ff3aaf12d8f43035.png

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...