home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 November
/
Chip_2002-11_cd1.bin
/
zkuste
/
delphi
/
unity
/
d56
/
DW
/
DW10242.ZIP
/
IniWorks.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2001-09-11
|
12KB
|
242 lines
unit IniWorks;
interface
uses Classes, Forms, Graphics, SysUtils, IniFiles, StringWorks;
function IniValueList(Ini, Section: String): TStringList;
function IniValueNameList(Ini, Section: String): TStringList;
function IniReadInteger(Ini, Section, Value: String): Integer;
function IniReadBool(Ini, Section, Value: String): Boolean;
function IniWriteBool(Ini, Section, Item: String; Value: Boolean): Boolean;
procedure IniSaveForm(Form: TForm; IniFile: String);
procedure IniLoadForm(Form: TForm; IniFile: String);
function IsNotNIL(Ini: TIniFile; Section, Item: String): Boolean;
const NILSTRING = '!º>NLNONE<º!';
implementation
function IniValueList(Ini, Section: String): TStringList;
var
I: Integer;
IniF: TIniFile;
TempList: TStringList;
TempStr: String;
begin
result:= TStringList.Create;
TempList:= TStringList.Create;
if not FileExists(Ini) then exit;
IniF:= TIniFile.Create(Ini);
with IniF do begin
if not SectionExists(Section) then exit;
ReadSectionValues(Section, TempList);
if TempList.Count = 0 then exit else if TempList.Count = 1 then begin
TempStr:= TempList[0];
result.Add(StrPart(TempStr, Pos('=', TempStr) + 1,
StringLen(TempStr)+1));
end else
if TempList.Count > 1 then
for I:= 0 to TempList.Count - 1 do begin
TempStr:= TempList[I];
result.Add(StrPart(TempStr, Pos('=', TempStr) + 1,
StringLen(TempStr)+1));
end;
end;
TempList.Free;
IniF.Free;
end;
function IniValueNameList(Ini, Section: String): TStringList;
var
I: Integer;
IniF: TIniFile;
TempList: TStringList;
TempStr: String;
begin
result:= TStringList.Create;
TempList:= TStringList.Create;
if not FileExists(Ini) then exit;
IniF:= TIniFile.Create(Ini);
with IniF do begin
if not SectionExists(Section) then exit;
ReadSectionValues(Section, TempList);
if TempList.Count = 0 then exit else if TempList.Count = 1 then
result.Add(StrLeft(TempStr, Pos('=', TempStr) - 1)) else
if TempList.Count > 1 then
for I:= 0 to TempList.Count - 1 do begin
TempStr:= TempList[I];
result.Add(StrLeft(TempStr, Pos('=', TempStr) - 1));
end;
end;
TempList.Free;
IniF.Free;
end;
function IniReadInteger(Ini, Section, Value: String): Integer;
var IniF: TIniFile;
begin
result:= 0;
if not FileExists(Ini) then exit;
IniF:= TIniFile.Create(Ini);
if not IniF.SectionExists(Section) or not IniF.ValueExists(Section, Value)
then exit;
result:= IniF.ReadInteger(Section, Value, 0);
IniF.Free;
end;
function IniReadBool(Ini, Section, Value: String): Boolean;
var IniF: TIniFile;
begin
result:= FALSE;
if not FileExists(Ini) then exit;
IniF:= TIniFile.Create(Ini);
if not IniF.SectionExists(Section) or not IniF.ValueExists(Section, Value)
then exit;
result:= IniF.ReadBool(Section, Value, FALSE);
IniF.Free;
end;
function IniWriteBool(Ini, Section, Item: String; Value: Boolean): Boolean;
var IniF: TIniFile;
begin
result:= FALSE;
if not FileExists(Ini) then exit;
IniF:= TIniFile.Create(Ini);
if not IniF.SectionExists(Section) or not IniF.ValueExists(Section, Item)
then exit;
IniF.WriteBool(Section, Item, Value);
result:= IniF.ReadBool(Section, Item, FALSE);
IniF.Free;
end;
procedure IniSaveForm(Form: TForm; IniFile: String);
var
Ini: TIniFile;
FN: String;
begin
FN:= Form.Name;
Ini:= TIniFile.Create(IniFile);
with Ini do begin
if Assigned(Form.Action) then WriteString(FN, 'Action', Form.Action.Name) else WriteString(FN, 'Action', NILSTRING);
if Assigned(Form.ActiveControl) then WriteString(FN, 'ActiveControl', Form.ActiveControl.Name) else WriteString(FN, 'ActiveControl', NILSTRING);
WriteString(FN, 'Align', AlignToStr(Form.Align));
WriteString(FN, 'Anchors', AnchorsToStr(Form.Anchors));
WriteBool(FN, 'AutoScroll', Form.AutoScroll);
WriteBool(FN, 'AutoSize', Form.AutoSize);
WriteString(FN, 'BiDiMode', BiDiModeToStr(Form.BiDiMode));
WriteString(FN, 'BorderIcons', BorderIconsToStr(Form.BorderIcons));
WriteString(FN, 'BorderStyle', BorderStyleToStr(Form.BorderStyle));
WriteInteger(FN, 'BorderWidth', Form.BorderWidth);
WriteString(FN, 'Caption', Form.Caption);
WriteInteger(FN, 'ClientHeight', Form.ClientHeight);
WriteInteger(FN, 'ClientWidth', Form.ClientWidth);
WriteString(FN, 'Color', ColorToString(Form.Color));
WriteString(FN, 'Constraints', ConstraintsToStr(Form.Constraints));
WriteInteger(FN, 'Cursor', Int64(Form.Cursor));
WriteString(FN, 'DefaultMonitor', DefaultMonitorToStr(Form.DefaultMonitor));
WriteBool(FN, 'DockSite', Form.DockSite);
WriteString(FN, 'DragKind', DragKindToStr(Form.DragKind));
WriteString(FN, 'DragMode', DragModeToStr(Form.DragMode));
WriteBool(FN, 'Enabled', Form.Enabled);
WriteString(FN, 'Font', FontToStr(Form.Font));
WriteString(FN, 'FormStyle', FormStyleToStr(Form.FormStyle));
WriteInteger(FN, 'Height', Form.Height);
WriteInteger(FN, 'HelpContext', Form.HelpContext);
WriteString(FN, 'HelpFile', Form.HelpFile);
WriteString(FN, 'Hint', Form.Hint);
WriteString(FN, 'HorzScrollBar', ControlScrollBarToStr(Form.HorzScrollBar));
if Assigned(Form.Icon) then WriteString(FN, 'Icon', Form.Icon.ClassName) else WriteString(FN, 'Icon', NILSTRING);
WriteBool(FN, 'KeyPreview', Form.KeyPreview);
WriteInteger(FN, 'Left', Form.Left);
if Assigned(Form.Menu) then WriteString(FN, 'Menu', Form.Menu.Name) else WriteString(FN, 'Menu', NILSTRING);
WriteString(FN, 'Name', Form.Name);
if Assigned(Form.ObjectMenuItem) then WriteString(FN, 'ObjectMenuItem', Form.ObjectMenuItem.Name) else WriteString(FN, 'ObjectMenuItem', NILSTRING);
WriteBool(FN, 'ParentBiDiMode', Form.ParentBiDiMode);
WriteBool(FN, 'ParentFont', Form.ParentFont);
WriteInteger(FN, 'PixelsPerInch', Form.PixelsPerInch);
if Assigned(Form.PopupMenu) then WriteString(FN, 'PopupMenu', Form.PopupMenu.Name) else WriteString(FN, 'PopupMenu', NILSTRING);
WriteString(FN, 'Position', PositionToStr(Form.Position));
WriteString(FN, 'PrintScale', PrintScaleToStr(Form.PrintScale));
WriteBool(FN, 'Scaled', Form.Scaled);
WriteBool(FN, 'ShowHint', Form.ShowHint);
WriteInteger(FN, 'Tag', Form.Tag);
WriteInteger(FN, 'Top', Form.Top);
WriteBool(FN, 'UseDockManager', Form.UseDockManager);
WriteString(FN, 'VertScrollBar', ControlScrollBarToStr(Form.VertScrollBar));
WriteBool(FN, 'Visible', Form.Visible);
WriteInteger(FN, 'Width', Form.Width);
if Assigned(Form.WindowMenu) then WriteString(FN, 'WindowMenu', Form.WindowMenu.Name) else WriteString(FN, 'WindowMenu', NILSTRING);
WriteString(FN, 'WindowState', WindowStateToStr(Form.WindowState));
end;
end;
procedure IniLoadForm(Form: TForm; IniFile: String);
var
Ini: TIniFile;
FN: String;
begin
Ini:= TIniFile.Create(IniFile);
FN:= Form.Name;
with Ini do begin
if IsNotNIL(Ini, FN, 'Action') then Form.Action.Name:= ReadString(FN, 'Action', NILSTRING);
if IsNotNIL(Ini, FN, 'ActiveControl') then Form.ActiveControl.Name:= ReadString(FN, 'ActiveControl', NILSTRING);
Form.Align:= StrToAlign(ReadString(FN, 'Align', NILSTRING));
Form.Anchors:= StrToAnchors(ReadString(FN, 'Anchors', NILSTRING));
Form.AutoScroll:= ReadBool(FN, 'AutoScroll', TRUE);
Form.AutoSize:= ReadBool(FN, 'AutoSize', TRUE);
Form.BiDiMode:= StrToBiDiMode(ReadString(FN, 'BiDiMode', NILSTRING));
Form.BorderIcons:= StrToBorderIcons(ReadString(FN, 'BorderIcons', NILSTRING));
Form.BorderStyle:= StrToBorderStyle(ReadString(FN, 'BorderStyle', NILSTRING));
Form.BorderWidth:= ReadInteger(FN, 'BorderWidth', 0);
Form.Caption:= ReadString(FN, 'Caption', Form.Name);
Form.ClientHeight:= ReadInteger(FN, 'ClientHeight', Form.ClientHeight);
Form.ClientWidth:= ReadInteger(FN, 'ClientWidth', Form.ClientWidth);
Form.Color:= StringToColor(ReadString(FN, 'Color', ColorToString(Form.Color)));
Form.Constraints:= StrToConstraints(ReadString(FN, 'Constraints', ConstraintsToStr(Form.Constraints)));
Form.Cursor:= ReadInteger(FN, 'Cursor', Int64(Form.Cursor));
Form.DefaultMonitor:= StrToDefaultMonitor(ReadString(FN, 'DefaultMonitor', DefaultMonitorToStr(Form.DefaultMonitor)));
Form.DockSite:= ReadBool(FN, 'DockSite', Form.DockSite);
Form.DragKind:= StrToDragKind(ReadString(FN, 'DragKind', DragKindToStr(Form.DragKind)));
Form.DragMode:= StrToDragMode(ReadString(FN, 'DragMode', DragModeToStr(Form.DragMode)));
Form.Enabled:= ReadBool(FN, 'Enabled', Form.Enabled);
Form.Font:= StrToFont(ReadString(FN, 'Font', FontToStr(Form.Font)));
Form.FormStyle:= StrToFormStyle(ReadString(FN, 'FormStyle', FormStyleToStr(Form.FormStyle)));
Form.Height:= ReadInteger(FN, 'Height', Form.Height);
Form.HelpContext:= ReadInteger(FN, 'HelpContext', Form.HelpContext);
Form.HelpFile:= ReadString(FN, 'HelpFile', Form.HelpFile);
Form.Hint:= ReadString(FN, 'Hint', Form.Hint);
Form.HorzScrollBar:= StrToControlScrollBar(ReadString(FN, 'HorzScrollBar', ''{ControlScrollBarToStr(Form.HorzScrollBar)}));
// if IsNotNIL(Ini, FN, 'Icon') then Form.Icon.ClassName:= ReadString(FN, 'Icon', Form.Icon.ClassName));
Form.KeyPreview:= ReadBool(FN, 'KeyPreview', Form.KeyPreview);
Form.Left:= ReadInteger(FN, 'Left', Form.Left);
if IsNotNIL(Ini, FN, 'Menu') then Form.Menu.Name:= ReadString(FN, 'Menu', Form.Menu.Name);
Form.Name:= ReadString(FN, 'Name', Form.Name);
if IsNotNIL(Ini, FN, 'ObjectMenuItem') then Form.ObjectMenuItem.Name:= ReadString(FN, 'ObjectMenuItem', Form.ObjectMenuItem.Name);
Form.ParentBiDiMode:= ReadBool(FN, 'ParentBiDiMode', Form.ParentBiDiMode);
Form.ParentFont:= ReadBool(FN, 'ParentFont', Form.ParentFont);
Form.PixelsPerInch:= ReadInteger(FN, 'PixelsPerInch', Form.PixelsPerInch);
if IsNotNIL(Ini, FN, 'PopupMenu') then Form.PopupMenu.Name:= ReadString(FN, 'PopupMenu', Form.PopupMenu.Name);
Form.Position:= StrToPosition(ReadString(FN, 'Position', PositionToStr(Form.Position)));
Form.PrintScale:= StrToPrintScale(ReadString(FN, 'PrintScale', PrintScaleToStr(Form.PrintScale)));
Form.Scaled:= ReadBool(FN, 'Scaled', Form.Scaled);
Form.ShowHint:= ReadBool(FN, 'ShowHint', Form.ShowHint);
Form.Tag:= ReadInteger(FN, 'Tag', Form.Tag);
Form.Top:= ReadInteger(FN, 'Top', Form.Top);
Form.UseDockManager:= ReadBool(FN, 'UseDockManager', Form.UseDockManager);
// Form.VertScrollBar:= StrToControlScrollBar(ReadString(FN, 'VertScrollBar', ControlScrollBarToStr(Form.VertScrollBar)));
Form.Visible:= ReadBool(FN, 'Visible', Form.Visible);
Form.Width:= ReadInteger(FN, 'Width', Form.Width);
if IsNotNIL(Ini, FN, 'WindowMenu') then Form.WindowMenu.Name:= ReadString(FN, 'WindowMenu', Form.WindowMenu.Name);
Form.WindowState:= StrToWindowState(ReadString(FN, 'WindowState', WindowStateToStr(Form.WindowState)));
end;
end;
function IsNotNIL(Ini: TIniFile; Section, Item: String): Boolean;
begin
result:= not (Ini.ReadString(Section, Item, NILSTRING) = NILSTRING);
end;
end.