gpt4 book ai didi

delphi - 如何解决delphi中的I/O错误103

转载 作者:行者123 更新时间:2023-12-03 18:27:04 25 4
gpt4 key购买 nike

所以基本上我在英国上大学(那是美国人(17 岁)的学校),我必须为我的期末考试做一个文件处理项目。我已经完成了其中的大部分工作,但让我很沮丧的是登录屏幕。我想让程序做的是读取用户名和密码并让人们登录。可以有 2 个不同的输出。如果您在用户名中键入“Staff”并在用户名中键入“warwickschool2013”​​,程序会将您带到程序的“教师”端,他们可以在其中添加新用户。

unit LoginScreen;
interface

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

type
TfrmLogin = class(TForm)
lblWelcomeLogin: TLabel;
edtPassword: TEdit;
lblPassword: TLabel;
btnLogin: TButton;
btnClose: TButton;
lblCounter: TLabel;
lblAttempts: TLabel;
Image1: TImage;
edtUsername: TEdit;
lblUserName: TLabel;
procedure btnCloseClick(Sender: TObject);
procedure btnLoginClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmLogin: TfrmLogin;


implementation
uses MainMenu, TeachersMainMenu, ViewEditTheData, Globals_Unit;
var
LoginDataArray: array of TLoginData;
counter: integer;
Password, username : String;
Count1, Count2 : integer;
Temp: TLoginData;

{$R *.dfm}

procedure TfrmLogin.btnLoginClick(Sender: TObject);
var
SearchName : string[10];
SearchCode : string[3];
begin
Password:=edtPassword.Text;
UserName:=edtUserName.Text;
btnclose.enabled:= true;
if (Password = 'warwickschool2013') AND (Username = 'Staff') then
begin
edtPassword.text :='';
frmTeachersMainMenu.show;
frmLogin.hide;
counter:= 0;
lblCounter.caption := IntToStr(Counter);
end
else
begin
assignfile (LoginDatafile,'C:\Users\NinjaBoffin\Desktop\Delphi\DataFiles\LoginData.txt');
reset (LoginDatafile);
LoginDatacounter := FileSize(LoginDatafile);
SetLength(LoginDataArray, LoginDatacounter);
edtPassword.clear;
edtUserName.Clear;
for Count1 := 1 to LoginDataCounter do
begin
read(LoginDatafile,SingleLoginData);
LoginDataArray[Count1] := SingleLoginData;
end;
closefile (LoginDatafile);

//bubble sort
edtUserName.Clear;
for count1 := 1 to LoginDatacounter-1 do
for count2 := 1 to LoginDatacounter-1 do
if LoginDataArray[count2].UserName > LoginDataArray[count2+1].UserName then
begin
temp := LoginDataArray[count2+1];
LoginDataArray[count2+1] := LoginDataArray[count2];
LoginDataArray[count2] := temp;
end;
//Linear Search (files getting ready)
begin
SearchName := edtUserName.text;
assignfile (LoginDatafile,'C:\Users\NinjaBoffin\Desktop\Delphi\DataFiles\LoginData.txt');
reset (LoginDatafile);
LoginDatacounter := FileSize(LoginDatafile);
SetLength(LoginDataArray, LoginDatacounter);
edtUserName.Clear;
//Copying to array
for Count1 := 1 to StudentCounter do
begin
read(LoginDatafile,SingleLoginData);
LoginDataArray[Count1] := SingleLoginData;
end;
closefile (Studentfile);
//The actual linear search
for Count1 := 1 to StudentCounter do
begin
if LoginDataArray[Count1].Username = SearchName then
begin
assignfile (LoginDatafile,'C:\Users\NinjaBoffin\Desktop\Delphi\DataFiles\LoginData.txt');
reset (LoginDatafile);
LoginDatacounter := FileSize(LoginDatafile);
SetLength(LoginDataArray, LoginDatacounter);
edtPassword.clear;
for Count1 := 1 to LoginDataCounter do
begin
read(LoginDatafile,SingleLoginData);
LoginDataArray[Count1] := SingleLoginData;
end;
closefile (LoginDatafile);
//bubble sort
edtUserName.Clear;
for count1 := 1 to LoginDatacounter-1 do
for count2 := 1 to LoginDatacounter-1 do
if LoginDataArray[count2].Password > LoginDataArray[count2+1].Password then
begin
temp := LoginDataArray[count2+1];
LoginDataArray[count2+1] := LoginDataArray[count2];
LoginDataArray[count2] := temp;
end;
//Linear Search (files getting ready)
begin
SearchName := edtPassword.text;
assignfile (LoginDatafile,'C:\Users\NinjaBoffin\Desktop\Delphi\DataFiles\LoginData.txt');
reset (LoginDatafile);
LoginDatacounter := FileSize(LoginDatafile);
SetLength(LoginDataArray, LoginDatacounter);
edtPassword.clear;
//Copying to array
for Count1 := 1 to StudentCounter do
begin
read(LoginDatafile,SingleLoginData);
LoginDataArray[Count1] := SingleLoginData;
end;
closefile (Studentfile);
//The actual linear search
for Count1 := 1 to StudentCounter do
begin
if LoginDataArray[Count1].Password = SearchName then
begin
frmLogin.Hide;
frmMainmenu.Show;
end;
end;
end;
end;
end;
end;
end;
end;

如果这不是用户名和密码,您必须输入老师为您创建的密码和用户名。这是在教师表格中,文件是“Logindata.txt”。

procedure TfrmAddNewUser.btnAddNewStudentClick(Sender: TObject);
begin
assignfile (LoginDataFile,'C:\Users\NinjaBoffin\Desktop\Delphi\DataFiles\LoginData.txt');
reset (loginDataFile);
LoginDataCounter := FileSize(LoginDataFile);
SingleLoginData.Username := edtNewUsername.text;
SingleLoginData.Password := edtNewPassword.Text;
//find where to store the record
seek (LoginDataFile,LoginDataCounter);
{...and put the record in}
write(LoginDataFile,SingleLoginData);
closefile (LoginDataFile);
edtNewUserName.Text := '';
edtNewPassword.Text := '';
end;

我不断收到 I/O 103 错误,我不知道它来自哪里(它在登录表单中)那么我该如何修复这个错误呢?登录是否有效?

这是我第一次编程

最佳答案

谢谢大家解决问题(I/O error 103)原来我正在关闭不存在的文件

Closefile (StudentFile)

应该是什么时候

Closefile (LoginDataFile)

感谢所有帮助过的人

关于delphi - 如何解决delphi中的I/O错误103,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22026948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com