Solved

Copy, Paste and Select All

Posted on 2007-03-20
4
169 Views
Last Modified: 2010-04-05
Dear Experts,

I have a procedure that select all text of a canvas when
the user select menu-item Select All and a procedure when
the user select the text with the mouse (rubberband rectan-
gle). And a procedure to Copy the text to the clipboard and
a procedure to paste text from Clipboard into the canvas.

These procedures works all fine, but now I have to programm
the menu-items in the procedure Edit1Click. Can someone
help me?

It has to be something like this:

if SocOpen := false then       (there is no connection)
                 Copy1.Enabled := False;
                 Paste1.Enabled := False;
                 SelectAll1.Enable := False;

If SocOpen := true then      (there is a connection)
                 SelectAll1.Enable :- True;
   
 If there is text in clipboard
                   Paste1.Enabled := True;
 If there is no text in clipboard
                   Paste1.Enabled := False;

 I believe this the code for it:
    Paste1.Enabled := Clipboard.HasFormat(CF_TEXT);

If there is a selection made by choosing menu-item Select All
or with the mouse:
 
Copy1. Enabled := True

If the user choose Copy then
Paste1.Enabled := True;

Can someone help me?

procedure TForm1.Edit1Click(Sender: TObject);
begin
    //
end;
(*-----------------------------------------------------*)
procedure TForm1.Copy1Click(Sender: TObject);
var
  i, j: integer;
  s: string;
begin
  s := '';
  for i := 1 to SCRROWS do
  begin
    for j := 1 to SCRCOLS do
      if (ScrBuf[i, j].Hilite = Char(chReverse)) and
        (ScrBuf[i, j].Data in ['A'..'Z', 'a'..'z', '0'..'9', ' ',
        ',', '!', '@', '#', '$', '%', '^', '&', '*', '(', '[', ']', ')',
          '<', '>', ';', ':', '=', '-', '.', '/', '\', '+', '"', '|']) then
        s := s + ScrBuf[i, j].Data;
    if s <> '' then s := s + #13#10;
  end;
  with Clipboard do
  begin
    open;
    astext := s;
    close;
  end;
end;
(*-----------------------------------------------------*)
procedure TForm1.Paste1Click(Sender: TObject);
var
  i, j, k: integer;
  ch: char;
  s: string;
begin
  with Clipboard do
  begin
    open;
    s := astext;
    close;
  end;
  k := 1;
  for i := 1 to SCRROWS do
    for j := 1 to SCRCOLS do begin
      if ((j > CsrCol) and (i >= CsrRow)) or (i > CsrRow) then begin
        if Length(s) >= k then begin
          ch := s[k];
          ScrBuf[i, j].data := ch;
          k := k + 1;
        end;
      end;
    end;
  ShowBuf;
end;
(*-----------------------------------------------------*)
procedure TForm1.SelectAll1Click(Sender: TObject);
var
  i, j: integer;
begin
  for i := 1 to SCRROWS do
    for j := 1 to SCRCOLS do
    begin
      if ScrBuf[i, j].Data = '' then
        ScrBuf[i, j].Data := ' ';
      ScrBuf[i, j].Color := Char(ccWhite);
      ScrBuf[i, j].Hilite := Char(chReverse);
    end;
  showbuf;
end;
(*-----------------------------------------------------*)

Peter Kiers

0
Comment
Question by:peterkiers
  • 3
4 Comments
 
LVL 1

Author Comment

by:peterkiers
ID: 18759242
I don't get any further than this:

procedure TForm1.Edit1Click(Sender: TObject);
begin
  if SocOpen = false then
  begin
  Copy1.Enabled := False;
  Paste1.Enabled := False;
  SelectAll1.Enabled := False
  end
  else begin
    Copy1.Enabled := True;
  Paste1.Enabled := Clipboard.HasFormat(CF_TEXT);
  SelectAll1.Enabled := True;
  end;
end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18759287

procedure TForm1.Edit1Click(Sender: TObject);
var
  i,j : integer;
begin
  if SocOpen = false then
  begin
  Copy1.Enabled := False;
  Paste1.Enabled := False;
  SelectAll1.Enabled := False
  end
  else begin
   //here must be the line if the text is selected then...
    Copy1.Enabled := True
    else Copy1.Enabled := False;
  Paste1.Enabled := Clipboard.HasFormat(CF_TEXT);
  SelectAll1.Enabled := True;
  end;
end;
0
 
LVL 10

Accepted Solution

by:
dinilud earned 500 total points
ID: 18762248
procedure TForm1.Edit1Click(Sender: TObject);

 function IsTextSelected:Boolean ;
 var i,j:Integer;
 begin
   Result:=False;
   for i := 1 to SCRROWS do
   begin
      for j := 1 to SCRCOLS do
        if (ScrBuf[i, j].Hilite = Char(chReverse)) and
          (ScrBuf[i, j].Data in ['A'..'Z', 'a'..'z', '0'..'9', ' ',
           ',', '!', '@', '#', '$', '%', '^', '&', '*', '(', '[', ']', ')',
            '<', '>', ';', ':', '=', '-', '.', '/', '\', '+', '"', '|']) then
        begin
           Result:=True;
           Break;
        end;
      if Result then Break;
   end;
 end;

begin
  if SocOpen = false then
  begin
    Copy1.Enabled := False;
    Paste1.Enabled := False;
    SelectAll1.Enabled := False
  end
  else
  begin
    Copy1.Enabled := IsTextSelected;
    Paste1.Enabled := Clipboard.HasFormat(CF_TEXT);
    SelectAll1.Enabled := True;
  end;
end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18766426
Thank you for the help

Greetings,

Peter Kiers
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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