Link to home
Start Free TrialLog in
Avatar of shekou
shekou

asked on

Paste format from Clipboard

I try to copy some text from listview
to clipboard, following is my code:

procedure TForm1.MyListView1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Item: TListItem;
  I,Count: Integer;
  S: String;
begin
  if Shift = [ssCtrl] then
  begin
    case Key of
      Ord('C'):
        with myListView1 do
          if SelCount > 0 then
          begin
            Count := SelCount;
            S := '';
            I := 0;
            while (I < Items.Count) and (Count > 0) do
            begin
              Item := Items[I];
              if Item.Selected then
              begin
                S := S + Item.SubItems.Strings[3] + #13 +Item.SubItems.Strings[2] + #13
                     +Item.SubItems.Strings[0] + #13 +Item.SubItems.Strings[1]+ #13 + #13;
                Dec(Count);
              end;
              Inc(I);
            end;
            Clipboard.AsText := S;
          end;
end;


The problem is when I try to paste it from clipborad to notepad, all #13 should be a in seperate line, but it come out some strange character, not in
a seperate line, how to solve it?
(paste to wordpad is OK).

Thanks

Shekou
Avatar of mahara
mahara

i've copied your code and pasted it to
notepad without #13 replacements.

i've pasted it into editpad and other programs.

So where are you copyin' the text from?
ASKER CERTIFIED SOLUTION
Avatar of Jaymol
Jaymol

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kretzschmar
same result as mahara :-)
for jaymol,

#13 - carriage return
#10 - line feed

meikl
Have you tried it????  I have given the correct answer.

We are talking MicroSoft, not ASCII.  

John.
Just in order to complete this:

1) DOS and Windows use #10#13 to describe a new line start

2) Unix/Linux use #10 and

3) Macintosh uses #13.

Most of the text editors under Windows can handle #10#13 or #10 alone but not #13 alone.

Ciao, Mike
Agreed.

Thanks Mike.
Avatar of shekou

ASKER

Thank both of you, I tried Jaymol's answer, still same problem,
But I think may be it because I am using
Chinese version,  so Jaymol may be right. I give points to him.
I get it work at last, i modified code as following, it works fine:
procedure TForm1.MyListView1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Item: TListItem;
  I,Count: Integer;
  s1: tstringlist;
begin
  if Shift = [ssCtrl] then
  begin
    case Key of
      Ord('C'):
        with myListView1 do
          if SelCount > 0 then
          begin
            Count := SelCount;
            s1:= tstringlist.create;
            I := 0;
            while (I < Items.Count) and (Count > 0) do
            begin
              Item := Items[I];
              if Item.Selected then
              begin
                s1.Add(Item.SubItems.Strings[3]);
                s1.Add(Item.SubItems.Strings[2]);
                s1.Add(Item.SubItems.Strings[0]);
                s1.Add(Item.SubItems.Strings[1]);
                s1.Add('');
                Dec(Count);
              end;
              Inc(I);
            end;
            Clipboard.AsText := S1.Text;
          end;
end;


Thanks

Shekou