fastxbl
asked on
how to delete from listbox using edit box
Hi i have almost made the code to delete from listbox using data from text field, but i am missing the part that needs to say "its not there".
I mean, i need my code to say "if the text is not in the listbox show message "not there", to avoid having a list index out of bounce.
here is my code and i have marked the part i need done
procedure TForm13.unbannickClick(Sen der: TObject);
begin
if form15.ListBox1.Items.Text =(form13.D Bname.text )
then begin
form15.listBox1.Items.Dele te(form15. listbox1.I tems.Index Of(DBname. text))
end else begin
****(If the name thats in the text box is not in listbox1)
THEN begin
showmessage(' Nothing there');
END;
end;
end.
I mean, i need my code to say "if the text is not in the listbox show message "not there", to avoid having a list index out of bounce.
here is my code and i have marked the part i need done
procedure TForm13.unbannickClick(Sen
begin
if form15.ListBox1.Items.Text
then begin
form15.listBox1.Items.Dele
end else begin
****(If the name thats in the text box is not in listbox1)
THEN begin
showmessage(' Nothing there');
END;
end;
end.
ASKER
Thanks, i did that but same thing happens, it shows nothing there message fine when nothing is there, but also shows same thing when it exsists and doesnt delete it.
it wouldnt compile, so i had to change
if form15.listBox1.IndexOf(fo rm13.DBnam e.text) > - 1 then
to
if form15.listBox1.items.Inde xOf(form13 .DBname.te xt) > - 1 then
it wouldnt compile, so i had to change
if form15.listBox1.IndexOf(fo
to
if form15.listBox1.items.Inde
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hint 1:
rename your forms and components
especially if this is a program which will be used by others
you will be trying to translate the chat form or nick list form to a Form15 or Form13
your users will think you are talking chinese to them if you talk about Form15 and Form13
hint 2:
in methods (procedures or functions of a class), do not refer to the instance of that class
use self instead ... or don't use any reference at all
delphi follows the scope starting local and then expanding globally to look for a variable/procedure/functio n, ... etc
sample of what will easily break your code:
Form15 := TForm13.Create(application )
Form13 := TForm15.Create(application )
hint3:
use indentation
hint4:
use of placement of then, else, begin, end, etc ... keep the structures always the same, don't start mixing, or your eyes are going to hurt after 20 minutes of writing code
>> i usually find errors within seconds, if hint3 and 4 are followed
hint5:
capitalization helps for easy reading
you code improved with all hints:
>> Assume Form13 = TfrmChat and Form15 = TfrmNicks, ListBox1 = lbNicks
rename your forms and components
especially if this is a program which will be used by others
you will be trying to translate the chat form or nick list form to a Form15 or Form13
your users will think you are talking chinese to them if you talk about Form15 and Form13
hint 2:
in methods (procedures or functions of a class), do not refer to the instance of that class
use self instead ... or don't use any reference at all
delphi follows the scope starting local and then expanding globally to look for a variable/procedure/functio
sample of what will easily break your code:
Form15 := TForm13.Create(application
Form13 := TForm15.Create(application
hint3:
use indentation
hint4:
use of placement of then, else, begin, end, etc ... keep the structures always the same, don't start mixing, or your eyes are going to hurt after 20 minutes of writing code
>> i usually find errors within seconds, if hint3 and 4 are followed
hint5:
capitalization helps for easy reading
you code improved with all hints:
>> Assume Form13 = TfrmChat and Form15 = TfrmNicks, ListBox1 = lbNicks
procedure TfrmChat.UnbanNickClick(Sender: TObject);
var y: integer;
begin
y := frmNicks.lbNicks.Items.IndexOf(dbName.text);
if y <> -1 then
frmNicks.lbNicks.Items.Delete(y)
else
ShowMessage('Nothing found in nick names list');
end;
procedure TForm13.unbannickClick(Sen
begin
if form15.ListBox1.Items.Text
then begin
if form15.listBox1.IndexOf(fo
form15.listBox1.Items.Dele
end else begin
showmessage(' Nothing there');
END;
end;
end.