Главная страница
    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.46 MB
Время: 0.012 c
3-27353
Gloony
2003-09-19 08:44
2003.10.09
Кривые символы в табл. Paradox


3-27360
Apollo
2003-09-19 13:01
2003.10.09
Фильтрация


1-27473
Chlavik
2003-09-26 16:55
2003.10.09
Parent у главной формы


3-27404
Вероника
2003-09-18 07:42
2003.10.09
FireBird даёт ошибку. Неделю назад всё было нормально!


3-27370
P0tia
2003-09-18 19:51
2003.10.09
Проблема с Excel





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский