Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 14 total
Thread Pasting Into a TMemo.
Wed, Feb 26 2014 4:33 PMPermanent Link

Steve Gill

Avatar

Is there a method for pasting text into a TMemo?  I want the user to be able to select text from a TComboBox, click a button, and have the text pasted into the TMemo at the current caret position.

This is for creating email templates and is part of an online business management system.  Basically the TComboBox will have a series of tags that the user can insert into an email, which will later be automatically filled in from a database via a backend process.  I've done this heaps of times in Delphi apps but I now want to be able to do it in EWB apps.

At the moment I can get around this by doing it all in a Windows app and then pasting the whole email template in the EWB app's TMemo field, but it would be much better to be able to do all of this in the EWB app itself.

Thanks,

Steve
Thu, Feb 27 2014 4:21 AMPermanent Link

Matthew Jones

Presumably you don't really need "paste" but rather to know where the caret is in
the existing text so you can do string manipulation. I can't see anything in the
TMemo that will tell you that.

/Matthew Jones/
Fri, Feb 28 2014 4:15 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Steve,

<< Is there a method for pasting text into a TMemo?  I want the user to be
able to select text from a TComboBox, click a button, and have the text
pasted into the TMemo at the current caret position. >>

Text caret/position handling and selection in a browser is notoriously
spotty/different among the various browsers, which is why I punted on it.
It will be something that I will address in version 2 eventually, but for
now the answer is "can't do that".

Tim Young
Elevate Software
www.elevatesoft.com
Sun, Mar 2 2014 4:31 PMPermanent Link

Steve Gill

Avatar

<<  Presumably you don't really need "paste" but rather to know where the caret is in
the existing text so you can do string manipulation. I can't see anything in the
TMemo that will tell you that.  >>

I use the Raize components in my Windows apps.  When I use a TRzMemo, I use the PasteFromClipboard method to paste the text at the current caret position.
Sun, Mar 2 2014 4:32 PMPermanent Link

Steve Gill

Avatar

<< Text caret/position handling and selection in a browser is notoriously
spotty/different among the various browsers, which is why I punted on it.
It will be something that I will address in version 2 eventually, but for
now the answer is "can't do that".  >>

No problem.  I'll modify the Windows app to edit the database on the website.
Sat, Sep 17 2016 2:27 AMPermanent Link

Trinione

"Tim Young [Elevate Software]" wrote:
<< Text caret/position handling and selection in a browser is notoriously
spotty/different among the various browsers, which is why I punted on it.
It will be something that I will address in version 2 eventually, but for
now the answer is "can't do that". >>

Tim:
Any update on this. I would love to have Selection/Cut/Copy/Paste functionality in my apps. In fact, I would even like to replace the default right-click context menu with one of my own created in EWB to work with the app.

In another thread I/we figured out the Copy. How can one paste? Is what I would like to do possible in EWB 2.05 B4 (the latest version)?
Sat, Sep 17 2016 12:01 PMPermanent Link

Raul

Team Elevate Team Elevate

On 9/17/2016 2:27 AM, Trinione wrote:
> "Tim Young [Elevate Software]" wrote:
> << Text caret/position handling and selection in a browser is notoriously
> spotty/different among the various browsers, which is why I punted on it.
> It will be something that I will address in version 2 eventually, but for
> now the answer is "can't do that". >>
>
> Tim:
> Any update on this. I would love to have Selection/Cut/Copy/Paste functionality in my apps. In fact, I would even like to replace the default right-click context menu with one of my own created in EWB to work with the app.
> In another thread I/we figured out the Copy. How can one paste? Is what I would like to do possible in EWB 2.05 B4 (the latest version)?

Trinione,

Paste is similar to the copy and this works for me :

MultiLineEdit1.SetFocus;
window.document.execCommand('paste',True,False);

Detecting caret etc is tricky and i'll leave it to Tim.

However as one approach you could use MouseUP and KeyUP events to check
for selection and then use it (even if just to enable/disable the copy
button).

This is using window.getSelection() function which for now is handled by
external function (no doubt Tim can include it webdom for either window
object or document object as there is Document.getSelection as well that
is same).

I did a quick test and this works in Chrome but not in FF - by docs it
should but don't have time today to dig in.

OK - here's what you need

create external function in external file

function getSelectedText()
{
    if (typeof window.getSelection != "undefined")
    {
        return window.getSelection().toString();
    }
}

define it in EWB

external function getSelectedText():string;


Now you need to define OnMouseUp and OnKeyUp events for your
TMultiLineEdit - in my case i called it "CheckForSelection" and it looks
like this


procedure TForm1.CheckForSelection(Sender: TObject; Key: Integer;
ShiftKey, CtrlKey, AltKey: Boolean);
var
   s:string;
begin
   s:=getSelectedText();
   if s<>'' then
   begin
      //use selection - i'm just adding it to edit box for ow
      Edit1.Text := s
   end
   else
     Edit1.Text := '<no selection found>';
end;


This seems to work quite well with Chrome both for mouse and keyboard
selection.

Raul
Sat, Sep 17 2016 9:15 PMPermanent Link

erickengelke

Avatar

Raul wrote:

On 9/17/2016 2:27 AM, Trinione wrote:
> "Tim Young [Elevate Software]" wrote:
> << Text caret/position handling and selection in a browser is notoriously
> spotty/different among the various browsers, which is why I punted on it.

> Any update on this. I would love to have Selection/Cut/Copy/Paste functionality in my apps. In fact, I would even >like to replace the default right-click context menu with one of my own created in EWB to work with the app.
> In another thread I/we figured out the Copy. How can one paste? Is what I would like to do possible in
>EWB 2.05 B4 (the latest version)?
.
>Paste is similar to the copy and this works for me :

In my book I show how to use CK Editor.  Not only is it feature packed, it's portable across all browsers one command works on all browsers.  You're more likely to have success with that everywhere than relying on browsers own editors.

Erick
 
Mon, Sep 19 2016 8:11 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< Any update on this. I would love to have Selection/Cut/Copy/Paste functionality in my apps. In fact, I would even like to replace the default right-click context menu with one of my own created in EWB to work with the app. >>

I'll have to revisit the issue, but I'm not sure if the situation has improved much.  Here's the clipboard API support breakdown:

http://caniuse.com/#feat=clipboard

and as you can see in the note, you can still only deal with clipboard data in response to user events.  So, no arbitrary access to the clipboard.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Sep 19 2016 10:01 AMPermanent Link

Trinione

erickengelke wrote:
In my book I show how to use CK Editor.  Not only is it feature packed, it's portable across all browsers one command works on all browsers.  You're more likely to have success with that everywhere than relying on browsers own editors.

Erick:
CK Editor is huge and overkill for this app. Its an in-company, not a web facing app and Chrome only. As its a simple text field using MultiLineEdit the execCommand 'copy/paste' would be fine. I do see the need for a more advanced editor like CKEditor or otherwise for other apps though.

Just checked. The book finally shipped today so I'll receive it in a few days. Smile

Thx.


 
Page 1 of 2Next Page »
Jump to Page:  1 2
Image