📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, ExtCtrls, Grids, Buttons;
//const long=5;
type
TForm1 = class(TForm)
Panel2: TPanel;
Label1: TLabel;
Label2: TLabel;
Panel4: TPanel;
StringGrid2: TStringGrid;
Edit1: TEdit;
Edit2: TEdit;
Panel5: TPanel;
BitBtn1: TBitBtn;
Panel6: TPanel;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
RadioGroup1: TRadioGroup;
BitBtn4: TBitBtn;
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure chushihuabianliang;
var i,j:Integer;
begin
for i:=1 to long do
for j:=1 to long do
a[i,j]:=0;
for i:=1 to long do
begin
b[i]:=0;
opt[i]:=0;
end;
for j:=1 to long do
begin
c[j]:=0;
x[j]:=0;
end;
end;
{------------初始化变量-------------------------}
procedure TForm1.BitBtn2Click(Sender: TObject);
var i,j:integer;
begin
try
VarNum:=strtoint(edit1.text);
ConNum:=strtoint(edit2.text); {输入变量个数和约束条件个数}
except
showmessage('输入有误!'+#13+'请确定您输入的是整数并且没有空格');
//纠错
end;
stringgrid2.ColCount:=VarNum+3;
stringgrid2.RowCount:=ConNum+2;
stringgrid2.Cells[0,0]:='约束\变量';
stringgrid2.Cells[0,ConNum+1]:='目标函数';
//表格的列数=变量数+3;第一列用作标签,最后两列为运算符及常数项 }
for j:=1 to VarNum do
stringgrid2.Cells[j,0]:='X'+inttostr(j);
//表格外观,第一行、第一列用作标签.第一行显示变量名
for i:=1 to ConNum do
StringGrid2.Cells[0,i]:='约束 '+IntToStr(i);
stringgrid2.Cells[VarNum+1,0]:= '运算符';
//表格第一行倒数第二列,显示约束条件中的运算符
stringgrid2.Cells[VarNum+2,0]:='b';
//表格第一行最后一列,显示约束条件的常数项b
StringGrid2.SetFocus;
end;
{----------设置数据输入界面-----------------------}
procedure duqushuju;
var i,j:Integer;
begin
for i:=1 to ConNum do
for j:=1 to VarNum do
if Form1.StringGrid2.Cells[j,i]<>'' then
a[i,j]:=StrToFloat(Form1.StringGrid2.Cells[j,i]);
//读取系数矩阵
for i:=1 to ConNum do
if Form1.StringGrid2.Cells[VarNum+2,i]<>'' then
b[i]:=StrToFloat(Form1.StringGrid2.Cells[varnum+2,i]);
//读取限定向量
for i:=1 to ConNum do
if Form1.StringGrid2.Cells[VarNum+1,i]<>'' then
opt[i]:=StrToInt(Form1.StringGrid2.Cells[varnum+1,i]);
//读取操作符
for j:=1 to VarNum do
if Form1.StringGrid2.Cells[j,ConNum+1]<>'' then
c[j]:=StrToFloat(Form1.StringGrid2.Cells[j,ConNum+1]);
//读取目标函数系数
end;
{----------读取文本框中的数据-----------------------}
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
chushihuabianliang;//自定义过程,初始化变量
RadioGroup1Click(Sender);//改变目标函数类型
duqushuju;//自定义过程,读取输入的数据
form2.show;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex=0 then
leixing:='Max'
else
leixing:='Min';
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
var i,j:Integer;
begin
for i:=1 to StringGrid2.RowCount-1 do
for j:=1 to StringGrid2.ColCount-1 do
StringGrid2.Cells[j,i]:='';
//清空文本框的数据
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -