简单的程序:
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
AssignFile(DealFile,Opendialog1.FileName);
Reset(DealFile);
end;
end;我的问题是:如果我打开选择文件对话框后,并不选择任何文件。是否有办法通过判断DealFile这个变量来确定是否assign了文件?谢谢!
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
AssignFile(DealFile,Opendialog1.FileName);
Reset(DealFile);
end;
end;我的问题是:如果我打开选择文件对话框后,并不选择任何文件。是否有办法通过判断DealFile这个变量来确定是否assign了文件?谢谢!
begin
if OpenDialog1.Execute then
begin
AssignFile(DealFile,Opendialog1.FileName);
Reset(DealFile);
end;
else
showmessage('请选择文件');
end;
closefile(DealFile);AssignFile(DealFile,FName);
Reset(DealFile);
var
R: TTextRec absolute DealFile;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
AssignFile(DealFile,Opendialog1.FileName);
Reset(DealFile);
if R.Handle > 0 then
ShowMessage('文件已经打开');
end;
end;
Delphi 5.0
sozeof(File) 得到 332
sozeof(TextFile) 得到 460另外用个标志变量,与DealFile同步修改吧。
R: TFileRec absolute DealFile;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
AssignFile(DealFile,Opendialog1.FileName);
Reset(DealFile);
if R.Handle > 0 then
ShowMessage('文件已经打开');
end;
end;
2个结构 TFileRec = packed record (* must match the size the compiler generates: 332 bytes *)
Handle: Integer;
Mode: Word;
Flags: Word;
case Byte of
0: (RecSize: Cardinal); // files of record
1: (BufSize: Cardinal; // text files
BufPos: Cardinal;
BufEnd: Cardinal;
BufPtr: PChar;
OpenFunc: Pointer;
InOutFunc: Pointer;
FlushFunc: Pointer;
CloseFunc: Pointer;
UserData: array[1..32] of Byte;
Name: array[0..259] of Char; );
end;{ Text file record structure used for Text files }
PTextBuf = ^TTextBuf;
TTextBuf = array[0..127] of Char;
TTextRec = packed record (* must match the size the compiler generates: 460 bytes *)
Handle: Integer; (* must overlay with TFileRec *)
Mode: Word;
Flags: Word;
BufSize: Cardinal;
BufPos: Cardinal;
BufEnd: Cardinal;
BufPtr: PChar;
OpenFunc: Pointer;
InOutFunc: Pointer;
FlushFunc: Pointer;
CloseFunc: Pointer;
UserData: array[1..32] of Byte;
Name: array[0..259] of Char;
Buffer: TTextBuf;
end;