IDE: make the TGenericCheckListForm more generic.

git-svn-id: trunk@42237 -
This commit is contained in:
juha 2013-07-30 10:49:50 +00:00
parent a17184add8
commit 74327375f3
3 changed files with 55 additions and 21 deletions

View File

@ -1145,24 +1145,13 @@ procedure TConfigureBuildLazarusDlg.CompileAdvancedButtonClick(Sender: TObject);
// mrCancel=do nothing
var
EditForm: TGenericCheckListForm;
btnBuild: TBitBtn;
i, ind: Integer;
begin
PrepareClose;
EditForm:=TGenericCheckListForm.Create(Nil);
// Add a button for building all.
EditForm:=TGenericCheckListForm.CreateWithActionButton(lisBuild, 'menu_build');
try
EditForm.Caption:=lisLazBuildSelectProfilesToBuild;
// Button for save and compile
btnBuild:=TBitBtn.Create(EditForm.ButtonPanel1);
btnBuild.Caption:=lisBuild;
btnBuild.Kind:=bkCustom;
btnBuild.ModalResult:=mrYes;
btnBuild.Align:=alRight;
btnBuild.BorderSpacing.Left:=6;
btnBuild.BorderSpacing.Right:=6;
btnBuild.Parent:=EditForm.ButtonPanel1;
btnBuild.LoadGlyphFromLazarusResource('menu_build');
btnBuild.AutoSize:=True;
// Copy profile names to checkboxlist and check the previously selected ones.
for i:=0 to fProfiles.Count-1 do begin
ind:=EditForm.CheckListBox1.Items.Add(fProfiles[i].Name);

View File

@ -7,7 +7,7 @@ object GenericCheckListForm: TGenericCheckListForm
Caption = 'GenericCheckListForm'
ClientHeight = 301
ClientWidth = 343
OnCreate = FormCreate
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.1'
object ButtonPanel1: TButtonPanel
@ -36,6 +36,7 @@ object GenericCheckListForm: TGenericCheckListForm
Width = 343
Align = alClient
ItemHeight = 0
OnItemClick = CheckListBox1ItemClick
TabOrder = 1
end
end

View File

@ -15,12 +15,15 @@ type
TGenericCheckListForm = class(TForm)
ButtonPanel1: TButtonPanel;
CheckListBox1: TCheckListBox;
procedure FormCreate(Sender: TObject);
procedure CheckListBox1ItemClick(Sender: TObject; Index: integer);
procedure FormShow(Sender: TObject);
private
fActionBtn: TBitBtn;
procedure UpdateButtons;
public
end;
constructor CreateWithActionButton(aCaption: TCaption; aResourceGlyphName: string = '');
destructor Destroy; override;
end;
var
GenericCheckListForm: TGenericCheckListForm;
@ -31,10 +34,51 @@ implementation
{ TGenericCheckListForm }
procedure TGenericCheckListForm.FormCreate(Sender: TObject);
constructor TGenericCheckListForm.CreateWithActionButton(aCaption: TCaption;
aResourceGlyphName: string);
begin
//ButtonPanel1.OKButton.Caption:=lisMenuOk;
//ButtonPanel1.CancelButton.Caption:=lisCancel;
inherited Create(Nil);
fActionBtn := TBitBtn.Create(ButtonPanel1);
fActionBtn.Caption:=aCaption;
fActionBtn.ModalResult:=mrYes; // ActionButton will return mrYes.
fActionBtn.Align:=alRight;
fActionBtn.BorderSpacing.Left:=6;
fActionBtn.BorderSpacing.Right:=6;
if aResourceGlyphName <> '' then
fActionBtn.LoadGlyphFromLazarusResource(aResourceGlyphName);
fActionBtn.AutoSize:=True;
fActionBtn.Parent:=ButtonPanel1;
end;
destructor TGenericCheckListForm.Destroy;
begin
inherited Destroy;
end;
procedure TGenericCheckListForm.FormShow(Sender: TObject);
begin
UpdateButtons;
end;
procedure TGenericCheckListForm.CheckListBox1ItemClick(Sender: TObject; Index: integer);
begin
UpdateButtons;
end;
procedure TGenericCheckListForm.UpdateButtons;
var
i: Integer;
begin
if Assigned(fActionBtn) then
begin
for i := 0 to CheckListBox1.Count-1 do
if CheckListBox1.Checked[i] then
begin
fActionBtn.Enabled := True;
Exit;
end;
fActionBtn.Enabled := False;
end;
end;
end.