From c3b41ed772ef91730a8dc89a2c287da0a86fba46 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Fri, 6 May 2011 12:34:36 +0200 Subject: The style must be instantiated before we create forms. The old behaviour caused problems with menus. A better solution must be found soon though - including getting rid of the fpgStyle variable. I also updated the instructions in the custom style unit for the demo. --- examples/gui/customstyles/customstyles.lpr | 12 +++++++----- examples/gui/customstyles/mystyle.pas | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'examples/gui/customstyles') diff --git a/examples/gui/customstyles/customstyles.lpr b/examples/gui/customstyles/customstyles.lpr index 5da13e0f..419e6456 100644 --- a/examples/gui/customstyles/customstyles.lpr +++ b/examples/gui/customstyles/customstyles.lpr @@ -48,13 +48,15 @@ var frm: TTestForm; begin fpgApplication.Initialize; + + { Set our new style as the default (before we create any forms), unless + a the end-user specified a different style via the command line. } + if not gCommandLineParams.IsParam('style') then + if fpgStyleManager.SetStyle('Demo Style') then + fpgStyle := fpgStyleManager.Style; + frm := TTestForm.Create(nil); try - { Lets set a new default style if no style was specified in the command line } - if not gCommandLineParams.IsParam('style') then - if fpgStyleManager.SetStyle('Demo Style') then - fpgStyle := fpgStyleManager.Style; - frm.Show; fpgApplication.Run; finally diff --git a/examples/gui/customstyles/mystyle.pas b/examples/gui/customstyles/mystyle.pas index 3e9c2992..8db9f2b4 100644 --- a/examples/gui/customstyles/mystyle.pas +++ b/examples/gui/customstyles/mystyle.pas @@ -2,9 +2,10 @@ A very quick and basic style implementation. It took all of 10 minutes. To apply this style, follow these instructions: - * free the old fpgStyle - * instantiate the new style class - * and assign this new instance to fpgStyle variable + 1) (optional) Check if a style was specified via a command line parameter + 2) If (1) was false, set the new default which will instantiate the new + style class and automatically free the old one. + 3) Assign our new style instance to the fpgStyle variable Example: @@ -14,14 +15,15 @@ frm: TMainForm; begin fpgApplication.Initialize; + + { Set our new style as the default (before we create any forms), unless + a the end-user specified a different style via the command line. } + if not gCommandLineParams.IsParam('style') then + if fpgStyleManager.SetStyle('Demo Style') then + fpgStyle := fpgStyleManager.Style; + frm := TMainForm.Create(nil); try - // Free the old and set the new style - if Assigned(fpgStyle) then - fpgStyle.Free; - fpgStyle := TMyStyle.Create; - - // now continue with the application frm.Show; fpgApplication.Run; finally @@ -41,8 +43,6 @@ uses type - { TMyStyle } - TMyStyle = class(TfpgStyle) public constructor Create; override; -- cgit v1.2.3-70-g09d2