線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1637
推到 Plurk!
推到 Facebook!

FileExists Example 問題

答題得分者是:領航天使
ok2002
一般會員


發表:3
回覆:8
積分:2
註冊:2002-04-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-09-27 11:34:49 IP:61.220.xxx.xxx 未訂閱
請問我去執行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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-09-27 11:40:12 IP:61.219.xxx.xxx 未訂閱
引言: 但卻在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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-09-27 13:27:31 IP:61.220.xxx.xxx 未訂閱
站長 : 還是一樣ㄋㄟ...
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-09-27 17:35:12 IP:218.163.xxx.xxx 未訂閱
var p:pchar; begin p:=pchar(StringGrid1.Cells[X,Y]); FileWrite( FileHandle,p, Length(StringGrid1.Cells[X,Y])); end; 這樣我試過可以Compile成功, 但您可能要測試看看讀出會不會與原存入的值一樣? ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
系統時間:2024-04-20 22:57:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!