HomePage   Delphi Library  

Unit Ads_Ini;

{Copyright(c)1998 Advanced Delphi Systems

 Richard Maley
 Advanced Delphi Systems
 12613 Maidens Bower Drive
 Potomac, MD 20854 USA
 phone 301-840-1554
 [email protected]
 [email protected]
 [email protected]}

Interface

Uses
  SysUtils, Classes, ExtCtrls, StdCtrls, Ads_Strg, IniFiles;

Const RunOutsideIDE_ads        = True;
Const RunOutsideIDEDate_ads    = '12/1/98';
Const RunOutsideIDECompany_ads = 'Advanced Delphi Systems';
Const RunOutsideIDEPhone_ads   = 'Please purchase at (301) 840-1554';


{!~ Returns the ini value for a variable (IntegerName)
in the ini section (IniSection) of the ini file (TheIniFile).}
Function IniGetIntegerValue(
  TheIniFile            : String;
  IniSection            : String;
  IntegerName           : String;
  DefaultInteger        : Integer): Integer;

{!~ Returns the ini value for a variable (StringName)
in the ini section (IniSection) of the ini file (TheIniFile).}
Function IniGetStringValue(
  TheIniFile            : String;
  IniSection            : String;
  StringName            : String;
  DefaultString         : String): String;

{!~ Sets a variable (IntegerName) in the ini section (IniSection)
of the ini file (TheIniFile) with the value (IntegerValue).
If an exception is thrown the function returns False,
True otherwise.}
Function IniSetIntegerValue(
  TheIniFile            : String;
  IniSection            : String;
  IntegerName           : String;
  IntegerValue          : Integer): Boolean;

{!~ Sets a variable (StringName) in the ini section (IniSection)
of the ini file (TheIniFile) with the value (StringValue).
If an exception is thrown the function returns False,
True otherwise.}
Function IniSetStringValue(
  TheIniFile            : String;
  IniSection            : String;
  StringName            : String;
  StringValue           : String): Boolean;

{!~ Updates an ini file from a TStringList}
Procedure IniUpdateFromTStringList(
  TheIniFile            : String;
  IniSection            : String;
  StringListName        : String;
  CountField            : String;
  StringList            : TStringList);

{!~ Updates a TStringList from an ini file}
Procedure IniUpdateTStringList(
  TheIniFile            : String;
  IniSection            : String;
  StringListName        : String;
  CountField            : String;
  StringList            : TStringList);

Implementation

Type
  TPanel_Cmp_Sec_ads = class(TPanel)
  Public
    procedure ResizeShadowLabel(Sender: TObject);
  End;

procedure TPanel_Cmp_Sec_ads.ResizeShadowLabel(
  Sender     : TObject);
Var
  PH, PW : Integer;
  LH, LW : Integer;
begin
  PH := TPanel(Sender).Height;
  PW := TPanel(Sender).Width;
  LH := TLabel(Controls[0]).Height;
  LW := TLabel(Controls[0]).Width;
  TLabel(Controls[0]).Top  := ((PH-LH) div 2)-3;
  TLabel(Controls[0]).Left := ((Pw-Lw) div 2)-3;
end;

Type
  TEditKeyFilter = Class(TEdit)
  Published
    {!~ Throws away all keys except 0-9,-,+,.}
    Procedure OnlyNumbers(Sender: TObject; var Key: Char);

    {!~ Throws away all keys except 0-9}
    Procedure OnlyNumbersAbsolute(Sender: TObject; var Key: Char);

    {!~ Throws away all keys except a-z and A-Z}
    Procedure OnlyAToZ(Sender: TObject; var Key: Char);

  End;

{!~ Throws away all keys except 0-9,-,+,.}
Procedure TEditKeyFilter.OnlyNumbers(Sender: TObject; var Key: Char);
Begin
  KeyPressOnlyNumbers(Key);
End;

{!~ Throws away all keys except 0-9}
Procedure TEditKeyFilter.OnlyNumbersAbsolute(Sender: TObject; var Key: Char);
Begin
  KeyPressOnlyNumbersAbsolute(Key);
End;

{!~ Throws away all keys except a-z and A-Z}
Procedure TEditKeyFilter.OnlyAToZ(Sender: TObject; var Key: Char);
Begin
  KeyPressOnlyAToZ(Key);
End;
{!~ Returns the ini value for a variable (IntegerName)
in the ini section (IniSection) of the ini file (TheIniFile).}
Function IniGetIntegerValue(
  TheIniFile            : String;
  IniSection            : String;
  IntegerName           : String;
  DefaultInteger        : Integer): Integer;
Var
  TheIni                : TIniFile;
Begin
  TheIni                := TIniFile.Create(TheIniFile);
  Try
    Result :=
      TheIni.ReadInteger(
        IniSection,
        IntegerName,
        DefaultInteger);
  Finally
    TheIni.Free;
  End;
End;

{!~ Returns the ini value for a variable (StringName)
in the ini section (IniSection) of the ini file (TheIniFile).}
Function IniGetStringValue(
  TheIniFile            : String;
  IniSection            : String;
  StringName            : String;
  DefaultString         : String): String;
Var
  TheIni                : TIniFile;
Begin
  TheIni                  := TIniFile.Create(TheIniFile);
  Try
    Result :=
      TheIni.ReadString(
        IniSection,
        StringName,
        DefaultString);
    If Result = '' Then
    Begin
      Result := DefaultString;
    End;
  Finally
    TheIni.Free;
  End;
End;

{!~ Sets a variable (IntegerName) in the ini section (IniSection)
of the ini file (TheIniFile) with the value (IntegerValue).
If an exception is thrown the function returns False,
True otherwise.}
Function IniSetIntegerValue(
  TheIniFile            : String;
  IniSection            : String;
  IntegerName           : String;
  IntegerValue          : Integer): Boolean;
Var
  TheIni                : TIniFile;
Begin
  TheIni                := TIniFile.Create(TheIniFile);
  Try
    Try
      TheIni.WriteInteger(
        IniSection,
        IntegerName,
        IntegerValue);
      Result := True;
    Except
      Result := False;
    End;
  Finally
    TheIni.Free;
  End;
End;

{!~ Sets a variable (StringName) in the ini section (IniSection)
of the ini file (TheIniFile) with the value (StringValue).
If an exception is thrown the function returns False,
True otherwise.}
Function IniSetStringValue(
  TheIniFile            : String;
  IniSection            : String;
  StringName            : String;
  StringValue           : String): Boolean;
Var
  TheIni                : TIniFile;
Begin
  TheIni                := TIniFile.Create(TheIniFile);
  Try
    Try
      TheIni.WriteString(
        IniSection,
        StringName,
        StringValue);
      Result := True;
    Except
      Result := False;
    End;
  Finally
    TheIni.Free;
  End;
End;

{!~ Updates an ini file from a TStringList}
Procedure IniUpdateFromTStringList(
  TheIniFile            : String;
  IniSection            : String;
  StringListName        : String;
  CountField            : String;
  StringList            : TStringList);
Var
  TheIni                : TIniFile;
  i                     : Integer;
Begin
  TheIni                  := TIniFile.Create(TheIniFile);
  Try
    TheIni.EraseSection(IniSection);
    TheIni.WriteString(
      IniSection,
      CountField,
      IntToStr(StringList.Count));
    For i := 0 To StringList.Count - 1 Do
    Begin
      TheIni.WriteString(
        IniSection,
        StringListName+'['+intToStr(i)+']',
        StringList[i]);
    End;
  Finally
    TheIni.Free;
  End;
End;

{!~ Updates a TStringList from an ini file}
Procedure IniUpdateTStringList(
  TheIniFile            : String;
  IniSection            : String;
  StringListName        : String;
  CountField            : String;
  StringList            : TStringList);
Var
  TheIni                : TIniFile;
  i                     : Integer;
  {CountString           : String;}
  Count                 : Integer;
Begin
  TheIni                  := TIniFile.Create(TheIniFile);
  Try
    Count :=
      IniGetIntegerValue(
        TheIniFile,
        IniSection,
        CountField,
        0);

    StringList.Clear;
    For i := 0 To Count - 1 Do
    Begin
      StringList.Add(
        TheIni.ReadString(
                 IniSection,
                 StringListName+'['+intToStr(i)+']',
                 ''));
    End;
  Finally
    TheIni.Free;
  End;
End;

End.
Hosted by www.Geocities.ws

1