Recent

Author Topic: Synedit Copy and Paste  (Read 4143 times)

vitronix

  • New member
  • *
  • Posts: 9
Synedit Copy and Paste
« on: September 22, 2015, 10:17:19 am »
Hello Object Pascal programmers,

I'm having trouble with the SynEdit component, when I paste from notepad the code is displayed twice in SynEdit it looks like this
#include <stdio.h>

void main()
{
  printf("Hello World \n");
}#include <stdio.h>

void main()
{
  printf("Hello World \n");
}

Code: [Select]
procedure TMainForm.PasteSpdBtnClick(Sender: TObject);
begin
  SynEdit.CommandProcessor(TSynEditorCommand(ecPaste), ' ', nil);
end;

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12023
  • Debugger - SynEdit - and more
    • wiki
Re: Synedit Copy and Paste
« Reply #1 on: September 22, 2015, 10:47:23 am »
did you try to call "synedit.paste"?   Probably no difference.

what OS/version/CPU?

If that is windows, this is the standard Notepad.exe? plain text? no richtext?

Try a breakpoint to see that the speedbutton click is triggered only once.

vitronix

  • New member
  • *
  • Posts: 9
Re: Synedit Copy and Paste
« Reply #2 on: September 22, 2015, 11:30:26 am »
OS is Windows 7 64-bit, CPU Intel Core i3
Editor to paste from is notepad.
Actually the paste button works fine, but when I use CTRL+V the problem occurs:
Code: [Select]
procedure TMainForm.SynEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  Altered:= TRUE;
  if (Shift = [ssCtrl]) then
  begin
    case Key of
    VK_C: SynEdit.CommandProcessor(TSynEditorCommand(ecCopy), ' ', nil);
    VK_V: SynEdit.CommandProcessor(TSynEditorCommand(ecPaste), ' ', nil);
    VK_X: SynEdit.CommandProcessor(TSynEditorCommand(ecCut), ' ', nil);
    end;
  end;
end;

I shamelessly copied the code from somewhere on the Internet, but you would say that exactly the same command is executed as the speedbutton's code.

Bart

  • Hero Member
  • *****
  • Posts: 5667
    • Bart en Mariska's Webstek
Re: Synedit Copy and Paste
« Reply #3 on: September 22, 2015, 02:28:16 pm »
You need to add
Code: [Select]
  Key := 0;

Otherwise the SynEdit happily handles the Ctrl+V itself (and it does the same as your handler, by default).
In a default SynEdit ^V, ^X and ^C works as expected, so you OnKeyDown handler doesn't add any functionality  :)

Bart

vitronix

  • New member
  • *
  • Posts: 9
Re: Synedit Copy and Paste
« Reply #4 on: September 23, 2015, 02:15:19 pm »
Okay Bart,

The only thing my eventhandler does is changing the Altered Boolean variable.
I should have figured it out myself . . .

Thank you very much for your time and effort.
How do I mark this SOLVED?
Like this:
[SOLVED]

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Synedit Copy and Paste
« Reply #5 on: September 23, 2015, 05:19:51 pm »
As originator of the thread, you are able to edit its title.

 

TinyPortal © 2005-2018