Delphi de ListBox ta Arama Yapmak
Merhaba arkadaşlar bu makalemizde Edit nesnesine girilen metini Listbox nesnesinde arama yapacağız.
İlk önce Delphi formumuza Edit, Listbox ve Button ekliyoruz. Aşağıdaki kod parçasını buttonun click olayına yazacağız.
Şekil 1
unit listbox_Unit1; interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Gr
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); var
i:integer;
begin
for i := 0 to ListBox1.items.Count -1 do if Pos(Edit1.Text,ListBox1.Items.Strings[i])>0 then begin
if Edit1.Text=ListBox1.Items.Strings[i] then
Listbox1.Selected[i]:= True;
Showmessage('Kayıt bulundu.');
exit;
end
else
Listbox1.Selected[i]:= False; Showmessage('Kayıt bulunmamaktadır.');
exit;
end;
end.
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN