#4 Sniper
No, je toho trochu víc, není to dodělaný a jsou v tom chyby o kterých vím...
Form1:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Buttons;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
i: integer;
j: integer; //pocitadlo spravne vypocitanych prikladu
k: integer; //pocitadlo celkove vypocitanych prikladu
x, y, POKUS, VYSLEDEK: array[1..50] of integer;
implementation
{$R *.lfm}
{ TForm1 }
var soubor1:TextFile;
procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.Visible:=false;
Image2.Visible:=false;
Button1.Enabled:=false;
i:=1;
j:=0;
k:=0;
randomize;
x[i]:=random(10);
y[i] :=random(10);
VYSLEDEK[i]:= x[i]*y[i];
Label1.Caption := inttostr(x[i])+ ' × ' + inttostr(y[i])+' = ';
Label2.Caption := inttostr(i);
AssignFile(soubor1,'casy.txt');
Rewrite (soubor1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:='';
i:=i+1;
randomize;
x[i]:=random(10);
y[i] :=random(10);
VYSLEDEK[i]:= x[i]* y[i];
Label1.Caption := inttostr(x[i])+ ' × ' + inttostr(y[i])+' = ';
Label2.Caption := inttostr(i);
Image1.Visible:=false;
Image2.Visible:=false;
Image3.Visible:=false;
Button1.Enabled:=false;
k:=i+1;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage ('Celkem jsi spočítal '+ inttostr(k-1) +' příkladů.'+ ' Z toho správně '+ inttostr(j) + '.');
writeln (soubor1,'Celkem příkladů: '+ inttostr(k-1) +'.'+ ' Z toho správně: '+ inttostr(j)+ '.');
Form1.Close;
CloseFile (soubor1);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Image1.Visible:=true;
Button1.Enabled:=true;
POKUS [i]:= strtoint (Edit1.Text);
if VYSLEDEK [i] = POKUS [i]
then j:=j+1;
if VYSLEDEK [i] <> POKUS [i]
then
begin
Image1.Visible:=false;
Image2.Visible:=true;
Image3.Visible:=true;
Image3.Canvas.Rectangle(-1,-1,Image3.Width+1,Image3.Height+1);
Image3.Canvas.Font.Color:=clRed;
Image3.Canvas.Font.Size:=15;
Image3.Canvas.Font.Name:='Arial';
Image3.Canvas.TextOut(0,0,'Ne, správný výsledek je: ');
Image3.Canvas.TextOut(230,0,IntToStr (VYSLEDEK[i]));
end
else Image1.Visible:=true;
writeln (soubor1,Label1.Caption + Edit1.Caption);
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
end;
end.
Form2:
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TForm2 }
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form2: TForm2;
i: integer;
j: integer; //pocitadlo spravne vypocitanych prikladu
k: integer; //pocitadlo celkove vypocitanych prikladu
x, y, POKUS, VYSLEDEK: array[1..50] of integer;
implementation
{$R *.lfm}
{ TForm2 }
var soubor2:TextFile;
procedure TForm2.FormCreate(Sender: TObject);
begin
Image1.Visible:=false;
Image2.Visible:=false;
Button1.Enabled:=false;
i:=1;
j:=0;
k:=0;
randomize;
x[i]:=random(10);
y[i] :=random(10);
if y[i]=0 then
y[i]:=random(10);
VYSLEDEK[i]:= x[i]*y[i];
Label1.Caption := inttostr(VYSLEDEK[i])+ ' : ' + inttostr(y[i])+' = ';
Label2.Caption := inttostr(i);
AssignFile(soubor2,'casy.txt');
Rewrite (soubor2);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Edit1.Text:='';
i:=i+1;
randomize;
x[i]:=random(10);
y[i] :=random(10);
if y[i]=0 then
y[i]:= random (10);
VYSLEDEK[i]:= x[i]* y[i];
Label1.Caption := inttostr(VYSLEDEK[i])+ ' : ' + inttostr(y[i])+' = ';
Label2.Caption := inttostr(i);
Image1.Visible:=false;
Image2.Visible:=false;
Image3.Visible:=false;
Button1.Enabled:=false;
k:=i+1;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
ShowMessage ('Celkem jsi spočítal '+ inttostr(k-1) +' příkladů.'+ ' Z toho správně '+ inttostr(j) + '.');
writeln (soubor2,'Celkem příkladů: '+ inttostr(k-1) +'.'+ ' Z toho správně: '+ inttostr(j)+ '.');
Form2.Close;
CloseFile (soubor2);
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
Image1.Visible:=true;
Button1.Enabled:=true;
POKUS [i]:= strtoint (Edit1.Text);
if x[i] = POKUS [i]
then j:=j+1;
if x [i] <> POKUS [i]
then
begin
Image1.Visible:=false;
Image2.Visible:=true;
Image3.Visible:=true;
Image3.Canvas.Rectangle(-1,-1,Image3.Width+1,Image3.Height+1);
Image3.Canvas.Font.Color:=clRed;
Image3.Canvas.Font.Size:=15;
Image3.Canvas.Font.Name:='Arial';
Image3.Canvas.TextOut(0,0,'Ne, správný výsledek je: ');
Image3.Canvas.TextOut(230,0,IntToStr (x[i]));
end
else Image1.Visible:=true;
writeln (soubor2,Label1.Caption + Edit1.Caption);
end;
end.
Form3 (hlavní form, ze kterýho se má "přepínat" na Form1 a Form2
unit Unit3;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
ExtCtrls, StdCtrls;
type
{ TForm3 }
TForm3 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.lfm}
Uses
Unit1, Unit2;
{ TForm3 }
procedure TForm3.Button1Click(Sender: TObject);
begin
Form1.Show;
Form3.Hide;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
Form2.Show;
Form3.Hide;
end;
end.
Project1:
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Unit1, Unit2, Unit3
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm2, Form2); //chyba???
Application.CreateForm(TForm1, Form1); //chyba???
Application.Run;
end.
A tady na konci je asi ta chyba, pokud přehodím pořadí, funguje ten Form1, ale ne Form2. Fakt nevím!!!
Díky moc.