Форум: "Основная";
Текущий архив: 2003.10.09;
Скачать: [xml.tar.bz2];
ВнизINI как это делать Найти похожие ветки
← →
Vitaliygavrilov (2003-09-26 13:12) [0]Уважаемые мастера!
помогите советом как сохранить настройки своей программы в INI.
С уважением Гаврилов В.А.
← →
Юрий Федоров (2003-09-26 13:21) [1]см. TIniFile
← →
ZEE (2003-09-26 13:30) [2]или RxLib - TFormPlacement - IniFileName, IniSection (UseRegisrty:=false)
← →
}{unter (2003-09-29 14:54) [3]unit IniFile;
interface
uses
WinProcs, SysUtils, Classes;
const
IniName : ShortString = "c:\default.ini";
type
ENoIniSection = class(Exception) end;
TIniFile = class(TObject)
private
FFileName : array[0..255] of Char;
FSection : array[0..255] of Char;
TempVar : array[0..255] of Char;
TempData : array[0..255] of Char;
TempDefault : array[0..255] of Char;
function ReadSection : ShortString;
procedure SetSection(const Sect : ShortString);
function ReadFileName : TFileName;
procedure SetFileName(const FName : TFileName);
public
property FileName : TFileName
read ReadFileName write SetFileName;
property Section : ShortString
read ReadSection write SetSection;
constructor Create; virtual;
destructor Destroy; override;
{writing}
procedure WriteString(const Variable, Data : ShortString);
{-Write a string to the INI file}
{reading}
function ReadString(const Variable, DefaultVal : ShortString) : ShortString;
{-Read a string from the INI file}
function ReadInteger(const Variable : ShortString; const DefaultVal : Integer) : Integer;
{-Read a integer from the INI file}
{sections}
procedure DeleteSection(const Section : String);
{-Delete Section completely from the INI file}
procedure DeleteCurrentSection;
{-Delete the section currently being used}
procedure DeleteVariableFromSection(const Section, Variable : String);
{-Delete Variable from Section}
procedure DeleteVariable(const Variable : String);
{-Delete a variable from the current section}
end;
implementation
constructor TIniFile.Create;
begin
FileName := "";
Section := ""
end;
destructor TIniFile.Destroy;
begin
end;
function TIniFile.ReadSection : ShortString;
begin
Result := StrPas(FSection)
end;
procedure TIniFile.SetSection(const Sect : ShortString);
begin
StrPCopy(FSection, Sect)
end;
function TIniFile.ReadFileName : TFileName;
begin
Result := StrPas(FFileName)
end;
procedure TIniFile.SetFileName(const FName : TFileName);
begin
StrPCopy(FFileName, FName)
end;
procedure TIniFile.WriteString(const Variable, Data : ShortString);
begin
if (Section = "") then
raise ENoIniSection.Create(ReadFileName);
WritePrivateProfileString(FSection, StrPCopy(TempVar, Variable),
StrPCopy(TempData, Data), FFileName)
end;
function TIniFile.ReadInteger(const Variable : ShortString; const DefaultVal : Integer) : Integer;
var
TmpDef : ShortString;
begin
TmpDef := IntToStr(DefaultVal);
try
Result := StrToInt(ReadString(Variable,TmpDef));
except
Result := DefaultVal
end
end;
function TIniFile.ReadString(const Variable, DefaultVal : ShortString) : ShortString;
begin
if (Section = "") then
raise ENoIniSection.Create(ReadFileName);
GetPrivateProfileString(FSection, StrPCopy(TempVar, Variable),
StrPCopy(TempDefault, DefaultVal),
TempData, 255, FFileName);
Result := StrPas(TempData)
end;
procedure TIniFile.DeleteSection(const Section : String);
{-Delete Section completely from the INI file}
var
Temp : array[0..255] of Char;
begin
WritePrivateProfileString(StrPCopy(Temp, Section), nil, nil, FFileName)
end;
procedure TIniFile.DeleteCurrentSection;
{-Delete the section currently being used}
begin
DeleteSection(StrPas(FSection))
end;
procedure TIniFile.DeleteVariableFromSection(const Section, Variable : String);
{-Delete Variable from Section}
var
TempSec : array[0..255] of Char;
TempKey : array[0..255] of Char;
begin
WritePrivateProfileString(StrPCopy(TempSec, Section),
StrPCopy(TempKey, Variable), nil, FFileName)
end;
procedure TIniFile.DeleteVariable(const Variable : String);
{-Delete a variable from the current section}
begin
DeleteVariableFromSection(StrPas(FSection), Variable)
end;
end.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2003.10.09;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.012 c