Delphi中io错误1819是什么意思
3个回答
展开全部
定有Reset(passwordfile);不然的话,rewrite(passwordfile);就有错误。
这是我为重写F:\下的password.txt文本文件的内容而写的一段小小代码(运行正常,直接复用即可):
procedure TForm1.Button1Click(Sender: TObject);
var
password:string;
passwordfile :TextFile;
begin
password:=maskedit2.Text;
assignfile(passwordfile,'f:\password.txt');
Reset(passwordfile);
rewrite(passwordfile);
write(passwordfile,maskedit2.Text);
closefile(passwordfile);
end;
这个程序没有问题,你的程序也没有问题,在我的计算机中实验正确!你必须事先在password.txt中输入密码,并且在maskedit2与maskedit3输入内容必须一致。maskedit1是要改的密码。以下是我在delphi7中的程序,实验正确:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button3: TButton;
maskedit1: TEdit;
maskedit2: TEdit;
maskedit3: TEdit;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
var
password:string;
passwordfile:textfile;
begin
assignfile(passwordfile,'f:\password.txt');
reset(passwordfile);
read(passwordfile,password);
closefile(passwordfile);
if (maskedit1.Text=password) and (maskedit2.Text=maskedit3.Text)
then
begin
password:=maskedit2.Text;
assignfile(passwordfile,'f:\password.txt');
reset(passwordfile);
rewrite(passwordfile);
write(passwordfile,password);
closefile(passwordfile);
messagedlg('密码修改成功',mtinformation,[mbok],0);
end
else
begin
messagedlg('输入错误',mterror,[mbok],0);
maskedit1.Text:='';
maskedit2.Text:='';
maskedit3.Text:='';
end;
end;
end.
您可以参照以下本人的《旅行社管理软件》登录口令验证窗体(三层模式)
unit sdlps;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, DBCtrls, ExtCtrls, Mask;
type
TPasswordDlg = class(TForm)
Label1: TLabel;
Password: TEdit;
OKBtn: TButton;
CancelBtn: TButton;
Label2: TLabel;
DBNavigator1: TDBNavigator;
Lusername: TLabel;
procedure OKBtnClick(Sender: TObject);
procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
PasswordDlg: TPasswordDlg;
FRetries:integer;
implementation
uses dmpas;
//客户端数据集
{$R *.dfm}
procedure TPasswordDlg.OKBtnClick(Sender: TObject);
var
MaxRetries:Integer;
s:string;
PopedomTextFile:TextFile;
begin
MaxRetries:=3;
inc(FRetries);
s:=dm.ClientDataSet1.Fields[4].AsString;//口令
s:=TrimRight(s);
if Password.text=s then
begin
with dm.ClientDataSet1 do
s:=Fields[1].AsString + Fields[2].AsString +
Fields[3].AsString + Fields[0].AsString;//Fields[1]是控制菜单项的,8位;
//Fields[2]是控制页项的,13位;Fields[3]是控制工具按钮项的,9位;
//Fields[0]是用户名称项的;
AssignFile(PopedomTextFile,'Popedom.txt');
Rewrite(PopedomTextFile);
try
Writeln(PopedomTextFile,s);
finally
CloseFile(PopedomTextFile);
end;
ModalResult:=mrOk;
end
else
begin
if FRetries>=MaxRetries then
begin
MessageBox(0,'密码错误!强制退出。','3次机会都忘记了密码吗?',mb_ok);
ModalResult:=mrCancel;
end
else
begin
MessageBox(0,'如果是你忘记了密码,请与设计者联系。','密码错误!还有机会!',mb_ok);
Password.Text:='';
Password.SetFocus;
ModalResult:=mrNone;
end;
end;
end;
procedure TPasswordDlg.DBNavigator1Click(Sender: TObject;
Button: TNavigateBtn);
begin
Lusername.Caption:=dm.ClientDataSet1.Fields[0].AsString;
end;
procedure TPasswordDlg.FormCreate(Sender: TObject);
begin
with dm.ClientDataSet1 do
begin
Close;
ProviderName:='DSP_popedom';
Open;
Lusername.Caption:=dm.ClientDataSet1.Fields[0].AsString;
end;
end;
end.
这是我为重写F:\下的password.txt文本文件的内容而写的一段小小代码(运行正常,直接复用即可):
procedure TForm1.Button1Click(Sender: TObject);
var
password:string;
passwordfile :TextFile;
begin
password:=maskedit2.Text;
assignfile(passwordfile,'f:\password.txt');
Reset(passwordfile);
rewrite(passwordfile);
write(passwordfile,maskedit2.Text);
closefile(passwordfile);
end;
这个程序没有问题,你的程序也没有问题,在我的计算机中实验正确!你必须事先在password.txt中输入密码,并且在maskedit2与maskedit3输入内容必须一致。maskedit1是要改的密码。以下是我在delphi7中的程序,实验正确:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button3: TButton;
maskedit1: TEdit;
maskedit2: TEdit;
maskedit3: TEdit;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
var
password:string;
passwordfile:textfile;
begin
assignfile(passwordfile,'f:\password.txt');
reset(passwordfile);
read(passwordfile,password);
closefile(passwordfile);
if (maskedit1.Text=password) and (maskedit2.Text=maskedit3.Text)
then
begin
password:=maskedit2.Text;
assignfile(passwordfile,'f:\password.txt');
reset(passwordfile);
rewrite(passwordfile);
write(passwordfile,password);
closefile(passwordfile);
messagedlg('密码修改成功',mtinformation,[mbok],0);
end
else
begin
messagedlg('输入错误',mterror,[mbok],0);
maskedit1.Text:='';
maskedit2.Text:='';
maskedit3.Text:='';
end;
end;
end.
您可以参照以下本人的《旅行社管理软件》登录口令验证窗体(三层模式)
unit sdlps;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, DBCtrls, ExtCtrls, Mask;
type
TPasswordDlg = class(TForm)
Label1: TLabel;
Password: TEdit;
OKBtn: TButton;
CancelBtn: TButton;
Label2: TLabel;
DBNavigator1: TDBNavigator;
Lusername: TLabel;
procedure OKBtnClick(Sender: TObject);
procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
PasswordDlg: TPasswordDlg;
FRetries:integer;
implementation
uses dmpas;
//客户端数据集
{$R *.dfm}
procedure TPasswordDlg.OKBtnClick(Sender: TObject);
var
MaxRetries:Integer;
s:string;
PopedomTextFile:TextFile;
begin
MaxRetries:=3;
inc(FRetries);
s:=dm.ClientDataSet1.Fields[4].AsString;//口令
s:=TrimRight(s);
if Password.text=s then
begin
with dm.ClientDataSet1 do
s:=Fields[1].AsString + Fields[2].AsString +
Fields[3].AsString + Fields[0].AsString;//Fields[1]是控制菜单项的,8位;
//Fields[2]是控制页项的,13位;Fields[3]是控制工具按钮项的,9位;
//Fields[0]是用户名称项的;
AssignFile(PopedomTextFile,'Popedom.txt');
Rewrite(PopedomTextFile);
try
Writeln(PopedomTextFile,s);
finally
CloseFile(PopedomTextFile);
end;
ModalResult:=mrOk;
end
else
begin
if FRetries>=MaxRetries then
begin
MessageBox(0,'密码错误!强制退出。','3次机会都忘记了密码吗?',mb_ok);
ModalResult:=mrCancel;
end
else
begin
MessageBox(0,'如果是你忘记了密码,请与设计者联系。','密码错误!还有机会!',mb_ok);
Password.Text:='';
Password.SetFocus;
ModalResult:=mrNone;
end;
end;
end;
procedure TPasswordDlg.DBNavigator1Click(Sender: TObject;
Button: TNavigateBtn);
begin
Lusername.Caption:=dm.ClientDataSet1.Fields[0].AsString;
end;
procedure TPasswordDlg.FormCreate(Sender: TObject);
begin
with dm.ClientDataSet1 do
begin
Close;
ProviderName:='DSP_popedom';
Open;
Lusername.Caption:=dm.ClientDataSet1.Fields[0].AsString;
end;
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询