Kanade's Delphi Stuff
Delphi Tips, Sample code and Tools
Copyright © 1997-2004, Sanjay Kanade
 
  Tips and Tricks on Delphi
Please read the DISCLAIMER before you use any of the tips from this web site. Go to main index
  Delphi Tips: File functions
Tip 11:  Don't use ExtractFileDir to make up full path names
(modified: 11 Nov 1999)


Tip 26:  Speeding up text file reading
(modified: 21 Nov 1999)


Tip 29:  File Formats
(modified: 21 Dec 1999)


Tip 12:  FindFirst and the memory leak in FmxUtils
(modified: 16 Feb 2001)


Tip 43:  Creating a file in Windows temp folder
(modified: 16 Feb 2001)


  11: Don't use ExtractFileDir to make up full path names
Date added/modified: 11 Nov 1999

If you want to make up full path names for files to be accessed from the same directory where your EXE file exists, don't use ExtractFileDir. Instead, use ExtractFilePath as follows:

  ExtractFilePath(Application.ExeName) 
  + theFileNameToAccess
If you use ExtractFileDir, it doesn't return ending backslash for all paths except the root. So, its result is inconsistent for such use. The Delphi help documentation also recommends using ExtractFileDir only for passing to the listed functions in that help topic. But, you may miss reading those notes as I did.

  26: Speeding up text file reading
Date added/modified: 21 Nov 1999

If you need to read text files in your applications, you might be using the standard text file function "Readln" in your code as given in the Delphi help file. Have you ever tested the speed? Well, as per my experience, these operations were slow and even using a "SetTextBuf" to specify a bigger text buffer didn't help. Finally, I changed my code to read text files as untyped files with a record size of 1, and then used BlockRead to read into a bigger buffer (the same one that I tried with SetTextBuf). It made a big difference.

You can try it on your own. Basically, you need the sophistication of Readln only if you want to analyze your text file line by line while reading. If you are just reading to display in some control, untyped method works much faster. Of course, this is my opinion based on my own testing. If you are an expert and know better, I will appreciate an email giving a hint on why SetTextBuf doesn't work as well as untyped reading.

  29: File Formats
Date added/modified: 21 Dec 1999

Recently, I got hold of a URL to an excellent site that is a repository of file formats. It is located at http://www.wotsit.org

I got this information from Niko, a developer from Germany (http://www.loonatic-entertainment.de). Thanks, Niko!

  12: FindFirst and the memory leak in FmxUtils
Date added/modified: 16 Feb 2001

Beware of the memory leak caused by improper use of FindFirst function as in FmxUtils in Delphi 3. Take note of this for your own code too. See the tip related to this in the "Memory leaks" category.

  43: Creating a file in Windows temp folder
Date added/modified: 16 Feb 2001

See this code in the sample code area.



 

Copyright 1995-2004, Sanjay Kanade. All rights reserved.
All trademarks and copyrights belong to their respective owners.