home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kolekce / d123456 / SIMONS.ZIP / Units / IniList.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-12-18  |  19.6 KB  |  754 lines

  1. unit IniList;
  2.  
  3. { TIniList (C)opyright 2001 Version 1.00
  4.   Autor : Simon Reinhardt
  5.   eMail : reinhardt@picsoft.de
  6.   Internet : http://www.picsoft.de
  7.  
  8.   Die Klasse TIniList ist eine Stringliste, die um die Methoden
  9.   von TIniFile erweitert wurde. Man hat somit eine M÷glichkeit,
  10.   Werte verschiedener Formate im Speicher zu halten und diese
  11.   erst bei Bedarf in ein Inifile zu speichern oder aus einem
  12.   Inifile zu laden.
  13.  
  14.   Die Komponente ist Public Domain, das Urheberrecht liegt aber
  15.   beim Autor. }
  16.  
  17. interface
  18.  
  19. {$I SRDefine.inc}
  20.  
  21. uses Classes;
  22.  
  23. type
  24.   TIniList = class(TComponent)
  25.   private
  26.     FLines           : TStringList;
  27.     FSeparator       : char;
  28.     FCaseSens,
  29.     FDateFloat       : boolean;
  30.     FFileName,
  31.     FTitle           : string;
  32.     FOnChange,
  33.     FOnChanging,
  34.     FOnSectionChange,
  35.     FOnKeyChange,
  36.     FOnValueChange   : TNotifyEvent;
  37.  
  38.     procedure SetSeparator(NewValue: char);
  39.     procedure SetTitle(NewValue: string);
  40.  
  41.   protected
  42.     procedure Changed; virtual;
  43.     procedure Changing; virtual;
  44.     procedure SectionChange; virtual;
  45.     procedure KeyChange; virtual;
  46.     procedure ValueChange; virtual;
  47.  
  48.     function AddKey(const SectionIdx:integer;const Key, Value: string):integer;
  49.     function AddSection(const Section: string):integer;
  50.     function GetKeyFromLine(const Line:string):string;
  51.     function GetKeyIndex(const Section, Key: string):integer;
  52.     function GetKeyIndexFromLine(const SectionIdx:integer;const Key: string):integer;
  53.     function GetSectionIndex(const Section: string):integer;
  54.     function GetValueFromLine(const Line:string):string;
  55.     function ReadValue(const Section, Key: string):string;
  56.     procedure WriteValue(const Section, Key: string; Value: string);
  57.  
  58.   public
  59.     constructor Create(AComponent: TComponent); override;
  60.     destructor Destroy; override;
  61.  
  62.     procedure Clear;
  63.     function LoadFromFile:boolean;
  64.     function LoadFromStream(AStream: TStream):boolean;
  65.     function SaveToFile:boolean;
  66.     function SaveToStream(AStream: TStream):boolean;
  67.  
  68.     procedure DeleteKey(const Section, Key: String);
  69.     procedure EraseSection(const Section: string);
  70.     function KeyCount(const Section: string):integer;
  71.     function SectionCount:integer;
  72.  
  73.     function ReadBool(const Section, Key: string; Default: Boolean): Boolean;
  74.     function ReadDate(const Section, Key: string; Default: TDateTime): TDateTime;
  75.     function ReadDateTime(const Section, Key: string; Default: TDateTime): TDateTime;
  76.     function ReadFloat(const Section, Key: string; Default: Double): Double;
  77.     function ReadInteger(const Section, Key: string; Default: Longint): Longint;
  78.     function ReadString(const Section, Key, Default: string): string;
  79.     function ReadTime(const Section, Key: string; Default: TDateTime): TDateTime;
  80.  
  81.     procedure ReadSection(const Section: string; AStrings: TStrings);
  82.     procedure ReadSections(AStrings: TStrings);
  83.     procedure ReadSectionKeys(const Section: string; AStrings: TStrings);
  84.     procedure ReadSectionValues(const Section: string; AStrings: TStrings);
  85.  
  86.     procedure WriteBool(const Section, Key: string; Value: Boolean);
  87.     procedure WriteDate(const Section, Key: string; Value: TDateTime);
  88.     procedure WriteDateTime(const Section, Key: string; Value: TDateTime);
  89.     procedure WriteFloat(const Section, Key: string; Value: Double);
  90.     procedure WriteInteger(const Section, Key: string; Value: Longint);
  91.     procedure WriteString(const Section, Key, Value: String);
  92.     procedure WriteTime(const Section, Key: string; Value: TDateTime);
  93.  
  94.   published
  95.     property CaseSensitive: boolean read FCaseSens write FCaseSens;
  96.     property DateTimeAsFloat: boolean read FDateFloat write FDateFloat;
  97.     property IniFilename: string read FFileName write FFileName;
  98.     property Separator: char read FSeparator write SetSeparator;
  99.     property Title: string read FTitle write SetTitle;
  100.  
  101.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  102.     property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
  103.     property OnSectionChange: TNotifyEvent read FOnSectionChange write FOnSectionChange;
  104.     property OnKeyChange: TNotifyEvent read FOnKeyChange write FOnKeyChange;
  105.     property OnValueChange: TNotifyEvent read FOnValueChange write FOnValueChange;
  106.  
  107.   end;
  108.  
  109. procedure Register;
  110.  
  111. implementation
  112.  
  113. {$IFDEF SR_Delphi2_Up}
  114. {$R *.D32}
  115. {$ELSE}
  116. {$R *.D16}
  117. {$ENDIF}
  118.  
  119. uses Consts, SysUtils, SRUtils;
  120.  
  121. constructor TIniList.Create(AComponent: TComponent);
  122. begin
  123.   inherited Create(AComponent);
  124.  
  125.   FSeparator:='=';
  126.   FCaseSens:=false;
  127.   FDateFloat:=false;
  128.   FFileName:='';
  129.   FTitle:='';
  130.  
  131.   FLines:=TStringList.Create;
  132.   FLines.Add('; NoTitle');
  133. end;
  134.  
  135. destructor TIniList.Destroy;
  136. begin
  137.   FOnChange := nil;
  138.   FOnChanging := nil;
  139.  
  140.   if assigned(FLines) then
  141.     FreeAndNil(FLines);
  142.  
  143.   inherited Destroy;
  144. end; {Destroy}
  145.  
  146. function TIniList.AddKey(const SectionIdx:integer;const Key, Value: string):integer;
  147. var AIndex : integer;
  148. begin
  149.   Changing;
  150.   AIndex:=GetKeyIndexFromLine(SectionIdx, Key);
  151.   if AIndex>=0 then begin
  152.     Result:=AIndex;
  153.     FLines[AIndex]:=Key+FSeparator+Value;
  154.     ValueChange;
  155.   end
  156.   else begin
  157.     Result:=SectionIdx+1;
  158.     FLines.Insert(SectionIdx+1, Key+FSeparator+Value);
  159.     KeyChange;
  160.   end;
  161.   Changed;
  162. end; {AddKey}
  163.  
  164. function TIniList.AddSection(const Section: string):integer;
  165. var AIndex : integer;
  166. begin
  167.   AIndex:=GetSectionIndex(Section);
  168.   if AIndex>=0 then
  169.     Result:=AIndex
  170.   else begin
  171.     Changing;
  172.     FLines.Add('');
  173.     Result:=FLines.Add('['+Section+']');
  174.     SectionChange;
  175.     Changed;
  176.   end;
  177. end; {AddSection}
  178.  
  179. procedure TIniList.Changed;
  180. begin
  181.   if Assigned(FOnChange) then
  182.     FOnChange(Self);
  183. end; {Changed}
  184.  
  185. procedure TIniList.Changing;
  186. begin
  187.   if Assigned(FOnChanging) then
  188.     FOnChanging(Self);
  189. end; {Changing}
  190.  
  191. procedure TIniList.SectionChange;
  192. begin
  193.   if Assigned(FOnSectionChange) then
  194.     FOnSectionChange(Self);
  195. end; {Changed}
  196.  
  197. procedure TIniList.KeyChange;
  198. begin
  199.   if Assigned(FOnKeyChange) then
  200.     FOnKeyChange(Self);
  201. end; {Changed}
  202.  
  203. procedure TIniList.ValueChange;
  204. begin
  205.   if Assigned(FOnValueChange) then
  206.     FOnValueChange(Self);
  207. end; {Changed}
  208.  
  209. procedure TIniList.Clear;
  210. begin
  211.   Changing;
  212.   FLines.Clear;
  213.   Changed;
  214. end; {Clear}
  215.  
  216. procedure TIniList.DeleteKey(const Section, Key: String);
  217. var KeyIndex  : integer;
  218. begin
  219.   KeyIndex:=GetKeyIndex(Section, Key);
  220.   if KeyIndex>=0 then begin
  221.     Changing;
  222.     FLines.Delete(KeyIndex);
  223.     KeyChange;
  224.     if KeyCount(Section)=0 then
  225.       EraseSection(Section);
  226.     Changed;
  227.   end;
  228. end; {DeleteKey}
  229.  
  230. procedure TIniList.EraseSection(const Section: string);
  231. var SectIndex : integer;
  232.     ALine     : string;
  233.     Abort     : boolean;
  234. begin
  235.   SectIndex:=GetSectionIndex(Section);
  236.   if SectIndex>=0 then begin
  237.     if SectIndex>0 then begin
  238.       ALine:=Trim(FLines[SectIndex-1]);
  239.       if ALine='' then begin
  240.         dec(SectIndex);
  241.         FLines.Delete(SectIndex);
  242.       end;
  243.     end;
  244.     ALine:='';
  245.     Abort:=false;
  246.     Changing;
  247.     FLines.BeginUpdate;
  248.     repeat
  249.       FLines.Delete(SectIndex);
  250.       if SectIndex<FLines.Count then
  251.         ALine:=FLines[SectIndex]
  252.       else
  253.         Abort:=true;
  254.     until Abort or (ALine='') or ((ALine<>'') and (ALine[1]='['));
  255.     FLines.EndUpdate;
  256.     SectionChange;
  257.     Changed;
  258.   end;
  259. end; {EraseSection}
  260.  
  261. function TIniList.GetKeyFromLine(const Line:string):string;
  262. var P : integer;
  263. begin
  264.   Result:='';
  265.   P:=Pos(FSeparator, Line);
  266.   if P>1 then
  267.     Result:=copy(Line, 1, P-1);
  268. end; {GetKeyFromLine}
  269.  
  270. function TIniList.GetKeyIndex(const Section, Key: string):integer;
  271. var AIndex,
  272.     ACount : integer;
  273.     ALine,
  274.     Key1,
  275.     Key2   : string;
  276. begin
  277.   Result:=-1;
  278.   ACount:=FLines.Count;
  279.   AIndex:=GetSectionIndex(Section);
  280.   if (ACount>0) and (AIndex>=0) then begin
  281.     if FCaseSens then
  282.       Key1:=Key
  283.     else
  284.       Key1:=UpperCase(Key);
  285.     repeat
  286.       inc(AIndex);
  287.       if AIndex<ACount then begin
  288.         ALine:=FLines[AIndex];
  289.         if FCaseSens then
  290.           Key2:=GetKeyFromLine(ALine)
  291.         else
  292.           Key2:=UpperCase(GetKeyFromLine(ALine));
  293.         if Key1=Key2 then
  294.           Result:=AIndex;
  295.       end;
  296.     until (Result>=0) or (AIndex>=ACount) or (ALine='')
  297.      or ((ALine<>'') and (ALine[1]='['));
  298.   end;
  299. end; {GetKeyIndex}
  300.  
  301. function TIniList.GetKeyIndexFromLine(const SectionIdx:integer;const Key: string):integer;
  302. var AIndex,
  303.     ACount : integer;
  304.     ALine,
  305.     Key1,
  306.     Key2   : string;
  307. begin
  308.   Result:=-1;
  309.   ACount:=FLines.Count;
  310.   if (ACount>0) and (SectionIdx>=0) then begin
  311.     if FCaseSens then
  312.       Key1:=Key
  313.     else
  314.       Key1:=UpperCase(Key);
  315.     AIndex:=SectionIdx;
  316.     repeat
  317.       inc(AIndex);
  318.       if AIndex<ACount then begin
  319.         ALine:=FLines[AIndex];
  320.         if FCaseSens then
  321.           Key2:=GetKeyFromLine(ALine)
  322.         else
  323.           Key2:=UpperCase(GetKeyFromLine(ALine));
  324.         if Key1=Key2 then
  325.           Result:=AIndex;
  326.       end;
  327.     until (Result>=0) or (AIndex>=ACount) or (ALine='')
  328.      or ((ALine<>'') and (ALine[1]='['));
  329.   end;
  330. end; {GetKeyIndexFromLine}
  331.  
  332. function TIniList.GetSectionIndex(const Section: string):integer;
  333. var AIndex,
  334.     ACount : integer;
  335.     ASect,
  336.     ALine  : string;
  337. begin
  338.   Result:=-1;
  339.   ACount:=FLines.Count;
  340.   if ACount>0 then begin
  341.     if FCaseSens then
  342.       ASect:=UpperCase(Section)
  343.     else
  344.       ASect:=Section;
  345.     for AIndex:=0 to ACount-1 do begin
  346.       if FCaseSens then
  347.         ALine:=UpperCase(FLines[AIndex])
  348.       else
  349.         ALine:=FLines[AIndex];
  350.       if (ALine<>'') and (ALine[1]='[') and
  351.        (copy(ALine, 2, length(ALine)-2)=ASect) then begin
  352.         Result:=AIndex;
  353.         Exit;
  354.       end;
  355.     end;
  356.   end;
  357. end; {GetSectionIndex}
  358.  
  359. function TIniList.GetValueFromLine(const Line:string):string;
  360. var P,L : integer;
  361. begin
  362.   Result:='';
  363.   P:=Pos(FSeparator, Line);
  364.   L:=length(Line);
  365.   if (P>0) and (P<L) then
  366.     Result:=copy(Line, P+1, L-P);
  367. end; {GetValueFromLine}
  368.  
  369. function TIniList.KeyCount(const Section: string):integer;
  370. var SectionIdx,
  371.     KCount,
  372.     AIndex,
  373.     ACount     : integer;
  374.     ALine      : string;
  375. begin
  376.   KCount:=0;
  377.   ACount:=FLines.Count;
  378.   SectionIdx:=GetSectionIndex(Section);
  379.   if (ACount>0) and (SectionIdx>=0) then begin
  380.     AIndex:=SectionIdx;
  381.     repeat
  382.       inc(AIndex);
  383.       if AIndex<ACount then begin
  384.         ALine:=Trim(FLines[AIndex]);
  385.         if (ALine<>'') and (ALine[1]<>'[') and (ALine[1]<>';') then
  386.           inc(KCount);
  387.       end;
  388.     until (AIndex>=ACount) or (ALine='')
  389.      or ((ALine<>'') and (ALine[1]='['));
  390.   end;
  391.   Result:=KCount;
  392. end; {KeyCount}
  393.  
  394. function TIniList.LoadFromFile:boolean;
  395. begin
  396.   Result:=false;
  397.   if FFileName<>'' then begin
  398.     try
  399.       Changing;
  400.       FLines.LoadFromFile(FFileName);
  401.       SetTitle(FTitle);
  402.       Changed;
  403.       Result:=true;
  404.     except
  405.       Raise;
  406.     end;
  407.   end;
  408. end; {LoadFromFile}
  409.  
  410. function TIniList.LoadFromStream(AStream: TStream):boolean;
  411. begin
  412.   Result:=false;
  413.   if assigned(AStream) then begin
  414.     try
  415.       Changing;
  416.       FLines.LoadFromStream(AStream);
  417.       SetTitle(FTitle);
  418.       Changed;
  419.       Result:=true;
  420.     except
  421.       Raise;
  422.     end;
  423.   end;
  424. end; {LoadFromStream}
  425.  
  426. function TIniList.ReadBool(const Section, Key: string; Default: Boolean): Boolean;
  427. var AText : string;
  428. begin
  429.   Result:=Default;
  430.   AText:=ReadValue(Section, Key);
  431.   if AText='0' then
  432.     Result:=false;
  433.   if AText='1' then
  434.     Result:=true;
  435. end; {ReadBool}
  436.  
  437. function TIniList.ReadDate(const Section, Key: string; Default: TDateTime): TDateTime;
  438. var AText : string;
  439. begin
  440.   AText:=ReadValue(Section, Key);
  441.   if FDateFloat then
  442.     Result:=StrToFloatDef(AText, Default)
  443.   else
  444.     Result:=StrToDateDef(AText, Default);
  445. end; {ReadDate}
  446.  
  447. function TIniList.ReadDateTime(const Section, Key: string; Default: TDateTime): TDateTime;
  448. var AText : string;
  449. begin
  450.   AText:=ReadValue(Section, Key);
  451.   if FDateFloat then
  452.     Result:=StrToFloatDef(AText, Default)
  453.   else
  454.     Result:=StrToDateTimeDef(AText, Default);
  455. end; {ReadDateTime}
  456.  
  457. function TIniList.ReadFloat(const Section, Key: string; Default: Double): Double;
  458. var AText : string;
  459. begin
  460.   AText:=ReadValue(Section, Key);
  461.   Result:=StrToFloatDef(AText, Default);
  462. end; {ReadFloat}
  463.  
  464. function TIniList.ReadInteger(const Section, Key: string; Default: Longint): Longint;
  465. var AText : string;
  466. begin
  467.   AText:=ReadValue(Section, Key);
  468.   Result:=StrToIntDef(AText, Default);
  469. end; {ReadInteger}
  470.  
  471. function TIniList.ReadString(const Section, Key, Default: string): string;
  472. var AText : string;
  473. begin
  474.   AText:=ReadValue(Section, Key);
  475.   if AText='' then
  476.     Result:=Default
  477.   else
  478.     Result:=AText;
  479. end; {ReadString}
  480.  
  481. function TIniList.ReadTime(const Section, Key: string; Default: TDateTime): TDateTime;
  482. var AText : string;
  483. begin
  484.   AText:=ReadValue(Section, Key);
  485.   if FDateFloat then
  486.     Result:=StrToFloatDef(AText, Default)
  487.   else
  488.     Result:=StrToTimeDef(AText, Default);
  489. end; {ReadTime}
  490.  
  491. procedure TIniList.ReadSection(const Section: string; AStrings: TStrings);
  492. var SectionIdx,
  493.     AIndex,
  494.     ACount     : integer;
  495.     ALine      : string;
  496. begin
  497.   ACount:=FLines.Count;
  498.   SectionIdx:=GetSectionIndex(Section);
  499.   if (ACount>0) and (SectionIdx>=0) and assigned(AStrings) then begin
  500.     AStrings.BeginUpdate;
  501.     AStrings.Clear;
  502.     AIndex:=SectionIdx;
  503.     repeat
  504.       inc(AIndex);
  505.       ALine:=Trim(FLines[AIndex]);
  506.       if (ALine<>'') and (ALine[1]<>'[') and (ALine[1]<>';') then
  507.         AStrings.Add(ALine);
  508.     until (AIndex>=ACount) or (ALine='')
  509.      or ((ALine<>'') and (ALine[1]='['));
  510.     AStrings.EndUpdate;
  511.   end;
  512. end; {ReadSection}
  513.  
  514. procedure TIniList.ReadSections(AStrings: TStrings);
  515. var AIndex,
  516.     ACount : integer;
  517.     ALine  : string;
  518. begin
  519.   ACount:=FLines.Count;
  520.   if (ACount>0) and assigned(AStrings) then begin
  521.     AStrings.BeginUpdate;
  522.     AStrings.Clear;
  523.     for AIndex:=0 to ACount-1 do begin
  524.       ALine:=Trim(FLines[AIndex]);
  525.       if (ALine<>'') and (ALine[1]='[') and (ALine[length(ALine)]=']') then
  526.         AStrings.Add(copy(ALine, 2, length(ALine)-2));
  527.     end;
  528.     AStrings.EndUpdate;
  529.   end;
  530. end; {ReadSections}
  531.  
  532. procedure TIniList.ReadSectionKeys(const Section: string; AStrings: TStrings);
  533. var SectionIdx,
  534.     AIndex,
  535.     ACount     : integer;
  536.     ALine      : string;
  537. begin
  538.   ACount:=FLines.Count;
  539.   SectionIdx:=GetSectionIndex(Section);
  540.   if (ACount>0) and (SectionIdx>=0) and assigned(AStrings) then begin
  541.     AStrings.BeginUpdate;
  542.     AStrings.Clear;
  543.     AIndex:=SectionIdx;
  544.     repeat
  545.       inc(AIndex);
  546.       if AIndex<ACount then begin
  547.         ALine:=Trim(FLines[AIndex]);
  548.         if (ALine<>'') and (ALine[1]<>'[') and (ALine[1]<>';') then
  549.           AStrings.Add(GetKeyFromLine(ALine));
  550.       end;
  551.     until (AIndex>=ACount) or (ALine='')
  552.      or ((ALine<>'') and (ALine[1]='['));
  553.     AStrings.EndUpdate;
  554.   end;
  555. end; {ReadSectionKeys}
  556.  
  557. procedure TIniList.ReadSectionValues(const Section: string; AStrings: TStrings);
  558. var SectionIdx,
  559.     AIndex,
  560.     ACount     : integer;
  561.     ALine      : string;
  562. begin
  563.   ACount:=FLines.Count;
  564.   SectionIdx:=GetSectionIndex(Section);
  565.   if (ACount>0) and (SectionIdx>=0) and assigned(AStrings) then begin
  566.     AStrings.BeginUpdate;
  567.     AStrings.Clear;
  568.     AIndex:=SectionIdx;
  569.     repeat
  570.       inc(AIndex);
  571.       if AIndex<ACount then begin
  572.         ALine:=Trim(FLines[AIndex]);
  573.         if (ALine<>'') and (ALine[1]<>'[') and (ALine[1]<>';') then
  574.           AStrings.Add(GetValueFromLine(ALine));
  575.       end;
  576.     until (AIndex>=ACount) or (ALine='')
  577.      or ((ALine<>'') and (ALine[1]='['));
  578.     AStrings.EndUpdate;
  579.   end;
  580. end; {ReadSectionValues}
  581.  
  582. function TIniList.ReadValue(const Section, Key: string):string;
  583. var KeyIndex  : integer;
  584. begin
  585.   Result:='';
  586.   KeyIndex:=GetKeyIndex(Section, Key);
  587.   if KeyIndex>=0 then
  588.     Result:=GetValueFromLine(FLines[KeyIndex]);
  589. end; {ReadValue}
  590.  
  591. function TIniList.SaveToFile:boolean;
  592. begin
  593.   Result:=false;
  594.   if FFileName<>'' then begin
  595.     try
  596.       FLines.SaveToFile(FFileName);
  597.       Result:=true;
  598.     except
  599.       Raise;
  600.     end;
  601.   end;
  602. end; {SaveToFile}
  603.  
  604. function TIniList.SaveToStream(AStream: TStream):boolean;
  605. begin
  606.   Result:=false;
  607.   if assigned(AStream) then begin
  608.     try
  609.       FLines.SaveToStream(AStream);
  610.       Result:=true;
  611.     except
  612.       Raise;
  613.     end;
  614.   end;
  615. end; {SaveToStream}
  616.  
  617. function TIniList.SectionCount:integer;
  618. var AIndex,
  619.     ACount,
  620.     SCount : integer;
  621.     ALine  : string;
  622. begin
  623.   SCount:=0;
  624.   ACount:=FLines.Count;
  625.   if ACount>0 then begin
  626.     for AIndex:=0 to ACount-1 do begin
  627.       ALine:=Trim(FLines[AIndex]);
  628.       if (ALine<>'') and (ALine[1]='[') and (ALine[length(ALine)]=']') then
  629.         inc(SCount);
  630.     end;
  631.   end;
  632.   Result:=SCount;
  633. end; {SectionCount}
  634.  
  635. procedure TIniList.SetSeparator(NewValue: char);
  636. var ACount,
  637.     i,P      : integer;
  638.     ALine    : string;
  639.     Modified : boolean;
  640. begin
  641.   if NewValue<>FSeparator then begin
  642.     ACount:=FLines.Count;
  643.     if ACount>0 then begin
  644.       Changing;
  645.       Modified:=false;
  646.       for i:=0 to ACount-1 do begin
  647.         ALine:=FLines[i];
  648.         if (ALine<>'') and (ALine[1]<>';') and (Pos('[', ALine)=0) then begin
  649.           P:=Pos(FSeparator, ALine);
  650.           if P>0 then begin
  651.             ALine[P]:=NewValue;
  652.             FLines[i]:=ALine;
  653.             Modified:=true;
  654.           end;
  655.         end;
  656.       end;
  657.       if Modified then
  658.         Changed;
  659.     end;
  660.     FSeparator:=NewValue;
  661.   end;
  662. end; {SetSeparator}
  663.  
  664. procedure TIniList.SetTitle(NewValue: string);
  665. var ALine : string;
  666. begin
  667.   FTitle:=NewValue;
  668.   if NewValue='' then
  669.     NewValue:='NoTitle';
  670.   if FLines.Count>0 then begin
  671.     ALine:=FLines[0];
  672.     if (ALine<>'') and (ALine[1]=';') then begin
  673.       ALine:='; '+NewValue;
  674.       FLines[0]:=ALine;
  675.     end
  676.     else begin
  677.       FLines.Insert(0, '');
  678.       FLines.Insert(0, '; '+NewValue);
  679.     end;
  680.   end
  681.   else begin
  682.     FLines.Add('; '+NewValue);
  683.     FLines.Add('');
  684.   end;
  685. end; {SetTitle}
  686.  
  687. procedure TIniList.WriteBool(const Section, Key: string; Value: Boolean);
  688. begin
  689.   WriteValue(Section, Key, IntToStr(ord(Value)));
  690. end; {WriteBool}
  691.  
  692. procedure TIniList.WriteDate(const Section, Key: string; Value: TDateTime);
  693. var AText : string;
  694. begin
  695.   if FDateFloat then
  696.     AText:=FloatToStr(Value)
  697.   else
  698.     AText:=DateToStrDef(Value, '', false);
  699.   if AText<>'' then
  700.     WriteValue(Section, Key, AText);
  701. end; {WriteDate}
  702.  
  703. procedure TIniList.WriteDateTime(const Section, Key: string; Value: TDateTime);
  704. var AText : string;
  705. begin
  706.   if FDateFloat then
  707.     AText:=FloatToStr(Value)
  708.   else
  709.     AText:=DateTimeToStrDef(Value, '', false);
  710.   if AText<>'' then
  711.     WriteValue(Section, Key, AText);
  712. end; {WriteDateTime}
  713.  
  714. procedure TIniList.WriteFloat(const Section, Key: string; Value: Double);
  715. begin
  716.   WriteValue(Section, Key, FloatToStr(Value));
  717. end; {WriteFloat}
  718.  
  719. procedure TIniList.WriteInteger(const Section, Key: string; Value: Longint);
  720. begin
  721.   WriteValue(Section, Key, IntToStr(Value));
  722. end; {WriteInteger}
  723.  
  724. procedure TIniList.WriteString(const Section, Key, Value: String);
  725. begin
  726.   WriteValue(Section, Key, Value);
  727. end; {WriteString}
  728.  
  729. procedure TIniList.WriteTime(const Section, Key: string; Value: TDateTime);
  730. var AText : string;
  731. begin
  732.   if FDateFloat then
  733.     AText:=FloatToStr(Value)
  734.   else
  735.     AText:=TimeToStrDef(Value, '');
  736.   if AText<>'' then
  737.     WriteValue(Section, Key, AText);
  738. end; {WriteTime}
  739.  
  740. procedure TIniList.WriteValue(const Section, Key: string; Value: string);
  741. var SectIdx : integer;
  742. begin
  743.   SectIdx:=AddSection(Section);
  744.   if SectIdx>=0 then
  745.     AddKey(SectIdx, Key, Value);
  746. end; {WriteBool}
  747.  
  748. procedure Register;
  749. begin
  750.   RegisterComponents('Simon', [TIniList]);
  751. end;
  752.  
  753. end.
  754.