📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
StringGrid1: TStringGrid;
Button2: TButton;
GroupBox1: TGroupBox;
Panel1: TPanel;
GroupBox2: TGroupBox;
Label2: TLabel;
Label3: TLabel;
Panel2: TPanel;
Label1: TLabel;
Panel3: TPanel;
Label4: TLabel;
ListBox1: TListBox;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n,sygjgs:integer;
gjsj:array [0..1000] of single; // 工件数组
wlcd:single;
data:array [0..1000,0..20] of single; //所需物料数组,
implementation
{$R *.dfm}
procedure insert(n:integer;j:integer); //插入到二维数组
var
i:integer;
begin
for i:=0 to 20 do
begin
if data[j,i]=0 then
begin
data[j,i]:=gjsj[n];
exit;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject); //数据优化
var
i,j:integer;
s:array [0..500] of single;
temp:single;
str:string;
begin
wlcd:=strtofloat(edit1.text);
for i:=0 to 500 do
s[i]:=0;
for i:=0 to sygjgs do //从大到小排序
begin
for j:=i to sygjgs do
begin
if gjsj[i]<gjsj[j] then
begin
temp:=gjsj[i];
gjsj[i]:=gjsj[j];
gjsj[j]:=temp;
end;
end;
end;
for i:=0 to sygjgs-1 do //优化数据
begin
j:=0;
while (gjsj[i]+s[j])>wlcd do
begin
inc(j);
end;
s[j]:=s[j]+gjsj[i];
insert(i,j); //插入到二维数组
end;
for i:=0 to 1000 do
begin
for j:=0 to 20 do
begin
if data[i,j]<> 0 then
begin
str:=str+floattostr(data[i,j])+' ';
end;
if data[i,j]=0 then
begin
listbox1.Items.Add('第'+inttostr(i+1)+'根'+' '+str);
str:='';
break;
end;
end;
if data[i+1,0]=0 then
exit;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='工件长度';
StringGrid1.Cells[1,0]:='数量';
end;
procedure TForm1.Button2Click(Sender: TObject); //添加工件
var
gjcd:single;
i,gjgs:integer;
begin
inc(n);
StringGrid1.Cells[0,n]:=edit2.Text;
StringGrid1.Cells[1,n]:=edit3.text;
gjcd:=strtofloat(edit2.text);
gjgs:=strtoint(edit3.text);
for i:=sygjgs to gjgs+sygjgs-1 do
begin
gjsj[i]:=gjcd;
end;
sygjgs:=gjgs+sygjgs;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
form1.Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -