summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-11-09 10:14:52 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-11-12 11:04:00 +0200
commit34f56684dc5d449d6a3e5bd701039aeaab88dc16 (patch)
tree8fff580da311f7be7dad1e462c0ad12c85009c3e
parentb71650d04ba702bb6c766f6b47c0be294b1c07cb (diff)
downloadfpGUI-34f56684dc5d449d6a3e5bd701039aeaab88dc16.tar.xz
fpgApplication.CreateForm implementation has changed, but end result is the same
Apparently it is good to allocate a instance, without calling the constructor. I'm not exactly sure why, but it also makes supporting FPC 2.5.1 a lot less messy (no casting required).
-rw-r--r--src/corelib/fpg_base.pas33
-rw-r--r--src/corelib/x11/fpg_x11.pas2
2 files changed, 28 insertions, 7 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas
index a5289474..eb23dfd0 100644
--- a/src/corelib/fpg_base.pas
+++ b/src/corelib/fpg_base.pas
@@ -526,7 +526,7 @@ type
procedure PopModalForm;
function PrevModalForm: TfpgWindowBase;
function RemoveWindowFromModalStack(AForm: TfpgWindowBase): Integer;
- procedure CreateForm(AFormClass: TComponentClass; out AForm: TfpgWindowBase);
+ procedure CreateForm(InstanceClass: TComponentClass; out Reference);
function GetScreenWidth: TfpgCoord; virtual; abstract;
function GetScreenHeight: TfpgCoord; virtual; abstract;
function Screen_dpi_x: integer; virtual; abstract;
@@ -711,6 +711,7 @@ uses
fpg_main, // needed for fpgApplication & fpgNamedColor
fpg_utils, // needed for fpgFileList
fpg_constants,
+ fpg_form, // needed for fpgApplication.CreateForms()
typinfo,
process;
@@ -2336,16 +2337,34 @@ begin
Result := FModalFormStack.Remove(AForm);
end;
-procedure TfpgApplicationBase.CreateForm(AFormClass: TComponentClass;
- out AForm: TfpgWindowBase);
+procedure TfpgApplicationBase.CreateForm(InstanceClass: TComponentClass; out Reference);
+var
+ Instance: TComponent;
+ ok: boolean;
+ AForm: TfpgForm;
begin
+ // Allocate the instance, without calling the constructor
+ Instance := TComponent(InstanceClass.NewInstance);
+ // set the Reference before the constructor is called, so that
+ // events and constructors can refer to it
+ TComponent(Reference) := Instance;
+
+ ok:=false;
try
- AForm := TfpgWindowBase(AFormClass.Create(self));
+ Instance.Create(Self);
+ ok:=true;
+ finally
+ if not ok then
+ begin
+ TComponent(Reference) := nil;
+ end;
+ end;
+
+ if (Instance is TfpgForm) then
+ begin
+ AForm := TfpgForm(Instance);
if FMainForm = nil then
FMainForm := AForm;
- except
- AForm := nil;
- raise;
end;
end;
diff --git a/src/corelib/x11/fpg_x11.pas b/src/corelib/x11/fpg_x11.pas
index 046f10ce..9d64599f 100644
--- a/src/corelib/x11/fpg_x11.pas
+++ b/src/corelib/x11/fpg_x11.pas
@@ -23,6 +23,8 @@ unit fpg_x11;
{.$Define DNDDEBUG} // drag-n-drop specific debugging
{ TODO : Compiz effects: Menu popup with correct window hint. Same for Combo dropdown window. }
+{ TODO : Under Compiz restoring a window position moves the window down/right the width and height
+ of the window borders. This as something to do with win_gravity = StaticGravity setting. }
interface