Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to copy selected items from a TListBox to the clipboard without using the VC Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
99
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I want to copy selected items (only text) from a TListBox that has LBS_EXTENDEDSEL 
style to the standard clipboard using only API functions.

Answer:

This code is untested and requires the unit APIClipboard from Tip "Clipboard access 
routines which use only API functions".
1   
2   procedure CopySelectedListboxItemsToClipboard(listboxwnd: HWND);
3   
4     function GetItem(num: Integer): string;
5     begin
6       SetLength(Result, SendMessage(listboxwnd, LB_GETTEXTLEN, num, 0));
7       if Length(Result) > 0 then
8         SendMessage(listboxwnd, LB_GETTEXT, num, LPARAM(@Result[1]));
9     end;
10  
11  var
12    num: Integer;
13    selIndices: array of Integer;
14    sl: TStringlist;
15    S: string;
16  begin
17    num = SendMessage(listboxwnd, LB_GETSELCOUNT, 0, 0);
18    if num = LB_ERR then
19    begin
20      {listbox is a single selection listbox}
21      num := SendMessage(listboxwnd, LB_GETCURSEL, 0, 0);
22      if num = LB_ERR then
23        Exit; {no selected item}
24      S := GetItem(num);
25    end
26    else
27    begin
28      SetLength(selIndices, num);
29      SendMessage(listboxwnd, LB_GETSELITEMS, num, LPARAM(@selIndices[0]));
30      sl := TStringlist.Create;
31      try
32        for num := 0 to High(selIndices) do
33          sl.Add(GetItem(selIndices[num]));
34        S := sl.Text;
35      finally
36        sl.free;
37      end;
38    end;
39    StringToClipboard(S);
40  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC