?? 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 + -