FileExists Example 問題 |
答題得分者是:領航天使
|
ok2002
一般會員 發表:3 回覆:8 積分:2 註冊:2002-04-14 發送簡訊給我 |
請問我去執行delphi help 的FileExists, RenameFile, FileCreate, FileWrite, FileClose, ExtractFileName Example
範例如下 :
procedure TForm1.Button1Click(Sender: TObject);
var
BackupName: string;
FileHandle: Integer;
StringLen: Integer;
X: Integer;
Y: Integer;
begin
if SaveDialog1.Execute then
begin
if FileExists(SaveDialog1.FileName) then
begin
BackupName := ExtractFileName(SaveDialog1.FileName);
BackupName := ChangeFileExt(BackupName, ''.BAK'');
if not RenameFile(SaveDialog1.FileName, BackupName) then raise Exception.Create(''Unable to create backup file.'');
end;
FileHandle := FileCreate(SaveDialog1.FileName);
{ Write out the number of rows and columns in the grid. }
FileWrite(FileHandle,
StringGrid1.ColCount, SizeOf(StringGrid1.ColCount));
FileWrite(FileHandle,
StringGrid1.RowCount, SizeOf(StringGrid1.RowCount));
for X := 0 to StringGrid1.ColCount -1 do
begin for Y := 0 to StringGrid1.RowCount -1 do
begin
{ Write out the length of each string, followed by the string itself. }
StringLen := Length(StringGrid1.Cells[X,Y]);
FileWrite(FileHandle, StringLen, SizeOf(StringLen));
FileWrite(FileHandle,
StringGrid1.Cells[X,Y], Length(StringGrid1.Cells[X,Y]);
end;
end;
FileClose(FileHandle);
end; end; 但卻在FileWrite(FileHandle,StringGrid1.Cells[X,Y],Length(StringGrid1.Cells[X,Y]);
出現Variable required
這是為何呢?
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
引言: 但卻在FileWrite(FileHandle,StringGrid1.Cells[X,Y],Length(StringGrid1.Cells[X,Y]); 出現Variable required 這是為何呢?將FileWrite(FileHandle,StringGrid1.Cells[X,Y],Length(StringGrid1.Cells[X,Y]); 改為 var len:integer; begin len:=Length(StringGrid1.Cells[X,Y]); FileWrite(FileHandle,StringGrid1.Cells[X,Y],Len); end;再試試看 ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~ |
ok2002
一般會員 發表:3 回覆:8 積分:2 註冊:2002-04-14 發送簡訊給我 |
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |