Главная страница
    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.015 c
3-27406
RDen
2003-09-18 12:17
2003.10.09
BDE выдаёт ошибку - At end of table


9-27296
KRIVOY
2003-04-05 20:11
2003.10.09
Кто-нибудь знает куда надо кидать glscene.inc при


9-27299
GL Forever!
2003-01-25 17:18
2003.10.09
Ориентация меша в пространстве (TMesh)


4-27782
YURiQUE
2003-08-02 12:00
2003.10.09
Иконка приложения


1-27500
Zhouck
2003-09-26 16:19
2003.10.09
Создание фреймов по типу фрейма





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