?
Solved

Editing Listbox at runtime 2

Posted on 2004-03-27
3
Medium Priority
?
251 Views
Last Modified: 2010-04-05
Hey,

I asked before how to edit a listbox at runtime by adding a string "locked" after a SELECTED Listbox item  when a button has been clicked.

Now I want to do the opposite so ...

When I click a button it removes the string "locked" after the SELECTED item.

Cheers,

Computer Programer
0
Comment
Question by:computerprogramer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10697866
procedure TForm1.Button2Click(Sender: TObject);
var
  ind: integer;
begin
  ind := Pos(' Locked',ListBox2.Items[ListBox2.ItemIndex]);
ListBox2.Items[ListBox2.ItemIndex] := Delete(ListBox2.Items[ListBox2.ItemIndex],ind,Length(' Locked')) ;
end;
0
 
LVL 17

Accepted Solution

by:
mokule earned 200 total points
ID: 10697869
or better
procedure TForm1.Button2Click(Sender: TObject);
var
  ind: integer;
begin
  ind := Pos(' Locked',ListBox2.Items[ListBox2.ItemIndex]);
  if ind > 0 then
    ListBox2.Items[ListBox2.ItemIndex] := Delete(ListBox2.Items[ListBox2.ItemIndex],ind,Length(' Locked')) ;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10701710
procedure TForm1.btnDeleteClick(Sender: TObject);
var
 tmpStr: String;
begin
 //if item is selected
 if ListBox1.ItemIndex <> - 1 then
 begin
  //shut off control painting
  ListBox1.Items.BeginUpdate;
  //get selected item from list
  tmpStr:= ListBox1.Items[ListBox1.ItemIndex];
  //delete string from selected item
  Delete(tmpStr,pos(' - LOCKED',tmpStr),9);
  //post selected item back to list
  ListBox1.Items[ListBox1.ItemIndex]:= tmpStr;
  //turn back on control painting
  ListBox1.Items.EndUpdate;
  end;
end;

procedure TForm1.btnAddClick(Sender: TObject);
var
 tmpStr: String;
begin
 //if item is selected
 if ListBox1.ItemIndex <> - 1 then
 begin
  //shut off control painting
  ListBox1.Items.BeginUpdate;
  //get selected item from list
  tmpStr:= ListBox1.Items[ListBox1.ItemIndex];
  tmpStr:= tmpStr + ' - LOCKED';
  //post selected item back to list
  ListBox1.Items[ListBox1.ItemIndex]:= tmpStr;
  //turn back on control painting
  ListBox1.Items.EndUpdate;
  end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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