Results 1 to 5 of 5

Thread: NLDSimpleIniFile

  1. #1

    NLDSimpleIniFile

    ------------
    De sources van NLDDanyUtils zijn te vinden in:
    ftp://ftp.nldelphi.com/public/OpenSo.../NLDDanyUtils/
    ------------

    Deze unit bevat procedures en functies die
    - automatisch gebruik maken van de Ini file die in de start-up directory van de applicatie staan (dus niet noodzakelijk in het path van de applicatie zelf)
    - ook TStrings kunnen schrijven en lezen naar en van de Ini file.
    - heel simpel in gebruik zijn ("Class"-loos, de procedures zijn aan te roepen zonder een object van een Class te moeten aanmaken).

    Voor de kompleetheid is een Class "TSimpleIniFile" aangemaakt. Die is een kind van "TIniFile" maar bevat de extra TStrings schrijf- en leesmethoden alsook de automatische plaatsing van de Ini file in de startup directory van de applicatie (tenzij je zelf een IniFile naam opgeeft).

    De interface:
    Code:
    { ---  Class "TSimpleIniFile" --- }
    
    type
      TSimpleIniFile = class(TIniFile)
      private
      public
        constructor Create(fn: string = '');
        // Added procedures in this Class with respect to "TIniFile"
        procedure WriteTStrings(Section, Key: string; Texts: TStrings); overload;
        procedure ReadTStrings(Section, Key: string; Texts: TStrings); overload;
        procedure WriteTStrings(Section: string; Texts: TStrings); overload;
        procedure ReadTStrings(Section: string; Texts: TStrings); overload;
        procedure WriteObject(Section: string; Obj: TObject);
        procedure ReadObject(Section: string; Obj: TObject);
      end;
    
    
    { --- Procedures and Functions without usage of a Class --- }
    
    // BinaryStream ----------------------------------------------------
    procedure WriteBinaryStreamToIniFile(Section, Key: string; Value: TStream);
    function ReadBinaryStreamFromIniFile(Section, Key: string; Value: TStream):
      Integer;
    
    // Bool ----------------------------------------------------
    procedure WriteBoolToIniFile(Section, Key: string; Value: Boolean);
    function ReadBoolFromIniFile(Section, Key: string): Boolean;
    
    // Date ----------------------------------------------------
    procedure WriteDateToIniFile(Section, Key: string; Value: TDateTime);
    function ReadDateFromIniFile(Section, Key: string): TDateTime;
    
    // DateTime ----------------------------------------------------
    procedure WriteDateTimeToIniFile(Section, Key: string; Value: TDateTime);
    function ReadDateTimeFromIniFile(Section, Key: string): TDateTime;
    
    // Float ----------------------------------------------------
    procedure WriteFloatToIniFile(Section, Key: string; Value: Double);
    function ReadFloatFromIniFile(Section, Key: string): Double;
    
    // Integer ----------------------------------------------------
    procedure WriteIntegerToIniFile(Section, Key: string; Value: Integer);
    function ReadIntegerFromIniFile(Section, Key: string): Integer;
    
    // Time ----------------------------------------------------
    procedure WriteTimeToIniFile(Section, Key: string; Value: TDateTime);
    function ReadTimeFromIniFile(Section, Key: string): TDateTime;
    
    // String ----------------------------------------------------
    procedure WriteStringToIniFile(Section, Key, Value: string);
    function ReadStringFromIniFile(Section, Key: string): string;
    
    // TStrings ----------------------------------------------------
    procedure WriteTStringsToIniFile(Section, Key: string; Texts: TStrings);
      overload;
    procedure ReadTStringsFromIniFile(Section, Key: string; Texts: TStrings);
      overload;
    procedure WriteTStringsToIniFile(Section: string; Texts: TStrings); overload;
    procedure ReadTStringsFromIniFile(Section: string; Texts: TStrings); overload;
    
    // Objects Texts and Statusses
    procedure WriteObjectToIniFile(Section: string; Obj: TObject);
    procedure ReadObjectFromIniFile(Section: string; Obj: TObject);
    
    // Miscellaneous ----------------------------------------------------
    procedure DeleteKeyFromIniFile(const Section, Key: string);
    procedure EraseSectionFromIniFile(const Section: string);
    procedure ReadSectionFromIniFile(const Section: string; Texts: TStrings);
    procedure ReadSectionsFromIniFile(Texts: TStrings);
    procedure ReadSectionValuesFromIniFile(const Section: string; Texts: TStrings);
    function SectionExistsInIniFile(const Section: string): Boolean;
    function ValueExistsInIniFile(const Section, Key: string): Boolean;
    Last edited by Dany; 23-Nov-06 at 20:21.

  2. #2
    Hoi iedereen,

    De 'class' loze routines zijn nu volledig: alle routines die normaal in TIniFile zitten zijn nu ook class-loos beschikbaar. De tekst in de bovenstaande post is in die zin ook aangepast.

    Veel plezier.
    Last edited by Dany; 03-Jun-04 at 20:19.
    Vriendelijke groeten,
    Dany

  3. #3
    Hoi,

    Er zijn een paar procedures toegevoegd om gemakkelijk keuzes van gebruikers in visuele componenten (zoals TEdit) naar de inifile te schrijven en ervan te lezen: ReadObjectFromIniFile en WriteObjectToIniFile.

    Zie thread: http://www.nldelphi.com/forum/showth...576#post146576

    Enkel het "OnCreate" en "OnDestroy" event van je form heeft een minimale hoeveelheid code nodig om het lezen en het opslaan in de inifile te verwezenlijken.

    Bv (3 TEdits):
    Code:
    procedure TForm1.FormCreate(Sender: TObject);
    begin
       ReadObjectFromIniFile('FileNames', DataFileEdit);
      ReadObjectFromIniFile('FileNames', DefinitionFileEdit);
      ReadObjectFromIniFile('FileNames', OutputFileEdit);
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
       WriteObjectToIniFile('FileNames', DataFileEdit);
      WriteObjectToIniFile('FileNames', DefinitionFileEdit);
      WriteObjectToIniFile('FileNames', OutputFileEdit);
    end;
    Voor de code zelf: zie de threadURL in de inleiding van deze post.
    Last edited by Dees; 27-Nov-04 at 17:19.

  4. #4

    Smile

    Hoi,

    Normaal zijn IniFiles zo geformat dat alles na mekaar staat, zonder lege regels tussen de sekties. Dit is moeilijk(er) te lezen voor een mens (mocht hij/zij dat willen).
    Daarom is in "NLDSimpleIniFiles" nu een kleine formatter ingebouwd die lege regels toevoegt waar nodig. Dat wordt gedaan tijdens bij het free-en van het TSimpleIniFile object.

    Veel plezier.
    Dany

  5. #5
    Vriendelijke groeten,
    Dany

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •