Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco


Home: Code Repository: Mastering Delphi 6

Chapter 12 - Package IntfFormPack

Package Structure

IntfSimple.pas
unit IntfSimple;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons, IntfColSel,
  ColorGrd;

type
  TFormSimpleColor = class(TForm, IColorSelect)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ColorGrid1: TColorGrid;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    procedure SetSelColor (Col: TColor);
    function GetSelColor: TColor;
  public
    procedure ApplyClick (Sender: TObject);
    function Display (Modal: Boolean = True): Boolean;
  published
    property SelectedColor: TColor
      read GetSelColor write SetSelColor;
  end;

implementation

{$R *.DFM}

procedure TFormSimpleColor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  // used by the modeless form
  Action := caFree;
end;

procedure TFormSimpleColor.ApplyClick(Sender: TObject);
begin
  // set the color of the main form
  Application.MainForm.Color := SelectedColor;
end;

// set and get properties

function TFormSimpleColor.GetSelColor: TColor;
begin
  Result := ColorGrid1.ForegroundColor;
end;

procedure TFormSimpleColor.SetSelColor (Col: TColor);
begin
  ColorGrid1.ForegroundIndex :=
    ColorGrid1.ColorToIndex(Col)
end;

function TFormSimpleColor.Display(Modal: Boolean): Boolean;
begin
  Result := True; // default
  if Modal then
    Result := (ShowModal = mrOK)
  else
  begin
    BitBtn1.Caption := 'Apply';
    BitBtn1.OnClick := ApplyClick;
    BitBtn2.Kind := bkClose;
    Show;
  end;
end;

initialization
  RegisterColorSelect (TFormSimpleColor);

end.