Solved

Cut&Copy from RichEdit add linefeeds :-(

Posted on 1997-11-23
14
403 Views
Last Modified: 2013-11-22
If i cut or copy some plaintext out of a TRichEdit using the clipboard standard hotkey (Shift-del, ctrl-c, ctrl-x) and paste it then to notepad, everything is ok.
But if i paste it to MS Outlook Express or some other special applications, at each line a linefeed is added.

I tried to write a message handler for the WM_CUT and WM_COPY message, but the Richedit don't send this messages if i using the standard hotkeys.

Can someone tell me why and how i can solve this?

Bye, Sascha
0
Comment
Question by:otti
  • 7
  • 2
  • 2
  • +3
14 Comments
 
LVL 1

Expert Comment

by:aluiken
ID: 1351593
Hi Sasha,

i can't tell you why but maybe i know the answer. (it's kind of hard because i am at my work and don't have delphi here so there may be some wrong syntaxes)

On the KeyDown event from the TRichEdit create a procedure in that procedure create a keyhandler eg something like

If Key = 'C' And Shift = 'Crtl' Then .......

Then copy the selected text to the clipboard i tought it was something like: RichEdit1.SelText.SaveToClipBoard;
(don't forget to include ClipBoard in your uses clause)

Best Regards,

Arijan
0
 

Author Comment

by:otti
ID: 1351594
Maybe the linefeeds are the {\par} in the richtext. Maybe you could use a Memo. Or do you need colors and formating in the text ?
0
 
LVL 1

Expert Comment

by:aluiken
ID: 1351595
Hi!

I use plaintext in RichEdit, no formating and colors or something.
I need TRichEdit because TMemo only can handle up to 64kB.

Bye, Sascha
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:otti
ID: 1351596
Adjusted points to 400
0
 

Author Comment

by:otti
ID: 1351597
If I understand, the problem is that there is a linefeed copied to the end of the text everytime you copy it from the Trichedit? Why not just deleting that linefeedcharacter? Or is that not possible?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351598
Does it also appears when you set the PlainText property to true?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1351599
Hi!

I think that this are not real linefeeds, because if i paste the text in notepad everything is OK. Only when i paste in Outlook express the lines are broken by empty lines.

If i delete the last character of each line, a char of the text will be deleted.

The property "Plaintext" is set to true.

Bye, sascha
0
 

Author Comment

by:otti
ID: 1351600
Hi!

To say it clear: At each line a linefeed is added.

Here an example:

-------BEGIN--------------
This is the text in the
RichEdit. The text is loaded
from a file or is typed in
from the user.
------END----------------

If i cut it from RichEdit and paste to Outlook Express:

---------BEGIN----------------

This is the text in the

RichEdit. The text is loaded

from a file or is typed in

from the user.

---------END----------------------

Sascha
0
 

Author Comment

by:otti
ID: 1351601
Have you tried searching the strings for controlcaracters, they
do make the most weird things. Where some editors simply ignores them, others don't. Some obscure is definetly in it. use an hexeditor/viewer f.ex.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1351602
Maybe something is wrong with your Outlook. Did you check the
options to avoid line feeds ?
0
 
LVL 2

Expert Comment

by:egono
ID: 1351603
Hi!

I viewed the saved file from Outlook with a hexviewer and there are really an extra CR and LF added.

A normal text looks:

This is a text in[CR LF]
Outlook.

And a pasted text looks:

This is a text in[CR LF CR LF]
Outlook.

If i save the file from my RichEdit and view it in HexEdit everything looks ok.

After some expermentation i think that the Clipboardformat is
not ok. If i cut a text out from notepad, Clipboard.format gives me "CF_TEXT", "CF_OEMTEXT" and "CF_LOCALE", but if i cut from TRichEdit i got many formats more like "CF_RICHEDIT" and some others.

Perhaps Outlook sees that the format in the Clipboard is not "CF_TEXT" and try to paste it as "CF_RICHEDIT".

But how to change Outlooks behavior??? Or better change TRichEdits behavior not to copy as "CF_RICHEDIT".

Sascha

0
 

Author Comment

by:otti
ID: 1351604
Hi Egono!

I looked hours in Outlook options for something that can be the
error, but i haven't found anything.

Did you found something??

Sascha
0
 

Author Comment

by:otti
ID: 1351605
I think I solved this annoying problem.
Try it:

uses clipbrd;

procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
begin
      If (key = 67) and (ssCtrl in Shift) Then begin
            ClipBoard.SetTextBuf(PChar(RichEdit1.SelText));
            Edit1.Text := 'Passou';
      end;
end;

procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
begin
      If (key = 67) and (ssCtrl in Shift) Then
            key := 0; //Prevent the real CTRL C, just for                             optimazation resons
end;

0
 
LVL 4

Accepted Solution

by:
itamar earned 500 total points
ID: 1351606
Hi!

Great, this works!

Many thanks,

Sascha
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question