size : 1959
uploaded_on : Wed Oct 14 00:00:00 1998
modified_on : Wed Dec 8 14:03:18 1999
title : Cut, Copy, Paste
org_filename : CutCopyPaste.txt
author : Neil J. Rubenking
authoremail :
description : Handling cut/copy/paste functions
keywords :
tested : not tested yet
submitted_by : Mike Orriss
submitted_by_email : mjo@3kcc.co.uk
uploaded_by : nobody
modified_by : nobody
owner : nobody
lang : plain
file-type : text/plain
category : delphi-system32bit
__END_OF_HEADER__
There are two steps in handling the cut/copy/paste functions. First, you need to see that the edit menu items are only enabled when they SHOULD be. Second, you need to process those items when they're selected. Here's some possible code:
procedure TForm1.Edit1Click(Sender: TObject);
begin
IF ActiveControl IS TCustomEdit THEN
BEGIN
WITH TCustomEdit(ActiveControl) DO
BEGIN
Cut1.Enabled := SelLength > 0;
Copy1.Enabled := SelLength > 0;
Paste1.Enabled := ClipBoard.HasFormat(CF_TEXT);
END;
END
ELSE
BEGIN
Cut1.Enabled := False;
Copy1.Enabled := False;
Paste1.Enabled := False;
END;
end;
procedure TForm1.Cut1Click(Sender: TObject);
begin
IF ActiveControl IS TDBEdit THEN
WITH TDBEdit(ActiveControl).DataSource.DataSet DO Edit;
TCustomEdit(ActiveControl).CutToClipboard;
IF ActiveControl IS TDBEdit THEN
WITH TDBEdit(ActiveControl).DataSource.DataSet DO Post;
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
TCustomEdit(ActiveControl).CopyToClipboard;
end;
procedure TForm1.Paste1Click(Sender: TObject);
begin
IF ActiveControl IS TDBEdit THEN
WITH TDBEdit(ActiveControl).DataSource.DataSet DO Edit;
TCustomEdit(ActiveControl).PasteFromClipboard;
IF ActiveControl IS TDBEdit THEN
WITH TDBEdit(ActiveControl).DataSource.DataSet DO Post;
end;
OK? Edit1 is the top-level edit menu - when it's clicked, before the menu drops down, it checks if the active control is some kind of edit. If so, it enables Cut and Copy based on whether anything is selected, and it enables Paste base on whether there's text in the clipboard. If not, it disables all three.
To Copy from the active edit control, you just call CopyToClipboard; no problemo. To Cut or Paste, you're *CHANGING* the contents of the active edit control - if it's a DBEdit you need to get into edit mode and post your change afterward.
- Neil J. Rubenking