Home arrow Delphi-Kylix arrow Page 4 - Handling Files in Delphi
DELPHI-KYLIX

Handling Files in Delphi


Handling files in Delphi is not so different from handling files in any other high level programming language. In this article we will examine how to read and write to text files and binary files and we will also explore various methods of accessing files.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
August 30, 2006
TABLE OF CONTENTS:
  1. · Handling Files in Delphi
  2. · Reading from a file
  3. · Binary Files
  4. · Streams

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Handling Files in Delphi - Streams
(Page 4 of 4 )

Streams are the latest method used to access files on disk. The biggest advantage of streams is that it makes file access much faster and that it is interchangeable. For example, once you've read a file into a TFileStream variable, you can then go on to load its contents into a memo or into a Tmemory variable which is used to transfer files over the Internet. Here's an example of how to read the contents of a file:

var
fs:TFilestream ;
begin
fs:=tfilestream.create(Afilename,fmOpenRead);
try
memo.lines.loadfromstream(s);
finally
fs.free;
end;
end;

This example reads the file contents into a tfilestream variable, and then that stream is loaded into a memo. The fm in the fmOpenRead is short for "File Mode." There are other modes, such as:

fmCreate                    If the file exists, open for write access, otherwise, create a new   file.

fmOpenRead              Open for read access only.

fmOpenWrite              Open for write access only.

fmOpenReadWrite      Open for read and write access.

fmShareExclusive        Read and write access is denied.

fmShareDenyWrite      Write access is denied.

fmShareDenyRead       Read access is denied. Do not use this mode in cross-platform applications.

fmShareDenyNone       Allows full access for others.

There are many more ways to handle files with streams and Delphi has integrated this method into its core libraries. The tstream libraries do not differentiate between text, image and binary files.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials