?
Solved

paste from blipbaord into listbox

Posted on 2011-05-10
9
Medium Priority
?
523 Views
Last Modified: 2012-08-13
hi how can i paste from clipboard into listbox1.. and then on button1 click
add text from listbox1 into listbox 2?

making sure the text is displayed as a list not one long line. The below code copies from the clipboard and pastes it into listbox1 fine, but as one longgggggggggg line. I need more code to fix that then send to listbox 1 and on BUTTON CLICK send it to listbox2.

So,



thnx
var
  strm : TFileStream;
begin
form15.ListBox1.Items.Insert(0, clipboard.astext);
  strm := TFileStream.Create('MyList.DAT', fmCreate);
  strm.WriteComponent(form15.ListBox1);
  strm.Free;
  close;

Open in new window

0
Comment
Question by:boycoder
  • 4
  • 3
  • 2
9 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 35731516
Try this...
procedure ClipboardToListBox(LBox: TListbox);
begin
  if not Assigned(LBox) then Exit;

  if not Clipboard.HasFormat(CF_TEXT) then Exit;

  LBox.Items.Text := Clipboard.AsText;
end;

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 35731523
Basic Clipboard Operations (Cut/Copy/Paste) using the TClipboard object
http://delphi.about.com/od/vclusing/a/tclipboard.htm
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35731567
This will move all items from ListBox1 to ListBox2...

ListBox2.Items.clear;
ListBox2.Items.AddStrings(ListBox1.Items)

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:systan
ID: 35731586
Here' some sample code that I made to add clipboard text to listbox then listbox to listbox by a button;
unit Unit1;

interface

uses ClipBrd,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
listbox2.Items.Add(listbox1.Items[listbox1.itemindex]);
listbox1.Items.Delete(listbox1.itemindex);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
listbox1.Items.Add(listbox2.Items[listbox2.itemindex]);
listbox2.Items.Delete(listbox2.itemindex);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if Clipboard.HasFormat(CF_TEXT) then
listbox1.Items.Add(Clipboard.AsText);
end;

end.

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 35731611
0
 

Author Comment

by:boycoder
ID: 35731856

var
  strm : TFileStream;
begin

if Clipboard.HasFormat(CF_TEXT) then
listbox1.Items.Add(Clipboard.AsText);

  strm := TFileStream.Create('MyList.DAT', fmCreate);
  strm.WriteComponent(ListBox1);
  strm.Free;


end;


/// It just does what i had it already mate, it needs to add the corrected format to the listbox. For example if i have a list of 5 users, they need to be added in 5 lines, not one big line. cheers
0
 
LVL 19

Accepted Solution

by:
Thommy earned 2000 total points
ID: 35733152
with listbox1.Items.add you are adding one listbox item, which results in a long line.


To add multiple items assign your clipboard text contents to items.text property as follows:
LBox.Items.Text := Clipboard.AsText
0
 

Author Closing Comment

by:boycoder
ID: 35733548
A++
0
 
LVL 14

Expert Comment

by:systan
ID: 35734476
>>For example if i have a list of 5 users, they need to be added in 5 lines, not one big line. cheers
You should have post in the question body a detailed manner.
Sorry, I was late to answer.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

864 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