unit Unit4;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.Buttons, Vcl.StdCtrls,
Vcl.Mask, Vcl.DBCtrls;
type
TForm3 = class(TForm)
lv1: TListView;
add: TButton;
delete: TButton;
procedure addClick(Sender: TObject);
procedure DeleteClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.addClick(Sender: TObject);
var
i:Integer;
ListItem:TListItem;
a,a1,s,s1:string;
d,b,c:Double;
begin
i := lv1.Items.Count;
with lv1 do
begin
ListItem:=Items.Add;
ListItem.Caption:= IntToStr(i+1);
a:= InputBox('输入科目','','');
ListItem.SubItems.Add(a);
s:= inputbox('输入数量','','');
b:=StrToFloat(s);
ListItem.SubItems.Add(FloatToStr(b));
s1:= inputbox('输入单价','','');
c:= StrToFloat(s1);
ListItem.SubItems.Add(FloatToStr(c));
d:= b * c;
ListItem.SubItems.Add(FloatToStr(d));
end;
Refresh;
end;
procedure TForm3.deleteClick(Sender: TObject);
var
i:Integer;
Edit1:TEdit;
begin
for i:=lv1.Items.Count-1 downto 0 Do
if lv1.Items[i].Caption = Edit1.Text then
begin
lv1.Items.Item[i].Delete(); //删除当前选中行
end;
//选中一行
if lv1.Selected <> nil then
Edit1.Text := lv1.Selected.Caption;
end;
end.