12

At the moment I have the following hack:

procedure TForm1.HTMLViewer1KeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
begin
    if (Key = Word('C')) and (Shift = [ssCtrl]) then
        HTMLViewer1.CopyToClipboard;
end;

Is there a more sensible/maintainable way of enabling copying from an htmlviewer? I am hoping that there is a property that I can set, or something, because having to do the above seems stupid. Descendants of TCustomEdit have copying, pasting and select-all-ing by default, but htmlviewer for some reason doesnt seem to be implemented this way.

Another problem is that the above method also doesnt account for right-clicking and selecting "copy"

EDIT: In the end I chose to replace the above code with a proper context menu, as per this tutorial: http://delphi.about.com/od/tmemotrichedit/a/richedit-popup.htm

Francisco Alvarado
  • 2,815
  • 2
  • 26
  • 51
  • 1
    What is THTMLViewer? It's not one of the standard VCL components (at least not in DelphiXE Professional or D2007 Pro). Never mind-it's one of the PBear components - leaving the comment for others to see.) – Ken White May 05 '11 at 00:50
  • 1
    Two suggestions: First, don't call stuff people were nice enough to write and then let you use for free "stupid" - you can always write your own instead and make it "smart". Second, did you look at the source? Does THTMLViewer descend from TCustomEdit? If so, you can create a descendent yourself and publish whatever is needed; if not, comparisons to the capability of TCustomEdit make no sense. – Ken White May 05 '11 at 01:05
  • Thanks for the response. I did look at the source, and it doesnt already implement this, and I thought it ought to work the same as a web browser to some extent, but I guess not. I dont like reinventing the wheel but I have done so now. Delphi was made for hacking as far as I'm concerned so I'll leave it as is. – Nicholas Grasevski May 05 '11 at 01:23
  • The standard Windows keyboard shortcut is Ctrl+Insert to copy. ctrl+C is a convention in some controls and not in others. That you have to do this yourself is expected for there are a lot of places that Ctrl+C does something OTHER than copy. – Warren P May 05 '11 at 01:50
  • 1
    @Warren, Ctrl+C is just as much the standard shortcut as Ctrl+Insert, if not moreso. Some of Microsoft's documentation on the matter doesn't even *mention* the Insert key. – Rob Kennedy May 05 '11 at 08:16
  • 4
    Can you answer your own question in a way that would help others? If you do, you can select yours as the correct answer. It may seem strange, but it is the preferred way of dealing with situations like this. –  May 05 '11 at 12:58
  • My bad. I did a proper context menu, like i said in the edit. Thats my solution. – Nicholas Grasevski May 16 '11 at 00:49
  • Without an **answer** accepted for a question it shows up for anybody looking for unanswered questions. – Brian May 20 '11 at 17:23
  • With THtmlViewer, do you mean PBears THtmlViewer (http://code.google.com/p/thtmlviewer/)? Or do you mean TWebBrowser? – Jon Lennart Aasenden Jun 15 '11 at 20:47
  • pbears thtmlviewer. there is no tick sign under my question for me to click. cbf'ed working out being a stack overflow noob so i accepted the 1 answer. thanks for your help – Nicholas Grasevski Jul 04 '11 at 04:04

1 Answers1

3

You could do something when the user presses Ctrl-C (ie. use your own solution #1)

procedure TForm1.HTMLViewer1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (Key = Word('C')) and (Shift = [ssCtrl]) then
    HTMLViewer1.CopyToClipboard;
end;

or you could implement a popup menu as described here (ie. your own solution #2)

Add a Standard Context (popup) Menu to Delphi's TRichEdit

Sam
  • 2,663
  • 10
  • 41
  • 60