home *** CD-ROM | disk | FTP | other *** search
/ Chip: Shareware for Win 95 / Chip-Shareware-Win95.bin / ostatni / delphi / delphi1 / fldinfo.exe / FLDINFO.PAS next >
Pascal/Delphi Source File  |  1995-10-09  |  4KB  |  114 lines

  1. unit FldInfo;
  2. (*
  3. Unit to save and recall DataSet field informaion to and and from an INI file
  4. This is usefull if the user sizes the columns and rearrages them.  This
  5. allows a program to return their setting.
  6.  
  7.     Author: William R. Florac
  8.   Company: FITCO, Verona, WI (wee little company from my house)
  9.     Copyright 1995, FITCO.  All rights reserved.
  10.  
  11.     1) Users of Fldinfo must accept this disclaimer of  warranty:
  12.          "FldInfo is supplied as is.  The author disclaims all
  13.      warranties, expressed or implied, including, without limitation,
  14.        the warranties of merchantability and of fitness for any purpose.
  15.        The author assumes no liability for damages, direct or conse-
  16.      quential, which may result from the use of FldInfo."
  17.  
  18.     2) This Unit is donated to the public as public domain.
  19.  
  20.     3) This Unit can be freely used and distributed in commercial and private
  21.      environments provided this notice is not modified in any way.
  22.  
  23.   4) If you do find this Unit handy and you feel guilty
  24.     for using such a great product without paying someone,
  25.     please feel free to send a few bucks ($25) to support further
  26.     development.
  27.  
  28.  5) This file was formated with tabs set to 2.
  29.  
  30.     Please forward any comments or suggestions to Bill Florac at:
  31.          email: flash@etcconnect.com
  32.         www: http://www.etcconnect.com/fitco.html
  33.         mail: FITCO
  34.                     209 Jenna Dr
  35.                     Verona, WI  53593
  36.  
  37.     Revision History
  38.     1.0     10-4-95    Initial release.
  39.     1.1        10-9-95    Changes procedures from TTable to TDataSet so
  40.                 unit will work with queries too.
  41.  
  42. *)
  43. interface
  44.  
  45. uses
  46.     inifiles, sysutils, dbTables, db;
  47.  
  48.     procedure GetFieldInfo(IniFileName: TFileName; DS: TDataSet);
  49.     procedure PutFieldInfo(IniFileName: TFileName; DS: TDataSet);
  50.  
  51. implementation
  52.  
  53. procedure GetFieldInfo(IniFileName: TFileName; DS: TDataSet);
  54. {gets a dataset field info from an ini file}
  55. var
  56.     IniFile: TIniFile;
  57.     ColWidth: longint;
  58.     ColName: String;
  59.     IndexStr: String;
  60.     X: integer;
  61.     aField: TField;
  62.     IniString: string;
  63.     comma: integer;
  64. begin
  65.     {create an ini object}
  66.   IniFile := TIniFile.Create(IniFileName);
  67.     {fields are save in the section <DataSetname>Fields and indexed by column
  68.      number, the field name and with is saved}
  69.     {select each field and reindex it}
  70.     for X := 0 to DS.FieldCount - 1 do begin
  71.         {create a string for the column number to find}
  72.         Str(X, IndexStr);
  73.         IniString := IniFile.ReadString(DS.Name+'Fields', IndexStr, '');
  74.         {find the comma, the width is to the right}
  75.         comma := pos(',',IniString);
  76.         if comma > 0 then begin {if we found one}
  77.             ColName := Copy(IniString, 1, comma -1);
  78.             ColWidth := StrToInt(Copy(IniString, comma + 1, 20));
  79.             if ColName <> '' then begin
  80.                 aField := DS.FindField(ColName);
  81.         {make sure we found one}
  82.           if aField <> nil then begin
  83.                     {now set the values}
  84.                     aField.DisplayWidth := ColWidth;
  85.                     aField.Index := X;
  86.                     end;
  87.                 end;
  88.             end;
  89.         end;
  90.   IniFile.Free; {let us not forget this!}
  91.     end; {of GetFieldInfo}
  92.  
  93. procedure PutFieldInfo(IniFileName: TFileName; DS: TDataSet);
  94. {saves a DataSet field info to an ini file}
  95. var
  96.     X: integer;
  97.     IndexStr: String;
  98.   IniFile: TIniFile;
  99. begin
  100.   IniFile := TIniFile.Create(IniFileName);
  101.     {fields are save in the section <DataSetname>Fields and indexed by column
  102.      number, the field name and with is saved}
  103.     for X := 0 to DS.FieldCount - 1 do begin
  104.         {create a string out of the column number}
  105.         Str(X, IndexStr);
  106.         {save it...}
  107.     IniFile.WriteString(DS.Name+'Fields', IndexStr,
  108.             DS.Fields[x].FieldName + ',' + IntToStr(DS.Fields[x].DisplayWidth));
  109.         end;
  110.   IniFile.Free; {let us not forget this!}
  111.     end; {of PutFieldInfo}
  112.  
  113. end. {of unit}
  114.