unit Unit1 interface uses Winapi Windows Winapi Messages System SysUti

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure refreshList;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
items:array[0..1000,0..1] of string;
implementation
{$R *.dfm}
function getLastId:integer;
var
i:integer;
begin
result:=-1;
for i := 0 to 1000 do
begin
if ((Items[i,0] = '') AND (Items[i,1] = '')) then
begin
result:=i;
break;
end;
end;
end;
procedure TForm1.refreshList;
var
i:integer;
begin
ListBox1.Clear;
for i := 0 to 1000 do
begin
if ((Items[i,0] = '') OR (Items[i,1] = '')) then break;
ListBox1.Items.Add(Items[i,0]+' ('+Items[i,1]+'р)');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
sum:integer;
begin
Memo1.Lines.Clear;
Memo1.Lines.Add('Товары:');
sum:=0;
for i := 0 to ListBox1.Items.Count-1 do
begin
if (ListBox1.Selected[i]) then
begin
Memo1.Lines.Add(ListBox1.Items[i]);
sum:=sum+StrToInt(Items[i,1]);
end;
end;
Label1.Caption:=IntToStr(sum);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
lastId:integer;
begin
lastId:=getLastId;
Items[lastId,0]:=Edit1.Text;
Items[lastId,1]:=Edit2.Text;
refreshList;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
Items[0,0]:='Хрень №1'; Items[0,1]:='20';
Items[1,0]:='Хрень №2'; Items[1,1]:='234';
Items[2,0]:='Хрень №3'; Items[2,1]:='102';
Items[3,0]:='Хрень №4'; Items[3,1]:='41';
Items[4,0]:='Хрень №5'; Items[4,1]:='32';
Items[5,0]:='Хрень №6'; Items[5,1]:='50';
refreshList;
end;
end.