?
Solved

Deleting in TStrings

Posted on 2003-03-20
3
Medium Priority
?
252 Views
Last Modified: 2012-05-04
Hi,

I have TStrings like this :

a=apple
b=orange
c=frog

Anyone can help, how can I delete an entry based on the LEFT side string?

Like this :

   function deletestring(leftkey: string; T: TStrings) : boolean;

So, I can use it like this :

   if (deletestring("b", T)) then ... it's deleted

Thanks.
0
Comment
Question by:db2trade
[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 9

Accepted Solution

by:
mocarts earned 80 total points
ID: 8173803
function deletestring(const leftkey: string; T: TStrings): boolean;
var
 idx: integer;
begin
 idx := T.indexOfName(leftKey);
 Result := (idx > -1);
 if Result then
  T.Delete(idx);
end;

wbr, mo.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8173812
maybe this ?

function DeleteString(leftkey: string; T: TStrings) : boolean;
var i : integer;
begin
  i := t.indexOfName(leftKey);
  if i > -1 then
    t.Delete(i);
  result := i > -1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if DeleteString(edit1.text, listbox1.items) then
    ShowMessage('String deleted')
  else
    ShowMessage('No such String available');
end;

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8173814
puu, too late :-(
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 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