这是自动出题的软件,麻烦高手注释一下红色字体函数function TForm1.GetMathunit untFrmMain;多谢interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RzLabel, Mask, RzEdit, RzButton, iniFiles, Math, ExtCtrls,
RzPanel;type
TForm1 = class(TForm)
RzPanel1: TRzPanel;
RzPanel2: TRzPanel;
RzBitBtn2: TRzBitBtn;
RzBitBtn1: TRzBitBtn;
pnlProblem: TRzPanel;
lbl1: TLabel;
lbl2: TLabel;
procedure FormCreate(Sender: TObject);
procedure RzBitBtn2Click(Sender: TObject);
procedure RzBitBtn1Click(Sender: TObject);
procedure RzNumericEdit1Enter(Sender: TObject);
procedure RzNumericEdit1MouseEnter(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
AppIniFile: TIniFile;
Function GetMath(var aMathProblem: string; aNumber: Integer;aAllowDigits:Boolean;
var aProblemResult: Double): Boolean;
end;var
Form1: TForm1;implementation{$R *.dfm}
{ TForm1 }
//Download by http://www.codefans.net
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
self.AppIniFile.UpdateFile;
self.AppIniFile.Free;
end;procedure TForm1.FormCreate(Sender: TObject);
var
MathProblem: string;
ProblemResult: Double;
MathProblemList, ProblemResultList: TstringList;
i, j: Integer;
NewLabel: TRzLabel;
NewResult: TRzNumericEdit;
Number: Integer;
AllowDigits:Boolean;
begin
self.BorderStyle := bsNone;
self.WindowState := wsmaximized;
self.AppIniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) +
'Config.ini');
if not fileexists(ExtractFilePath(Application.ExeName) + 'Config.ini') then
self.AppIniFile.WriteInteger('System', 'Number', 3);
AllowDigits:= Self.AppIniFile.ReadBool('system','allowDigits',false);
Number := self.AppIniFile.ReadInteger('System', 'Number', 3);
MathProblemList := TstringList.Create;
ProblemResultList := TstringList.Create;
for j := 0 to 2 do
begin
for i := 0 to 9 do
begin
self.GetMath(MathProblem, Number,AllowDigits, ProblemResult);
MathProblemList.Add(MathProblem);
ProblemResultList.Add(Floattostr(ProblemResult));
NewLabel := TRzLabel.Create(self);
NewLabel.Alignment := taLeftJustify;
NewLabel.AutoSize := false;
NewLabel.Caption := MathProblem;
NewLabel.Left := j * 350 + 10;
NewLabel.Top := i * 50 + 10;
NewLabel.Width := 240;
NewLabel.Height := 40;
NewLabel.Parent := pnlProblem;
NewLabel.Font.Size := 24;
NewLabel.Visible := true;
// NewLabel.Font.Name := '仿宋体'; NewResult := TRzNumericEdit.Create(self);
NewResult.Width := 60;
NewResult.Top := i * 50 + 10;
NewResult.Height := 40;
NewResult.Left := j * 380 + 220;
NewResult.Font.Size := 24;
// NewResult.Font.Name := '仿宋体';
NewResult.Parent := pnlProblem;
NewResult.Visible := true;
NewResult.DisplayFormat := ',0;(,0);';
NewResult.HelpKeyword := Floattostr(ProblemResult);
NewResult.OnEnter := RzNumericEdit1Enter;
end;
end;
MathProblemList.SaveToFile('d:\博旺数学题.txt');
ProblemResultList.SaveToFile('d:\答案.txt');
MathProblemList.Free;
end;function TForm1.GetMath(var aMathProblem: string; aNumber: Integer;aAllowDigits:Boolean;
var aProblemResult: Double): Boolean;
var
N1, N2, N3, TempResult: Double;
N: Array of Double;
i: Integer;
begin
SetLength(N, aNumber);
while 1 = 1 do
begin
// 初始化
for i := 0 to aNumber - 1 do
begin
N[i] := 0;
while N[i] < 10 do
begin
if aAllowDigits then
N[i] := roundto(random() * 100, -2)
else
N[i]:=RoundTo(Random()*100,0);
end;
end;
// 循环判断
N1 := N[0];
i := 1;
aMathProblem := Floattostr(N1);
while i < aNumber do
begin
N2 := N[i];
// 计算前2个数字
case random(2) of
0:
begin
TempResult := N1 + N2;
aMathProblem := aMathProblem + '+' + Floattostr(N2);
end;
1:
begin
TempResult := N1 - N2;
aMathProblem := aMathProblem + '-' + Floattostr(N2);
end;
end;
// 判断结果
if (TempResult > 100) or (TempResult <= 0) then
Break;
N1 := TempResult;
inc(i);
end;
// 判断最终结果
if (TempResult > 100) or (TempResult <= 0) then
continue
else
begin
aMathProblem := aMathProblem + '=';
aProblemResult := TempResult;
Break;
end;
end;
end;procedure TForm1.RzBitBtn1Click(Sender: TObject);
var
CurControl: TControl;
i: Integer;
CurValue: Double;
begin for i := 0 to pnlProblem.ControlCount - 1 do
begin
if pnlProblem.Controls[i].InheritsFrom(TRzNumericEdit) then
begin
try
CurValue := StrToFloat(TRzNumericEdit(pnlProblem.Controls[i])
.HelpKeyword);
if TRzNumericEdit(pnlProblem.Controls[i]).IntValue <> CurValue then
TRzNumericEdit(pnlProblem.Controls[i]).Font.Color := clred
else
TRzNumericEdit(pnlProblem.Controls[i]).Font.Color := clblack;
except
TRzNumericEdit(pnlProblem.Controls[i]).Font.Color := clred
end;
end;
end;
end;procedure TForm1.RzBitBtn2Click(Sender: TObject);
begin
self.Close;
end;procedure TForm1.RzNumericEdit1Enter(Sender: TObject);
begin
TRzNumericEdit(Sender).SelStart:=0;
TRzNumericEdit(Sender).SelectAll;
end;procedure TForm1.RzNumericEdit1MouseEnter(Sender: TObject);
begin
TRzNumericEdit(Sender).SelectAll;
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货