自己循环判断: function TForm1.GetLastIndex(s: string): Integer; var i: Integer; begin for i := ListBox1.Count - 1 downto 0 do if ListBox1.Items[i] = '3' then Break; Result := i; end;procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(GetLastIndex('3'))); end;
上面的'3'改为s,这样: function TForm1.GetLastIndex(s: string): Integer; var i: Integer; begin for i := ListBox1.Count - 1 downto 0 do if ListBox1.Items[i] = s then Break; Result := i; end;procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(GetLastIndex('3'))); end;
var i,n:integer; begin n:=listbox1.Items.Count; i:=n-1; while i>0 do begin if listbox1.Items.Strings[i]='3' then begin n:=i; i:=0; end; i:=i-1; end; end; n为所求值
var i,n:integer; begin n:=listbox1.Items.Count; i:=n-1; while i>0 do begin if listbox1.Items.Strings[i]='3' then begin n:=i; i:=0; end; i:=i-1; end; end;主要是循环,如果某一项的值为3,记下这一项的行号
function TForm1.GetLastIndex(s: string): Integer;
var i: Integer;
begin
for i := ListBox1.Count - 1 downto 0 do
if ListBox1.Items[i] = '3' then Break;
Result := i;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(GetLastIndex('3')));
end;
function TForm1.GetLastIndex(s: string): Integer;
var i: Integer;
begin
for i := ListBox1.Count - 1 downto 0 do
if ListBox1.Items[i] = s then Break;
Result := i;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(GetLastIndex('3')));
end;
begin
n:=listbox1.Items.Count;
i:=n-1;
while i>0 do
begin
if listbox1.Items.Strings[i]='3' then
begin
n:=i;
i:=0;
end;
i:=i-1;
end;
end;
n为所求值
begin
n:=listbox1.Items.Count;
i:=n-1;
while i>0 do
begin
if listbox1.Items.Strings[i]='3' then
begin
n:=i;
i:=0;
end;
i:=i-1;
end;
end;主要是循环,如果某一项的值为3,记下这一项的行号