Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - Handling Files in Delphi
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Handling Files in Delphi
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-08-30

    Table of Contents:
  • Handling Files in Delphi
  • Reading from a file
  • Binary Files
  • Streams

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

       · I hope this article is of use to those of you who is learning to program using...
     

    DELPHI-KYLIX ARTICLES

    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...
    - Using Try and Finally to Help Prevent Memory...
    - The Implementation of an FTP Server







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway