1. Start your IDE of choice
2. Create a new application
3. Drop a TButton and TJSDialog on the Form
4. Double click the button to create an OnClick handler
5. In the OnClick handler put the following code:
JSDialog1.Execute;
6. Enter in a title, main instruction and content
7. In the implementation section of the code enter create a new button class descending from TBitBtn (doesn't have to descend from TBitBtn):
type TMyButton = class(TBitBtn) end;
Add Buttons to the implementation uses clause.
8. Select the events tab
9. Double click on the OnGetControlClass event and enter in the following code:
if AControlType = ctButton then ControlClass := TMyButton;
10, Double click on the OnInitControl event and enter in the following code:
var lBtn: TMyButton; lBI: TJSCustomButtonItem; begin if ControlType = ctButton then begin lBtn := TMyButton(Control); lBI := TJSCustomButtonItem(ControlItem); lBtn.Caption := lBI.Caption; lBtn.Default := lBI.Default; lBtn.Cancel := lBI.Cancel; lBtn.ModalResult := lBI.ModalResult; lBtn.Font.Color := clRed; Handled := True; end; end;
11. Run the application
The captions of the dialog buttons should now be red.
Full unit source follows
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, JSDialog, StdCtrls; type TForm1 = class(TForm) Button1: TButton; JSDialog1: TJSDialog; procedure Button1Click(Sender: TObject); procedure JSDialog1GetControlClass(Sender: TObject; ControlType: TControlType; var ControlClass: TControlClass); procedure JSDialog1InitControl(Sender: TObject; ControlType: TControlType; Control: TControl; ControlItem: TCollectionItem; var Handled: Boolean); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Buttons ; {$R *.dfm} type TMyButton = class(TBitBtn) end; procedure TForm1.Button1Click(Sender: TObject); begin JSDialog1.Execute; end; procedure TForm1.JSDialog1GetControlClass(Sender: TObject; ControlType: TControlType; var ControlClass: TControlClass); begin if ControlType = ctButton then ControlClass := TMyButton; end; procedure TForm1.JSDialog1InitControl(Sender: TObject; ControlType: TControlType; Control: TControl; ControlItem: TCollectionItem; var Handled: Boolean); var lBtn: TMyButton; lBI: TJSCustomButtonItem; begin if ControlType = ctButton then begin lBtn := TMyButton(Control); lBI := TJSCustomButtonItem(ControlItem); lBtn.Caption := lBI.Caption; lBtn.Default := lBI.Default; lBtn.Cancel := lBI.Cancel; lBtn.ModalResult := lBI.ModalResult; lBtn.Font.Color := clRed; Handled := True; end; end; end.
Copyright © 2013 by LMD Innovative. All rights reserved.
|