Задачка: погрузить груз заданной массы из таблицы на судно определенного тоннажа, вводимого или набираемого в ComboBox. Суть в том, что если тоннаж больше заданной величины груза в ячейки, то он должен перейти и погрузить груз из следующий и так далее пока не заполниться, а в ячейках с забранным грузом проставлять нули. Проблема заключается в том, что не всегда корректно происходит погрузка на разных значения и шаг не всегда происходит и еще вылезает постоянно знак минус. Как сделать добавление и удаление записей в таблице?
procedure TForm1.Button1Click(Sender: TObject); var x,y,y1,y2,y3:integer; a,a1,a2,a3:integer; begin x:=strtoint(ComboBox1.Text); //strtoint(Edit1.text); y:=strtoint(StringGrid1.Cells[2,1]); a:=(x-y); if y<=x then StringGrid1.Cells[2,1]:='0'; if y>=x then StringGrid1.Cells[2,1]:=inttostr(a); Edit2.Text:=inttostr(a); if a=0 then exit; if a<0 then exit;
begin a:=strtoint(Edit2.Text); //if a>0 then a:=a*(-1); y1:=strtoint(StringGrid1.Cells[2,2]); a1:=(a-y1); if y1<=a1 then StringGrid1.Cells[2,2]:='0'; if y1>=a1 then StringGrid1.Cells[2,2]:=inttostr(a1); Edit2.Text:=inttostr(a1); if a1=0 then exit; if a1<0 then exit;
begin a1:=strtoint(Edit2.Text); if a1>0 then a1:=a1*(-1); y2:=strtoint(StringGrid1.Cells[2,3]); a2:=(a1-y2); if y2<=a1 then StringGrid1.Cells[2,3]:='0'; if y2>=a1 then StringGrid1.Cells[2,3]:=inttostr(a2); Edit2.Text:=inttostr(a2); if a2=0 then exit; if a2<0 then exit;
begin a2:=strtoint(Edit2.Text); if a2>0 then a2:=a2*(-1); y3:=strtoint(StringGrid1.Cells[2,4]); a3:=(a2-y3); if y3<=a2 then StringGrid1.Cells[2,4]:='0'; if y3>=a2 then StringGrid1.Cells[2,4]:=inttostr(a2); end; end; end; end;
procedure TForm1.Button2Click(Sender: TObject); begin Close; end;
procedure TForm1.Button3Click(Sender: TObject); begin StringGrid1.Cells[0,0]:='Номер состава'; StringGrid1.Cells[0,1]:='434'; StringGrid1.Cells[0,2]:='285'; StringGrid1.Cells[0,3]:='013'; StringGrid1.Cells[0,4]:='202';