Delphi - mc File I/O Component


Actions are designed to manipulate which ever component currently has the focus. However, the File_IO component is never visible and, therefore, can never have focus.

Each Action overrides create so that a default menu caption can be defined.


Custom OnRead Event

This example reads a text file and stores the results in a memo. Note that assigning TmcFile_IO.Control to a TMenu component automatically performs the same function. This example would allow you to change the data before displaying it.


For the derived Read_ini component, I don't want Control and Filter to be published.

  This was written as a generic File I/O interface that could be
  accessed via Actions.

  This component will be the basis of
    An ini file processor
    An xml file processor
  by overloading only FileOpen and FileSave. The rest of the code
  should be common.

  Other applications will use OnRead and OnWrite
    The labortory will process data buffers
    Increased Depth of field will use OnRead to call FileOpen
      for multiple images - goldxx.jpg where xx is 01 to xx


INI File Processing

There are 2 basic ways to use TmcCustomFile_IO in an INI file component Locically, it makes more sense to derive this component from TMemIniFile and to make an FFile_IO property and manipulate it as necessary. However, I really want the Open, Save, and SaveAs actions to work and they require a component derived from TmcCustomFile_IO.

TMemIniFile does not preserve blank lines or comments (lines which start with ";"). It seems ok for reading and sotring parameters, but I want my own WriteIni method. There is also a problem with spaces around the equals sign.

A WriteParameter method is not overloaded because

Date, Time, and DateTime
all pass parameters as TDateTime. The ReadParameter method can not be overloaded because only the return type changes.

Purpose of the ini component

Easy to use
Read command line prarameters (name of ini file)
Read ini parameters
Command line parameters should take priority
Write ini parameters and keep comments and spacing
Ignore spaces around "="
On save, maintain spaces around "="
Saves ini, command line, default, current parameters
If any parameters are "changed", a flag is set
  so that "save" is enabled in the menu
A way to create parameters and defaults at design time
Other components need to call this and to store defaults
Allow parameters which are not in the ini file
Save any parameter set "by the user"
  Parameters with the default value or the command line value
  are not "added" to the ini file

Store comments in the string list with a comment flag
  This should simplify writing an ini file
  Allows inclusion of an ini file developer (just use a memo field)
  Don't do this - makes maintaining spaces difficult
  Allows comments to be added to parameters not yet in ini file
    then comments can be generated when parameter is added

The Delphi ini component has no way to store default values
Over riding the "readString" command won't work because
the other "read" commands pass a null string as the default parameter

Allowing blank lines and comments in the string list will
slow down searches

Provide a way to see what changes have been made

Read ini file into a stringlist
Search for "[section]" to get start of search
search for "[" to get end of search
Find line which starts with "name"

Use this stringlist when you write a new ini file
 (keeps from having to read the file again)
This could be a problem with large ini files
(mine tend to be 2K, ie size is not an issue)

Some ini files may NOT have sections
Command line parameters can only apply to parameters without sections
unless special code is written


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Delphi / mc_File_IO.html