Link to home
Start Free TrialLog in
Avatar of Wyn
Wyn

asked on

a idiot question!

I'm totally dummy on delphi, I read some info below, would you please tell me if it's logic and reasonable?

"The programmer create a stream component in order to replace TextFile.The stream component deals with file read/write and works much faster than TextFile.
Later, The programmer use SetTextBuf() to change the cache size and then use TextFile again to deal with file read/write.This time,TextFile also works much faster..."


So, are there some functions named TextFile and SetTextBuf in Delphi? is TextFile a class or function in Delphi? Are the logic of above quote reasonable,logic in Delphi programming? Please point out any error.

Thank you!Thank you!Thank you!
Best Regards
Yinan
Avatar of ckaneta
ckaneta

Actually, just use the FileStream object that is provided in Delphi.
look in the help files for TFileStream, or TStream

Avatar of Wyn

ASKER

Where Can I find help files? I have no delphi.

Thank you!
Oh, that would make it more difficult then...
From Delphi Help Files:
TextFile / Text
---------------
Standard I/O routines use the predefined TextFile or Text type, which represents a file containing characters organized into lines.

SetTextBuf
----------
SetTextBuf assigns an I/O buffer to a text file.

Unit

System

Category

text file routines

procedure SetTextBuf(var F: Text; var Buf [ ; Size: Integer] );

Description

F is a text file variable, Buf is any variable, and Size is a optional expression.

Each Text file variable has an internal 128-byte buffer that buffers Read and Write operations. This buffer is adequate for most operations. However, heavily I/O-bound programs benefit from a larger buffer to reduce disk head movement and file system overhead.

SetTextBuf changes the text file F to use the buffer specified by Buf instead of F's internal buffer. Size specifies the size of the buffer in bytes. If Size is omitted, SizeOf(Buf) is assumed. The new buffer remains in effect until F is next passed to AssignFile.

SetTextBuf can be called immediately after Reset, Rewrite, and Append, but never apply it to an open file.

When SetTextBuf is called on an open file once I/O operations have taken place, data could be lost because of the change of buffer.

Delphi does not ensure that the buffer exists for the entire duration of I/O operations on the file. A common error is to install a local variable as a buffer, then use the file outside the procedure that declared the buffer.




TFileStream enables applications to read from and write to a file on disk.

Unit : classes

Description:
Use TFileStream to access the information in disk files. TFileStream will open a named file and provide methods to read from or write to it. If an application already has a handle to the file, opened in the appropriate mode, use THandleStream instead.

Properties:
Handle
Read Handle to get the handle for Windows API calls or file management functions. To read from or write to the resource, use the methods of the THandleStream object.

Handle is a read-only property. The handle property cannot be changed to allow the handle stream to switch from reading to writing or vice versa. For example, to change from a file handle that is opened in read-only mode to one that is opened in write mode:

1     Free the stream object.
2     Call FileClose to close the file.
3     Re-open the file in write mode, and use the handle to create a new instance of a handle stream. Alternately, open a TFileStream object for the file, specifying a write mode for the stream.
Position
Indicates the current offset into the stream for reading and writing.
property Position: Longint;
Description
Use Position to obtain the current position of the stream. This is the number of bytes from the beginning of the streamed data.
Size
Size indicates the size in bytes of the stream.

property Size: Longint;

Description

Use Size to find the size of the stream. Size is used internally in routines that read and write to and from the stream. Setting the Size property of TStream does nothing. Some descendants of TStream override this property to allow applications to change the size of the resource accessed using the stream.
Some Methods:
Create
Destroy
Read
Seek
Write
CopyFrom
ReadBuffer
ReadComponent
ReadComponentRes
ReadResHeader
WriteBuffer
WriteComponent
WriteComponentRes
WriteDescendent
WriteDescendentRes
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would say that "Delphi in a nutshell" is greate for things like this. You can get it from Amazon.com
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange