home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 January
/
Chip_1999-01_cd.bin
/
zkuste
/
delphi
/
D1
/
HSTCBO.ZIP
/
HSTCBO.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1996-01-29
|
4KB
|
147 lines
unit Hstcbo;
{******************************************************************************
THistoryComboBox:
FREEWARE !
Version 1.0, Jan. 96
Author: Christian Holzner, Austria
CIS: 100553,67
Internet: cholzner@ping.at
********************************************************************************
Reads/Writes Items of a TComboBox to an IniFile.
The reading and writing has to be initiated manually (methods: ReadIniFile,
WriteIniFile). It could also done in Create/Destroy but then I would loose
flexibility.
If you find any bugs or enhance this component I would like to get an info.
********************************************************************************
Added properties to TComboBox
IniFileName: Name of the Inifile
If left blank, the Application.Exename with the Extension
'INI' is used as default!
IniSection: Section of the Inifile
If left blank, no history maintenance is made
FMaxHistoryLength: Maxmimum allowed length of the history-items
Added methods
ReadIniFile: Reads items from inifile
WriteIniFile: Writes items to inifile
*******************************************************************************}
interface
uses
SysUtils, {Windows,} WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, IniFiles;
type
THistoryComboBox = class(TComboBox)
private
{ Private-Deklarationen }
FIniFileName: String;
FIniSection: String;
FMaxHistoryLength: Integer;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent); Override;
procedure ReadIniFile;
procedure WriteIniFile;
published
{ Published-Deklarationen }
property IniFileName: String read FIniFileName write FIniFileName;
property IniSection: String read FIniSection write FIniSection;
property MaxHistoryLength: Integer read FMaxHistoryLength write FMaxHistoryLength default 7;
end;
procedure Register;
implementation
constructor THistoryComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMaxHistoryLength := 7;
end;
procedure THistoryComboBox.ReadIniFile;
var
IniFile: TiniFile;
i : Integer;
Value: String;
begin
if FIniSection <> '' then begin
{ If FIniFileName is empty then use Applicationname with Extension "INI" }
{ as default. }
if FIniFileName = '' then
IniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.INI'))
else
IniFile := TIniFile.Create(FIniFileName);
try
Clear;
{ Read maximum allowed entries from INI }
for i:= 0 to FMaxHistoryLength-1 do begin
Value := IniFile.ReadString(FIniSection,'H'+IntToStr(i),'');
if Value <> ''
then Items.Add(Value)
else exit;
end;
finally
IniFile.Free;
end;
end;
end;
procedure THistoryComboBox.WriteIniFile;
var
IniFile: TiniFile;
i : Integer;
begin
if FIniSection <> '' then begin
{ If FIniFileName is empty then use Applicationname with Extension "INI" }
{ as default. }
if FIniFileName = '' then
IniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.INI'))
else
IniFile := TIniFile.Create(FIniFileName);
try
IniFile.EraseSection(FIniSection);
{ If not empty - Insert in first position }
if Text <> '' then Items.Insert(0,Text);
{ Check maximum numer of entries and delete any duplicate }
for i := 1 to Items.Count-1 do
if (Items[i] = Text) or (i > FMaxHistoryLength-1) then
Items.Delete(i);
{ Write to INI }
for i := 0 to Items.Count-1 do
IniFile.WriteString(FIniSection,'H'+IntToStr(i),Items[i]);
finally
IniFile.Free;
end;
end;
end;
procedure Register;
begin
RegisterComponents('Samples',[THistoryComboBox]);
end;
end.