Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 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.47 MB
Время: 0.007 c
1-27429
Viktor Kushnir
2003-09-28 14:13
2003.10.09
RGB наоборот.


1-27568
Alex Shulg
2003-09-26 18:09
2003.10.09
Отображение Splash-формы!


1-27455
romeo
2003-09-27 18:31
2003.10.09
Копирование и вставка компонента... Как?


14-27660
Омлет
2003-09-22 00:01
2003.10.09
Именинники 22 сентября !


1-27430
@Ujin
2003-09-28 16:02
2003.10.09
Win 9X и WinNT в чем проблема?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский