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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Listbox to copy Text into an Edit, and Digits into a Memo?

Status
Not open for further replies.

Ante0

Programmer
Apr 19, 2007
98
SE
I'm working on a cheat list program.
But now I'm kinda stuck.
What it does is pretty simple, and makes it easier for me...
I insert "Cheat Name" into an Edit, and the code(s) into a Memo.
Then click on a button and it goes to a ListBox.
Here's an example:
Code:
Edit: Cheat1
Memo:
1234
1234
1234
1234

then when I press the button all goes into a listbox (And for the codes to work I need to put ListBox1.Items.Add('..'+Edit1.Text)).

Code:
Listbox after buttonclick:
..Cheat1
1234
1234
1234
1234

Now, what I want to do is...
When I doubleclick ..Cheat1 in the ListBox I want ..Cheat1 to be copied into the Edit, and the Digits copied into the memo (For easier editing).

But I have no idea how to make this work...
I had an idea, when you click ..Cheat1 it would search down from ..Cheat1's itemindex and copy everything until it hit another text entry, like.

Code:
..Cheat1 -> to edit1
1234 -> to Memo
1234 -> to Memo
1234 -> to Memo
1234 -> to Memo
..Cheat2 -> not to be copied unless I doubleclick this entry
2345
2345
2345

Not sure how this would work though.
If anyone has any snippets or code I would appreciate it alot.
Just realized how long this got, if you have any questions just post and I'll try to give more info :)
 
1) You want to use the OnDblClick event of Listbox1.
2) It might be useful to search for a sentinel, it seems you are using one in '..'. Don't respond to the event unless it starts with '..'.
3) You want single select to be set.
4) The Selected property is going to have the value of what you double-clicked on, since the single click should give it focus. This means you will be able to use code no different than you use for a regular listbox.
5) To copy to the memo, you loop on the Listbox list until you hit another sentinel or the end of it.

Pretty straight-forward, really.
 
Well, yes, I will use DblClick event on listbox.
Hmm. a Loop. yes that will work.
How do you use wildcards within a string?
since it will start with '..' then I could put w/e I wanted after it. Would a wildcard be '*' as it is in a dospromt?
I've never worked with wildcards in delphi before..
 
Code:
var
  sTemp : String;
begin
  sTemp := AnsiLeftStr(listBoxString,2);
  if sTemp = '..' then
    begin
    end;
end;

Where listBoxString is the current string you have clicked in the listbox.

There are lots of ways to do this... you can also use Pos (or AnsiPos), AnsiContainsStr etc.

You may want to take a look at the strings section on the Delphi Basics website ( It should provide you with the help you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top