Marco Cantù 1998, Mastering Delphi 4
Project: MORE.DPR
Project Structure
MORE.DPR
program More;
uses
Forms,
MoreF in 'MoreF.pas' {Form1},
Confdial in 'CONFDIAL.PAS' {ConfigureDialog};
{$R *.RES}
begin
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TConfigureDialog, ConfigureDialog);
Application.Run;
end.
MOREF.PAS
unit MoreF;
interface
uses
Windows, Classes, Graphics, Forms,
Controls, ConfDial, StdCtrls;
type
TForm1 = class(TForm)
ConfigureButton: TButton;
Label1: TLabel;
Label2: TLabel;
procedure ConfigureButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ConfigureButtonClick(Sender: TObject);
begin
ConfigureDialog.CheckBox1.Checked := Label1.Visible;
ConfigureDialog.CheckBox2.Checked := Label2.Visible;
if (fsItalic in Label1.Font.Style) then
ConfigureDialog.ItalicCheckBox.Checked := True
else
ConfigureDialog.ItalicCheckBox.Checked := False;
if (fsBold in Label1.Font.Style) then
ConfigureDialog.BoldCheckBox.Checked := True
else
ConfigureDialog.BoldCheckBox.Checked := False;
if (ConfigureDialog.ShowModal = mrOk) then
begin
Label1.Visible := ConfigureDialog.CheckBox1.Checked;
Label2.Visible := ConfigureDialog.CheckBox2.Checked;
{compute the style of the first label}
if ConfigureDialog.BoldCheckBox.Checked then
Label1.Font.Style := [fsBold]
else
Label1.Font.Style := [];
if ConfigureDialog.ItalicCheckBox.Checked then
Label1.Font.Style := Label1.Font.Style + [fsItalic];
{copy the style to the other label}
Label2.Font.Style := Label1.Font.Style;
end;
end;
end.
CONFDIAL.PAS
unit Confdial;
interface
uses
Windows, Classes, Graphics, Forms,
Controls, Buttons, StdCtrls;
type
TConfigureDialog = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
BitBtn3: TBitBtn;
Label1: TLabel;
ItalicCheckBox: TCheckBox;
BoldCheckBox: TCheckBox;
procedure BitBtn3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
OldHeight, NewHeight: Integer;
end;
var
ConfigureDialog: TConfigureDialog;
implementation
{$R *.DFM}
procedure TConfigureDialog.BitBtn3Click(Sender: TObject);
var
I: Integer;
begin
BitBtn3.Enabled := False;
BoldCheckBox.Enabled := True;
ItalicCheckBox.Enabled := True;
for I := ClientHeight to NewHeight do
begin
ClientHeight := I;
Update;
end;
end;
procedure TConfigureDialog.FormCreate(Sender: TObject);
begin
OldHeight := ClientHeight;
// bottom of the checkbox + margin above the button
NewHeight := ItalicCheckBox.Top +
ItalicCheckBox.Height + BitBtn1.Top;
end;
procedure TConfigureDialog.FormActivate(Sender: TObject);
begin
ClientHeight := OldHeight;
BitBtn3.Enabled := True;
BoldCheckBox.Enabled := False;
ItalicCheckBox.Enabled := False;
end;
end.
MOREF.DFM
object Form1: TForm1
Left = 130
Top = 119
Width = 334
Height = 116
ActiveControl = ConfigureButton
Caption = 'Dialog test'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 19
Width = 116
Height = 16
Caption = 'This is the first label'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
end
object Label2: TLabel
Left = 16
Top = 51
Width = 137
Height = 16
Caption = 'This is the second label'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
end
object ConfigureButton: TButton
Left = 232
Top = 30
Width = 81
Height = 25
Caption = '&Configure...'
TabOrder = 0
OnClick = ConfigureButtonClick
end
end
CONFDIAL.DFM
object ConfigureDialog: TConfigureDialog
Left = 240
Top = 251
ActiveControl = BitBtn1
BorderStyle = bsDialog
Caption = 'Choose configuration'
ClientHeight = 107
ClientWidth = 306
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
OnActivate = FormActivate
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 112
Width = 161
Height = 33
AutoSize = False
Caption = 'Here comes the rest of the dialog box, with some new controls...'
WordWrap = True
end
object BitBtn1: TBitBtn
Left = 200
Top = 8
Width = 97
Height = 27
TabOrder = 0
Kind = bkOK
end
object BitBtn2: TBitBtn
Left = 200
Top = 40
Width = 97
Height = 28
TabOrder = 1
Kind = bkCancel
end
object CheckBox1: TCheckBox
Left = 24
Top = 25
Width = 105
Height = 24
Caption = 'Show &first label'
TabOrder = 2
end
object CheckBox2: TCheckBox
Left = 24
Top = 57
Width = 121
Height = 24
Caption = 'Show &second label'
TabOrder = 3
end
object BitBtn3: TBitBtn
Left = 200
Top = 72
Width = 97
Height = 28
Caption = '&More >>'
TabOrder = 4
OnClick = BitBtn3Click
Glyph.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000000000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF003333333CCC33
3333333333CCCCC3333333333CCCCCCC33333333CCCCCCCCC333333CCC3CCC3C
CC3333CCC33CCC33CCC333CC333CCC333CC333C3333CCC3333C33333333CCC33
33333333333CCC3333333333333CCC3333333333333CCC3333333333333CCC33
33333333333CCC3333333333333CCC3333333333333333333333}
end
object ItalicCheckBox: TCheckBox
Left = 17
Top = 152
Width = 65
Height = 25
Caption = '&Italic'
Enabled = False
TabOrder = 5
end
object BoldCheckBox: TCheckBox
Left = 105
Top = 152
Width = 81
Height = 25
Caption = '&Bold'
Enabled = False
TabOrder = 6
end
end
Copyright Marco Cantù 1998