Bu unit program ini ve register işleminde kullanılır.
Kod: Tümünü seç
Unit Ads_Ini;
{Copyright(c)2000 Advanced Delphi Systems
Richard Maley
Advanced Delphi Systems
12613 Maidens Bower Drive
Potomac, MD 20854 USA
phone 301-840-1554
maley@advdelphisys.com
The code herein can be used or modified by anyone. Please retain references
to Richard Maley at Advanced Delphi Systems. If you make improvements to the
code please send your improvements to maley@advdelphisys.com so that the
entire Delphi community can benefit. All comments are welcome.
}
Interface
Uses
SysUtils, Classes, ExtCtrls, StdCtrls, Ads_Strg, IniFiles,
Registry, Windows;
{!~RegGetStringValue:
Gets the value of a variable (VarName) in the registry.
If the variable does not exist or is null the value
of VarDefault is returned.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'.}
Function RegGetStringValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarDefault: String): String;
{!~RegGetIntegerValue:
Gets the value of a variable (VarName) in the registry.
If the variable does not exist or is null the value
of VarDefault is returned.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'.}
Function RegGetIntegerValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarDefault: Integer): Integer;
{!~RegGetBooleanValue:
Gets the value of a variable (VarName) in the registry.
If the variable does not exist or is null the value
of VarDefault is returned.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'.}
Function RegGetBooleanValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarDefault: Boolean): Boolean;
{!~RegSetStringValue:
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetStringValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: String): Boolean;
{!~RegSetIntegerValue:
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetIntegerValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: Integer): Boolean;
{!~RegSetBooleanValue:
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetBooleanValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: Boolean): Boolean;
{!~RegDeleteVariable:
Deletes a variable (VarName) in the registry.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegDeleteVariable(
const RootKey : HKEY;
const SubKey : String;
const VarName : String): Boolean;
{!~RegDeleteSection:
DANGEROUS!!! BE CAREFUL!!!
Deletes a complete section from the registry.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp', the MyApp section
would be deleted. The SubKey will be removed with all
associated values. If an exception is thrown the
function returns False, True otherwise.}
Function RegDeleteSection(
const RootKey : HKEY;
const SubKey : String): Boolean;
{!~ 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;
{!~RegSetStringValue:
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetStringValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: String): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Reg.WriteString('', VarName, VarValue);
Result := True;
Except
Result := False;
End;
Finally
Reg.Free;
End;
end;
{!~RegSetIntegerValue:
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetIntegerValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: Integer): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Reg.WriteInteger('', VarName, VarValue);
Result := True;
Except
Result := False;
End;
Finally
Reg.Free;
End;
end;
{!~RegSetBooleanValue:
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetBooleanValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: Boolean): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Reg.WriteBool('', VarName, VarValue);
Result := True;
Except
Result := False;
End;
Finally
Reg.Free;
End;
end;
{!~RegSetExpandStringValue:
Call RegSetExpandStringValue to store a string that contains
unexpanded references to environment variables such as
“%PATH%”.
Sets a variable (VarName) in the registry to the value
VarValue. The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegSetExpandStringValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarValue: String): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Reg.WriteExpandString(VarName, VarValue);
Result := True;
Except
Result := False;
End;
Finally
Reg.Free;
End;
end;
{!~RegGetStringValue:
Gets the value of a variable (VarName) in the registry.
If the variable does not exist or is null the value
of VarDefault is returned.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'.}
Function RegGetStringValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarDefault: String): String;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Result :=
Reg.
ReadString
('', VarName, VarDefault);
Finally
Reg.Free;
End;
end;
{!~RegGetIntegerValue:
Gets the value of a variable (VarName) in the registry.
If the variable does not exist or is null the value
of VarDefault is returned.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'.}
Function RegGetIntegerValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarDefault: Integer): Integer;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Result :=
Reg.
ReadInteger
('', VarName, VarDefault);
Finally
Reg.Free;
End;
end;
{!~RegGetBooleanValue:
Gets the value of a variable (VarName) in the registry.
If the variable does not exist or is null the value
of VarDefault is returned.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'.}
Function RegGetBooleanValue(
const RootKey : HKEY;
const SubKey : String;
const VarName : String;
const VarDefault: Boolean): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Result :=
Reg.
ReadBool
('', VarName, VarDefault);
Finally
Reg.Free;
End;
end;
{!~RegDeleteVariable:
Deletes a variable (VarName) in the registry.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. If an exception is
thrown the function returns False, True otherwise.}
Function RegDeleteVariable(
const RootKey : HKEY;
const SubKey : String;
const VarName : String): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Reg.DeleteKey('', VarName);
Result := True;
Except
Result := False;
End;
Finally
Reg.Free;
End;
end;
{!~RegDeleteSection:
DANGEROUS!!! BE CAREFUL!!!
Deletes a complete section from the registry.
The Registry's RootKey must be provided as the
RootKey value, e.g., HKEY_LOCAL_MACHINE (note no quotes,
double quotes or brackets). Subkey is the key path under
the RootKey, e.g.,'\Software\MyApp'. The SubKey will
be removed with all associated values. If an exception is
thrown the function returns False, True otherwise.}
Function RegDeleteSection(
const RootKey : HKEY;
const SubKey : String): Boolean;
Var
Reg : TRegIniFile;
begin
Reg := TRegIniFile.Create('');
Try
Try
Reg.RootKey := RootKey;
Reg.OpenKey(SubKey,True);
Reg.EraseSection('');
Result := True;
Except
Result := False;
End;
Finally
Reg.Free;
End;
end;
End.