summaryrefslogtreecommitdiff
path: root/src/corelib
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-10-21 21:16:24 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-10-21 21:16:24 +0000
commite756eaa248c07ea390980d445471c88bdc42990c (patch)
tree0692ddf1836003f42f46bc170a7695d8fe0f297b /src/corelib
parent4a7af72768eefb23afe566cce52cce3788425dfa (diff)
downloadfpGUI-e756eaa248c07ea390980d445471c88bdc42990c.tar.xz
* Added name and version constants.
* Added a SetDefaults method which we could use in the future to autoset the default property values for us. * Minor documentation update
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/fpgfx.pas4
-rw-r--r--src/corelib/gfxbase.pas45
2 files changed, 48 insertions, 1 deletions
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas
index be4254d9..c2c64cfe 100644
--- a/src/corelib/fpgfx.pas
+++ b/src/corelib/fpgfx.pas
@@ -37,6 +37,10 @@ const
// Used for the internal message queue
cMessageQueueSize = 512;
+
+ // version and name constants
+ fpGUIVersion = '0.5.1';
+ fpGUIName = 'fpGUI Library';
type
diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas
index 9ae7f503..173b8017 100644
--- a/src/corelib/gfxbase.pas
+++ b/src/corelib/gfxbase.pas
@@ -342,6 +342,7 @@ type
public
// The standard constructor.
constructor Create(AOwner: TComponent); override;
+ procedure AfterConstruction; override;
// Make some setup before the window shows. Forms modify the window creation parameters.
procedure AdjustWindowStyle; virtual;
// Make some setup before the window shows. Invoked after the window is created.
@@ -408,7 +409,13 @@ procedure SortRect(var left, top, right, bottom: integer);
implementation
uses
- fpgfx; // needed for fpgApplication
+ fpgfx, // needed for fpgApplication
+ typinfo;
+
+
+const
+ NoDefault = $80000000;
+ tkPropsWithDefault = [tkInteger, tkChar, tkSet, tkEnumeration];
function KeycodeToText(AKey: Word; AShiftState: TShiftState): string;
@@ -660,6 +667,32 @@ begin
SortRect(left, top, right, bottom);
end;
+// This function uses RTTI to automatically set the default values of properties.
+// That means we don't have to do it in the constructor anymore! :-)
+procedure SetDefaults(Obj: TObject);
+var
+ PropInfos: PPropList;
+ Count, Loop: Integer;
+begin
+ PropInfos := nil;
+ { Find out how many properties we'll be considering }
+ Count := GetPropList(Obj.ClassInfo, tkPropsWithDefault, nil);
+ { Allocate memory to hold their RTTI data }
+ GetMem(PropInfos, Count * SizeOf(PPropInfo));
+ try
+ { Get hold of the property list in our new buffer }
+ GetPropList(Obj.ClassInfo, tkPropsWithDefault, PropInfos);
+ { Loop through all the selected properties }
+ for Loop := 0 to Count - 1 do
+ with PropInfos^[Loop]^ do
+ { If there is supposed to be a default value... }
+ if Default <> NoDefault then
+ { ...then jolly well set it }
+ SetOrdProp(Obj, PropInfos^[Loop], Default)
+ finally
+ FreeMem(PropInfos, Count * SizeOf(PPropInfo));
+ end;
+end;
{ TfpgRect }
@@ -755,6 +788,16 @@ begin
FMouseCursor := mcDefault;
end;
+procedure TfpgWindowBase.AfterConstruction;
+begin
+ inherited AfterConstruction;
+ { Here is a neater way by using RTTI to set default property values all
+ automatically. No need to duplicate the efforts and manually set the
+ property default values in the constructor. This code is no the same for
+ each TfpgWindowBase descendant (which includes GUI widgets) }
+// SetDefaults(self);
+end;
+
procedure TfpgWindowBase.AdjustWindowStyle;
begin
// does nothing here