Solved

Editing Listbox at runtime 2

Posted on 2004-03-27
3
239 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
  • 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 105
Wininet read php file from internet issue 6 81
Working this component WebCopy with proxy, help 3 76
Delphi 2 49
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now