listbox1有N行字符串. listbox2里有400行字符串.
我要把listbox1的每一行 都跟listbox2的400行进行比较.(listbox400行是变化的)1.例如:按钮button1按下: 如果listbox1的第8行=listbox2.items.string[n] 就得到listbox1的选中行号8并break.
2.button1再次按下listbox1就从第9行起开始比较,有相等结果就就得到listbox1的选中行号并break;以此类推. 如果listbox1的所有行都比较不等就退出循环. 比较完后,button1再按下又循环从第一行开始比较
我要把listbox1的每一行 都跟listbox2的400行进行比较.(listbox400行是变化的)1.例如:按钮button1按下: 如果listbox1的第8行=listbox2.items.string[n] 就得到listbox1的选中行号8并break.
2.button1再次按下listbox1就从第9行起开始比较,有相等结果就就得到listbox1的选中行号并break;以此类推. 如果listbox1的所有行都比较不等就退出循环. 比较完后,button1再按下又循环从第一行开始比较
解决方案 »
- 如何把宽带连接设置为共享?
- 关于dbgrid的数据获取问题
- 关于MouseDown事件的奇怪问题
- delphi(自学)新手!!高手请指教如何快速的高效率的学习delphi??谢谢!!!谢谢!!!!
- 请问谁知道那里有Delphi6官方简体中文版下载阿?
- 高分求教关于窗体的问题
- 获得操作系统的信息(98 or 2000)?
- 已经安装过FAST REPORT很多次了,但今天去别人单位竟然安装不上,老提示什么'VCL' not found
- 为什么现在用DELPHI的人越来越多啊??
- 我的odbc出问题了
- 关于在已经添加CheckBox的TreeView中响应MouseUp事件的提问
- PageControl问题!!!!!!!!!!!!!!!!!!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
gIndex : integer;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
for i := gIndex to ListBox1.Items.Count -1 do
begin
if ListBox2.Items.IndexOf(Trim(ListBox1.Items.Strings[i])) <> -1 then
begin
ShowMessage('ListBox1中的 '+ListBox1.Items.Strings[i]+' 在listbox2中存在');
gIndex := i + 1;
break;
end;
end;end;procedure TForm1.FormCreate(Sender: TObject);
begin
gIndex := 0;
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
if ListBox1.ItemIndex = -1 then ListBox1.ItemIndex := 0;
for i := ListBox1.ItemIndex to ListBox1.Items.Count -1 do
begin
if ListBox2.Items.IndexOf(Trim(ListBox1.Items.Strings[i])) <> -1 then
begin
ShowMessage('ListBox1中的 '+ListBox1.Items.Strings[i]+' 在listbox2中存在');
ListBox1.ItemIndex := i+1;
break;
end;
end;end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.ItemIndex := 0;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
if ListBox1.ItemIndex = -1 then ListBox1.ItemIndex := 0;
for i := ListBox1.ItemIndex to ListBox1.Items.Count -1 do
begin
if ListBox2.Items.IndexOf(Trim(ListBox1.Items.Strings[i])) <> -1 then
begin
ShowMessage('ListBox1中的 '+ListBox1.Items.Strings[i]+' 在listbox2中存在');
if i = ListBox1.Count -1 then ListBox1.ItemIndex := 0 else
ListBox1.ItemIndex := i+1;
break;
end;
end; if i = ListBox1.Count then ListBox1.ItemIndex := 0;end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.ItemIndex := 0;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
if ListBox1.ItemIndex = -1 then ListBox1.ItemIndex := 0;
for i := ListBox1.ItemIndex to ListBox1.Items.Count -1 do
begin
if ListBox2.Items.IndexOf(Trim(ListBox1.Items.Strings[i])) <> -1 then
begin
ListBox2.ItemIndex := ListBox2.Items.IndexOf(Trim(ListBox1.Items.Strings[i]));
ShowMessage('ListBox1中的 '+ListBox1.Items.Strings[i]+' 在listbox2的第'+IntTostr(ListBox2.Itemindex+1)+'行');
if i = ListBox1.Count -1 then ListBox1.ItemIndex := 0 else
ListBox1.ItemIndex := i+1;
break;
end;
end; if i = ListBox1.Count then ListBox1.ItemIndex := 0;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.ItemIndex := 0;end;end.