Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell which label the user wants to copy the text of?

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
Thanx all for reading my question and happy new year!

Here's the deal: I got 5 labels and a listbox. I have made popupmenu with a button "copy to clipboard". For this I use the code:

Code:
Clipboard.AsText := LinkStorage.Items[i];

or 

Clipboard.AsText := MyLabel12345.Caption;

Which works fine in itself. But! I want to use the same button for all 5 labels and the listbox (to copy the selected item to the clipboard, multiselect is turned off). How do you go about this? I obviously can't use Sender as it is always the same TMenuItem. So what am I to do?

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
Great Delphi Websites faq102-5352
 
I am not sure that I understand your problem exactly.

The selected item in the Listbox is identified by the property ItemIndex.

You can copy the selected item in the ListBox to the clipboard by
Code:
  Clipboard.AsText := ListBox.Items[ListBox.ItemIndex];
The Items property of the ListBox is a TStrings so you can assign a pointer to each item in the ListBox. This pointer could point to a TLabel. By using this link from the ListBox to the label you could copy the 'selected' label into the clipboard:
Code:
...
var
  label: TLabel;
begin
  ...
  label := ListBox.Items.Objects[ListBox.ItemIndex] as TLabel;
  Clipboard.AsText := label.caption;
I haven't tested the above code but it should give you some idea.

Andrew
Hampshire, UK
 
Could use OnMouseEnter and OnMouseLeave to set a variable as to which label the mouse is pointing to.



Regards and HTH,
JGS
 
Thanks Sijgs,

I initially tried onMouseLeave for the labels but that didnt work with the PopupMenu. But onMouseEnter works really nice!

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
Great Delphi Websites faq102-5352
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top