Solved

Copy, Paste and Select All

Posted on 2007-03-20
4
171 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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