fopen, fgetc, fclose 的功能對應?? |
缺席
|
adonis
高階會員 發表:140 回覆:258 積分:159 註冊:2002-04-15 發送簡訊給我 |
|
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
引言: 請問在 C++ Builder 5 中的 fopen, fgetc, fclose 相當於 Delphi 中的哪些 函數或功能,謝謝。HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file DWORD dwDesiredAccess, // access (read-write) mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes DWORD dwCreationDistribution, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to file with attributes to copy ); HFILE OpenFile( LPCSTR lpFileName, // pointer to filename LPOFSTRUCT lpReOpenBuff, // pointer to buffer for file information UINT uStyle // action and attributes ); BOOL WriteFile( HANDLE hFile, // handle to file to write to LPCVOID lpBuffer, // pointer to data to write to file DWORD nNumberOfBytesToWrite, // number of bytes to write LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written LPOVERLAPPED lpOverlapped // pointer to structure needed for overlapped I/O ); BOOL ReadFile( HANDLE hFile, // handle of file to read LPVOID lpBuffer, // address of buffer that receives data DWORD nNumberOfBytesToRead, // number of bytes to read LPDWORD lpNumberOfBytesRead, // address of number of bytes read LPOVERLAPPED lpOverlapped // address of structure for data ); BOOL CloseHandle( HANDLE hObject // handle to object to close ); 發表人 - cmf 於 2003/01/16 17:36:41
------
︿︿ |
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
1. 請問在 C++ Builder 5 中的 fopen 相當於 Delphi 中的哪些
function FileOpen(const FileName: string; Mode: LongWord): Integer;
open modes
fmOpenRead = $0000;
fmOpenWrite = $0001;
fmOpenReadWrite = $0002; fmShareCompat = $0000;
fmShareExclusive = $0010;
fmShareDenyWrite = $0020;
fmShareDenyRead = $0030;
fmShareDenyNone = $0040; FileOpen Example
procedure OpenForShare(const FileName: String);
var
FileHandle : Integer;
begin
FileHandle := FileOpen(FileName, fmOpenWrite or fmShareDenyNone);
if FileHandle > 0 then
{valid file handle}
else
{Open error: FileHandle = negative DOS error code}
end; 2. 請問在 C++ Builder 5 中的 fgetc 相當於 Delphi 中的哪些 function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer; FileOpen, FileSeek, FileRead Example
procedure TForm1.Button1Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer: PChar;
i: Integer
begin
if OpenDialog1.Execute then
begin
try
iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
Buffer := PChar(AllocMem(iFileLength + 1));
iBytesRead := FileRead(iFileHandle, Buffer, iFileLength);
FileClose(iFileHandle); for i := 0 to iBytesRead-1 do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cells[1,i+1] := Buffer[i];
StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer[i]));
end;
finally
FreeMem(Buffer);
end;
end;
end; 3. 請問在 C++ Builder 5 中的 fclose 相當於 Delphi 中的哪些
procedure FileClose(Handle: Integer); 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;
------
︿︿ |
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
TFileStreamCreates an instance of TFileStream. constructor Create(const FileName: string; Mode: Word); overload; constructor Create(const FileName: string; Mode: Word; Rights: Cardinal); overload; Description Call Create to instantiate a file stream for reading from or writing to the named file. Specify the name of the file and the way the file should be opened as parameters. The Mode parameter indicates how the file is to be opened. The Mode parameter consists of an open mode and (possibly) a share mode ored together. The open mode must be one of the following values: Value Meaning fmCreate Create a file with the given name. If a file with the given name exists, open the file in write mode. fmOpenRead Open the file for reading only. fmOpenWrite Open the file for writing only. Writing to the file completely replaces the current contents. fmOpenReadWrite Open the file to modify the current contents rather than replace them. The share mode must be one of the following values: Value Meaning fmShareCompat Sharing is compatible with the way FCBs are opened. fmShareExclusive Other applications can not open the file for any reason. fmShareDenyWrite Other applications can open the file for reading but not for writing. fmShareDenyRead Other applications can open the file for writing but not for reading. fmShareDenyNone No attempt is made to prevent other applications from reading from or writing to the file. The Rights parameter indicates the permission bits with which to create the file on Linux when Mode is fmCreate. Rights is ignored when used on the Windows platform. If the file can not be opened, Create raises an exception. function Read(var Buffer; Count: Longint): Longint; override; Reads up to Count bytes of data from the resource associated with the handle stream into Buffer. function Write(const Buffer; Count: Longint): Longint; override; Writes Count bytes from the Buffer to the current position in the resource. 發表人 - cmf 於 2003/02/04 14:28:13
------
︿︿ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |