Borland Delphi 7“实际参数太多”然后重置文件

时间:2014-10-01 18:08:12

标签: delphi parameters reset pascal

它投掷了一个" 太多的实际论点"重置文件进行阅读时,在我脸上编译错误。

当省略" SaveFile"部分来自重置和关闭部分,它在执行时抛出了一堆IO错误104和105。

我错过了什么?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    BitBtn10: TBitBtn;
    BitBtn11: TBitBtn;
    BitBtn12: TBitBtn;
    BitBtn13: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
    procedure BitBtn9Click(Sender: TObject);
    procedure winnerCheck;
    procedure Reset;
    procedure BitBtn10Click(Sender: TObject);
    procedure BitBtn11Click(Sender: TObject);
    procedure ReadFile;
    procedure WriteFile;
    procedure BitBtn12Click(Sender: TObject);
    procedure BitBtn13Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }


  end;

var
  Form1: TForm1;
  total: Double;
  odd: Boolean;
  even: Boolean;
  Clicked1: Boolean;
  Clicked2: Boolean;
  Clicked3: Boolean;
  Clicked4: Boolean;
  Clicked5: Boolean;
  Clicked6: Boolean;
  Clicked7: Boolean;
  Clicked8: Boolean;
  Clicked9: Boolean;
  totalscore : Double;
  winnerX : Boolean;
  winnerO : Boolean;
  xwins : Double;
  owins : Double;
  Games : Double;
  Ties : Double;
  SaveFile : textfile;
  ln1,ln2,ln3,ln4,ln5 : String;
  lolol:Integer;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked1=false then
begin
if total=0 then BitBtn1.Caption:='X';
if total=2 then BitBtn1.Caption:='X';
if total=4 then BitBtn1.Caption:='X';
if total=6 then BitBtn1.Caption:='X';
if total=8 then BitBtn1.Caption:='X';
if total=1 then BitBtn1.Caption:='O';
if total=3 then BitBtn1.Caption:='O';
if total=5 then BitBtn1.Caption:='O';
if total=7 then BitBtn1.Caption:='O';
if total=9 then BitBtn1.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked1:=true;
winnerCheck;
end;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked2=false then
begin
if total=0 then BitBtn2.Caption:='X';
if total=2 then BitBtn2.Caption:='X';
if total=4 then BitBtn2.Caption:='X';
if total=6 then BitBtn2.Caption:='X';
if total=8 then BitBtn2.Caption:='X';
if total=1 then BitBtn2.Caption:='O';
if total=3 then BitBtn2.Caption:='O';
if total=5 then BitBtn2.Caption:='O';
if total=7 then BitBtn2.Caption:='O';
if total=9 then BitBtn2.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked2:=true;
winnerCheck;
end;
end;

//procedure setTotal(Sender: TObject);
//Label2.Caption:=floattostr(total);
//end;


procedure TForm1.Label2Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked3=false then
begin
if total=0 then BitBtn3.Caption:='X';
if total=2 then BitBtn3.Caption:='X';
if total=4 then BitBtn3.Caption:='X';
if total=6 then BitBtn3.Caption:='X';
if total=8 then BitBtn3.Caption:='X';
if total=1 then BitBtn3.Caption:='O';
if total=3 then BitBtn3.Caption:='O';
if total=5 then BitBtn3.Caption:='O';
if total=7 then BitBtn3.Caption:='O';
if total=9 then BitBtn3.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked3:=true;
winnerCheck;
end;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked4=false then
begin
if total=0 then BitBtn4.Caption:='X';
if total=2 then BitBtn4.Caption:='X';
if total=4 then BitBtn4.Caption:='X';
if total=6 then BitBtn4.Caption:='X';
if total=8 then BitBtn4.Caption:='X';
if total=1 then BitBtn4.Caption:='O';
if total=3 then BitBtn4.Caption:='O';
if total=5 then BitBtn4.Caption:='O';
if total=7 then BitBtn4.Caption:='O';
if total=9 then BitBtn4.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked4:=true;
winnerCheck;
end;
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked5=false then
begin
if total=0 then BitBtn5.Caption:='X';
if total=2 then BitBtn5.Caption:='X';
if total=4 then BitBtn5.Caption:='X';
if total=6 then BitBtn5.Caption:='X';
if total=8 then BitBtn5.Caption:='X';
if total=1 then BitBtn5.Caption:='O';
if total=3 then BitBtn5.Caption:='O';
if total=5 then BitBtn5.Caption:='O';
if total=7 then BitBtn5.Caption:='O';
if total=9 then BitBtn5.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked5:=true;
winnercheck;
end;
end;

procedure TForm1.BitBtn6Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked6=false then
begin
if total=0 then BitBtn6.Caption:='X';
if total=2 then BitBtn6.Caption:='X';
if total=4 then BitBtn6.Caption:='X';
if total=6 then BitBtn6.Caption:='X';
if total=8 then BitBtn6.Caption:='X';
if total=1 then BitBtn6.Caption:='O';
if total=3 then BitBtn6.Caption:='O';
if total=5 then BitBtn6.Caption:='O';
if total=7 then BitBtn6.Caption:='O';
if total=9 then BitBtn6.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked6:=true;
winnerCheck;
end;
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked7=false then
begin
if total=0 then BitBtn7.Caption:='X';
if total=2 then BitBtn7.Caption:='X';
if total=4 then BitBtn7.Caption:='X';
if total=6 then BitBtn7.Caption:='X';
if total=8 then BitBtn7.Caption:='X';
if total=1 then BitBtn7.Caption:='O';
if total=3 then BitBtn7.Caption:='O';
if total=5 then BitBtn7.Caption:='O';
if total=7 then BitBtn7.Caption:='O';
if total=9 then BitBtn7.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked7:=true;
winnerCheck;
end;
end;

procedure TForm1.BitBtn8Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked8=false then
begin
if total=0 then BitBtn8.Caption:='X';
if total=2 then BitBtn8.Caption:='X';
if total=4 then BitBtn8.Caption:='X';
if total=6 then BitBtn8.Caption:='X';
if total=8 then BitBtn8.Caption:='X';
if total=1 then BitBtn8.Caption:='O';
if total=3 then BitBtn8.Caption:='O';
if total=5 then BitBtn8.Caption:='O';
if total=7 then BitBtn8.Caption:='O';
if total=9 then BitBtn8.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked8:=true;
winnercheck;
end;
end;

procedure TForm1.BitBtn9Click(Sender: TObject);
begin
Label2.Caption:=floattostr(total);
if Clicked9=false then
begin
if total=0 then BitBtn9.Caption:='X';
if total=2 then BitBtn9.Caption:='X';
if total=4 then BitBtn9.Caption:='X';
if total=6 then BitBtn9.Caption:='X';
if total=8 then BitBtn9.Caption:='X';
if total=1 then BitBtn9.Caption:='O';
if total=3 then BitBtn9.Caption:='O';
if total=5 then BitBtn9.Caption:='O';
if total=7 then BitBtn9.Caption:='O';
if total=9 then BitBtn9.Caption:='O';
if total>=9 then total:=0;
total:= total+1;
Clicked9:=true;
winnerCheck;

end;
end;
procedure TForm1.winnerCheck;
begin
if ((Clicked1=true) and (BitBtn1.Caption='X')) and ((Clicked2=true) and (BitBtn2.Caption='X')) and ((Clicked3=true) and (BitBtn3.Caption='X')) then
begin
bitbtn1.font.color:= clgreen;
bitbtn2.font.color:= clgreen;
bitbtn3.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn1.font.color:= clblack;
bitbtn2.font.color:= clblack;
bitbtn3.font.color:= clblack;
end;
if ((Clicked1=true) and (BitBtn1.Caption='O')) and ((Clicked2=true) and (BitBtn2.Caption='O')) and ((Clicked3=true) and (BitBtn3.Caption='O')) then
begin
bitbtn1.font.color:= clgreen;
bitbtn2.font.color:= clgreen;
bitbtn3.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn1.font.color:= clblack;
bitbtn2.font.color:= clblack;
bitbtn3.font.color:= clblack;
end;
if ((Clicked4=true) and (BitBtn4.Caption='X')) and ((Clicked5=true) and (BitBtn5.Caption='X')) and ((Clicked6=true) and (BitBtn6.Caption='X')) then
begin
bitbtn4.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn6.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn4.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn6.font.color:= clblack;
end;
if ((Clicked4=true) and (BitBtn4.Caption='O')) and ((Clicked5=true) and (BitBtn5.Caption='O')) and ((Clicked6=true) and (BitBtn6.Caption='O')) then
begin
bitbtn4.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn6.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn4.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn6.font.color:= clblack;
end;
if ((Clicked7=true) and (BitBtn7.Caption='X')) and ((Clicked8=true) and (BitBtn8.Caption='X')) and ((Clicked9=true) and (BitBtn9.Caption='X')) then
begin
bitbtn7.font.color:= clgreen;
bitbtn8.font.color:= clgreen;
bitbtn9.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn7.font.color:= clblack;
bitbtn8.font.color:= clblack;
bitbtn9.font.color:= clblack;
end;
if ((Clicked7=true) and (BitBtn7.Caption='O')) and ((Clicked8=true) and (BitBtn8.Caption='O')) and ((Clicked9=true) and (BitBtn9.Caption='O')) then
begin
bitbtn7.font.color:= clgreen;
bitbtn8.font.color:= clgreen;
bitbtn9.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn7.font.color:= clblack;
bitbtn8.font.color:= clblack;
bitbtn9.font.color:= clblack;
end;
if ((Clicked1=true) and (BitBtn1.Caption='X')) and ((Clicked4=true) and (BitBtn4.Caption='X')) and ((Clicked7=true) and (BitBtn7.Caption='X')) then
begin
bitbtn1.font.color:= clgreen;
bitbtn4.font.color:= clgreen;
bitbtn7.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn1.font.color:= clblack;
bitbtn4.font.color:= clblack;
bitbtn7.font.color:= clblack;
end;
if ((Clicked1=true) and (BitBtn1.Caption='O')) and ((Clicked4=true) and (BitBtn4.Caption='O')) and ((Clicked7=true) and (BitBtn7.Caption='O')) then
begin
bitbtn1.font.color:= clgreen;
bitbtn4.font.color:= clgreen;
bitbtn7.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn1.font.color:= clblack;
bitbtn4.font.color:= clblack;
bitbtn7.font.color:= clblack;
end;
if ((Clicked2=true) and (BitBtn2.Caption='X')) and ((Clicked5=true) and (BitBtn5.Caption='X')) and ((Clicked8=true) and (BitBtn8.Caption='X')) then
begin
bitbtn2.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn8.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn2.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn8.font.color:= clblack;
end;
if ((Clicked2=true) and (BitBtn2.Caption='O')) and ((Clicked5=true) and (BitBtn5.Caption='O')) and ((Clicked8=true) and (BitBtn8.Caption='O')) then
begin
bitbtn2.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn8.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn2.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn8.font.color:= clblack;
end;
if ((Clicked3=true) and (BitBtn3.Caption='X')) and ((Clicked6=true) and (BitBtn6.Caption='X')) and ((Clicked9=true) and (BitBtn9.Caption='X')) then
begin
bitbtn3.font.color:= clgreen;
bitbtn6.font.color:= clgreen;
bitbtn9.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn3.font.color:= clblack;
bitbtn6.font.color:= clblack;
bitbtn9.font.color:= clblack;
end;
if ((Clicked3=true) and (BitBtn3.Caption='O')) and ((Clicked6=true) and (BitBtn6.Caption='O')) and ((Clicked9=true) and (BitBtn9.Caption='O')) then
begin
bitbtn3.font.color:= clgreen;
bitbtn6.font.color:= clgreen;
bitbtn9.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn3.font.color:= clblack;
bitbtn6.font.color:= clblack;
bitbtn9.font.color:= clblack;
end;
if ((Clicked1=true) and (BitBtn1.Caption='X')) and ((Clicked5=true) and (BitBtn5.Caption='X')) and ((Clicked9=true) and (BitBtn9.Caption='X')) then
begin
bitbtn1.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn9.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn1.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn9.font.color:= clblack;
end;
if ((Clicked1=true) and (BitBtn1.Caption='O')) and ((Clicked5=true) and (BitBtn5.Caption='O')) and ((Clicked9=true) and (BitBtn9.Caption='O')) then
begin
bitbtn1.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn9.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn1.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn9.font.color:= clblack;
end;
if ((Clicked3=true) and (BitBtn3.Caption='X')) and ((Clicked5=true) and (BitBtn5.Caption='X')) and ((Clicked7=true) and (BitBtn7.Caption='X')) then
begin
bitbtn3.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn7.font.color:= clgreen;
showMessage('Speler X heeft gewonnen!');
winnerX:=true;
bitbtn3.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn7.font.color:= clblack;
end;
if ((Clicked3=true) and (BitBtn3.Caption='O')) and ((Clicked5=true) and (BitBtn5.Caption='O')) and ((Clicked7=true) and (BitBtn7.Caption='O')) then
begin
bitbtn3.font.color:= clgreen;
bitbtn5.font.color:= clgreen;
bitbtn7.font.color:= clgreen;
showMessage('Speler O heeft gewonnen!');
WinnerO:=true;
bitbtn3.font.color:= clblack;
bitbtn5.font.color:= clblack;
bitbtn7.font.color:= clblack;
end
else if ((clicked1=true) and (clicked2=true) and (clicked3=true) and (clicked4=true) and (clicked5=true) and (clicked6=true) and (clicked7=true) and (clicked8=true) and (clicked9=true) and (WinnerX=false) and (WinnerO=false)) then
begin
Ties:= ties+1;
Label1.Caption:=floattostr(ties);
showmessage('Gelijk spel!');
reset;
end;
if WinnerO=true then
begin
owins:=strtofloat(Label7.Caption);
Label7.Caption:=floattostr(owins+1);
Reset;
end;
if WinnerX=true then
begin
xwins:=strtofloat(Label6.Caption);
Label6.Caption:=floattostr(xwins+1);
Reset;
end;

end;

procedure TForm1.Reset;
begin
BitBtn1.Caption:='';
BitBtn2.Caption:='';
BitBtn3.Caption:='';
BitBtn4.Caption:='';
BitBtn5.Caption:='';
BitBtn6.Caption:='';
BitBtn7.Caption:='';
BitBtn8.Caption:='';
BitBtn9.Caption:='';
total:=0;
Label2.Caption:='0';
WinnerX:=false;
WinnerO:=false;
Games:= Games+1;
Label3.Caption:=floattostr(Games);
Clicked1:=false;
Clicked2:=false;
Clicked3:=false;
Clicked4:=false;
Clicked5:=false;
Clicked6:=false;
Clicked7:=false;
Clicked8:=false;
Clicked9:=false;

end;

procedure TForm1.BitBtn10Click(Sender: TObject);
begin
Reset;
end;

procedure TForm1.BitBtn11Click(Sender: TObject);
begin
reset;
label3.caption:='0';
label6.caption:='0';
label7.caption:='0';
label1.Caption:='0';
xwins:=0;
owins:=0;
end;

procedure TForm1.ReadFile;
begin
assignfile(SaveFile, 'SaveFile.txt');
{$I+} //to use exceptions
try
  System.Reset(SaveFile);
  Readln(SaveFile, ln1); //X
  Label6.Caption:=ln1;
  xwins:=strtofloat(ln1);
  Readln(SaveFile, ln2); //O
  Label7.Caption:=ln2;
  owins:=strtofloat(ln2);
  Readln(SaveFile, ln3); //Ties
  Label1.Caption:=ln3;
  ties:=strtofloat(ln3);
  Readln(SaveFile, ln4); //Amt Total
  Label2.Caption:=ln4;
  total:=strtofloat(ln4);
  Readln(SaveFile, ln5); //Amt Games
  Label3.Caption:=ln5;
  Games:=strtofloat(ln5);
  System.Close(SaveFile);
except
writeln('Doetniemeer');
end;

end;


procedure TForm1.WriteFile;
begin
assignfile(SaveFile, 'SaveFile.txt');
{$I+} //to use exceptions'n shit
try
  Rewrite(SaveFile);
  writeln(SaveFile, Label6.Caption); //Score X
  writeln(SaveFile, Label7.Caption); //Score O
  writeln(SaveFile, Label1.Caption); //Ties
  writeln(SaveFile, Label2.Caption); //Total Amount (1-9) Likely due to be 0 because... it just is
  writeln(SaveFile, Label3.Caption); //Amt. Games
  CloseFile(SaveFile);
except

on E: EInOutError do writeln('Doetniemeer '+E.Message);
end;

end;
procedure TForm1.BitBtn12Click(Sender: TObject);
begin
WriteFile;
end;

procedure TForm1.BitBtn13Click(Sender: TObject);
begin
ReadFile;
end;

end.




// if total>=9 then total:=0;
// if total=1 then odd:=true;
// if total=3 then odd:=true;
// if total=5 then odd:=true;
// if total=7 then odd:=true;
// if total=9 then odd:=true;
// if total=0 then even:=true;
// if total=2 then even:=true;
// if total=4 then even:=true;
// if total=6 then even:=true;
// if total=8 then even:=true;
// total:=total+1;
// if odd then BitBtn1.Caption:='X';
// if even then BitBtn1.Caption:= 'O';

1 个答案:

答案 0 :(得分:4)

您收到错误,因为您的表单有自己的Reset()方法,不带任何参数:

procedure Reset;

编译器正在尝试调用该方法而不是System.Reset()函数。

因此,要么将TForm1.Reset()方法重命名为其他方法,要么使用Reset(SaveFile)前缀限定System.调用,以便编译器知道需要调用哪个Reset()。< / p>