mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 14:39:13 +02:00
LCL:replace direct call of TXXWidgetset.Create by indirect CreateWidgetset(TXXWidgetset) to move some initialization code from units initialization (from graphics.pp) to that new procedure. This fix memory leaks in lazbuild tool which indirectly uses many lcl units but doesnot work with widgetset.
git-svn-id: trunk@13062 -
This commit is contained in:
parent
2110590f03
commit
c828678066
@ -1348,6 +1348,7 @@ const
|
|||||||
[biSystemMenu, biMinimize, biMaximize]); // bsSizeToolWin
|
[biSystemMenu, biMinimize, biMaximize]); // bsSizeToolWin
|
||||||
|
|
||||||
|
|
||||||
|
procedure CreateWidgetset(AWidgetsetClass: TWidgetsetClass);
|
||||||
procedure FreeWidgetSet;
|
procedure FreeWidgetSet;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
@ -1573,6 +1574,13 @@ begin
|
|||||||
Result := Copy(Hint, I + 1, Maxint);
|
Result := Copy(Hint, I + 1, Maxint);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure CreateWidgetset(AWidgetsetClass: TWidgetsetClass);
|
||||||
|
begin
|
||||||
|
//debugln('CreateWidgetset');
|
||||||
|
CallInterfaceInitializationHandlers;
|
||||||
|
WidgetSet := AWidgetsetClass.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure FreeWidgetSet;
|
procedure FreeWidgetSet;
|
||||||
begin
|
begin
|
||||||
//debugln('FreeWidgetSet');
|
//debugln('FreeWidgetSet');
|
||||||
|
@ -2078,6 +2078,14 @@ begin
|
|||||||
Result := RGBToColor(R, G, B);
|
Result := RGBToColor(R, G, B);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure InterfaceInit;
|
||||||
|
begin
|
||||||
|
//debugln('Graphics.InterfaceInit');
|
||||||
|
FontResourceCache:=TFontHandleCache.Create;
|
||||||
|
PenResourceCache:=TPenHandleCache.Create;
|
||||||
|
BrushResourceCache:=TBrushHandleCache.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure InterfaceFinal;
|
procedure InterfaceFinal;
|
||||||
begin
|
begin
|
||||||
//debugln('Graphics.InterfaceFinal');
|
//debugln('Graphics.InterfaceFinal');
|
||||||
@ -2087,11 +2095,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
FontResourceCache:=TFontHandleCache.Create;
|
|
||||||
PenResourceCache:=TPenHandleCache.Create;
|
|
||||||
BrushResourceCache:=TBrushHandleCache.Create;
|
|
||||||
RegisterIntegerConsts(TypeInfo(TColor), @IdentToColor, @ColorToIdent);
|
RegisterIntegerConsts(TypeInfo(TColor), @IdentToColor, @ColorToIdent);
|
||||||
RegisterIntegerConsts(TypeInfo(TFontCharset), @IdentToCharset, @CharsetToIdent);
|
RegisterIntegerConsts(TypeInfo(TFontCharset), @IdentToCharset, @CharsetToIdent);
|
||||||
|
RegisterInterfaceInitializationHandler(@InterfaceInit);
|
||||||
RegisterInterfaceFinalizationHandler(@InterfaceFinal);
|
RegisterInterfaceFinalizationHandler(@InterfaceFinal);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
|
@ -72,7 +72,7 @@ type
|
|||||||
procedure PassCmdLineOptions; virtual;
|
procedure PassCmdLineOptions; virtual;
|
||||||
function CreateThemeServices: TThemeServices; virtual;
|
function CreateThemeServices: TThemeServices; virtual;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create; virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
procedure AppInit(var ScreenInfo: TScreenInfo); virtual; abstract;
|
procedure AppInit(var ScreenInfo: TScreenInfo); virtual; abstract;
|
||||||
@ -108,6 +108,7 @@ type
|
|||||||
|
|
||||||
property ThemeServices: TThemeServices read FThemeServices;
|
property ThemeServices: TThemeServices read FThemeServices;
|
||||||
end;
|
end;
|
||||||
|
TWidgetSetClass = class of TWidgetSet;
|
||||||
|
|
||||||
type
|
type
|
||||||
EInterfaceException = class(Exception);
|
EInterfaceException = class(Exception);
|
||||||
|
@ -77,7 +77,7 @@ type
|
|||||||
|
|
||||||
procedure RegisterEvents;
|
procedure RegisterEvents;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
function LCLPlatform: TLCLPlatform; override;
|
function LCLPlatform: TLCLPlatform; override;
|
||||||
|
@ -40,7 +40,7 @@ uses
|
|||||||
CarbonInt, Forms;
|
CarbonInt, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
WidgetSet:= TCarbonWidgetSet.Create;
|
CreateWidgetset(TCarbonWidgetSet);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeWidgetSet;
|
FreeWidgetSet;
|
||||||
|
@ -64,7 +64,7 @@ type
|
|||||||
// procedure AppSetTitle(const ATitle: string); override;
|
// procedure AppSetTitle(const ATitle: string); override;
|
||||||
function LCLPlatform: TLCLPlatform; override;
|
function LCLPlatform: TLCLPlatform; override;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
||||||
|
@ -38,11 +38,9 @@ uses
|
|||||||
fpguiint, Forms;
|
fpguiint, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
CreateWidgetset(TFpGuiWidgetSet);
|
||||||
WidgetSet := TFpGuiWidgetSet.Create;
|
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
|
FreeWidgetset;
|
||||||
WidgetSet.Free;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -277,7 +277,7 @@ type
|
|||||||
// notebook
|
// notebook
|
||||||
procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);virtual;
|
procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);virtual;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure SendCachedLCLMessages; override;
|
procedure SendCachedLCLMessages; override;
|
||||||
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
||||||
|
@ -40,7 +40,7 @@ uses
|
|||||||
GTK1Int, Forms;
|
GTK1Int, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
WidgetSet := TGTK1WidgetSet.Create;
|
CreateWidgetset(TGTK1WidgetSet);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeWidgetSet;
|
FreeWidgetSet;
|
||||||
|
@ -36,7 +36,7 @@ uses
|
|||||||
Gtk2Int, Forms;
|
Gtk2Int, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
WidgetSet := TGtk2WidgetSet.Create;
|
CreateWidgetset(TGtk2WidgetSet);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeWidgetSet;
|
FreeWidgetSet;
|
||||||
|
@ -38,11 +38,9 @@ uses
|
|||||||
qtint, Forms;
|
qtint, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
CreateWidgetset(TQtWidgetSet);
|
||||||
WidgetSet := TQtWidgetSet.Create;
|
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
|
|
||||||
FreeWidgetset;
|
FreeWidgetset;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -90,7 +90,7 @@ type
|
|||||||
procedure AppSetTitle(const ATitle: string); override;
|
procedure AppSetTitle(const ATitle: string); override;
|
||||||
procedure AttachMenuToWindow(AMenuObject: TComponent); override;
|
procedure AttachMenuToWindow(AMenuObject: TComponent); override;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
||||||
|
@ -37,7 +37,7 @@ uses
|
|||||||
Win32Int, Forms;
|
Win32Int, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
WidgetSet := TWin32WidgetSet.Create;
|
CreateWidgetset(TWin32WidgetSet);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeWidgetSet;
|
FreeWidgetSet;
|
||||||
|
@ -174,9 +174,9 @@ type
|
|||||||
procedure RemoveCallbacks(Sender: TObject); virtual;
|
procedure RemoveCallbacks(Sender: TObject); virtual;
|
||||||
|
|
||||||
{ Constructor of the class }
|
{ Constructor of the class }
|
||||||
constructor Create;
|
constructor Create; override;
|
||||||
{ Destructor of the class }
|
{ Destructor of the class }
|
||||||
destructor Destroy; Override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
function LCLPlatform: TLCLPlatform; override;
|
function LCLPlatform: TLCLPlatform; override;
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@
|
|||||||
|
|
||||||
Constructor for the class.
|
Constructor for the class.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
Constructor TWin32WidgetSet.Create;
|
constructor TWin32WidgetSet.Create;
|
||||||
Begin
|
begin
|
||||||
Inherited Create;
|
inherited Create;
|
||||||
FTimerData := TList.Create;
|
FTimerData := TList.Create;
|
||||||
FMetrics.cbSize := SizeOf(FMetrics);
|
FMetrics.cbSize := SizeOf(FMetrics);
|
||||||
FMetricsFailed := not Windows.SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
|
FMetricsFailed := not Windows.SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
|
||||||
@ -42,7 +42,7 @@ Begin
|
|||||||
OnClipBoardRequest := nil;
|
OnClipBoardRequest := nil;
|
||||||
Pointer(InitCommonControlsEx) := GetProcAddress(GetModuleHandle(comctl32), 'InitCommonControlsEx');
|
Pointer(InitCommonControlsEx) := GetProcAddress(GetModuleHandle(comctl32), 'InitCommonControlsEx');
|
||||||
FCommonControlsVersion := GetFileVersion(comctl32);
|
FCommonControlsVersion := GetFileVersion(comctl32);
|
||||||
End;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TWin32WidgetSet.Destroy
|
Method: TWin32WidgetSet.Destroy
|
||||||
@ -51,11 +51,11 @@ End;
|
|||||||
|
|
||||||
Destructor for the class.
|
Destructor for the class.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
Destructor TWin32WidgetSet.Destroy;
|
destructor TWin32WidgetSet.Destroy;
|
||||||
var
|
var
|
||||||
n: integer;
|
n: integer;
|
||||||
TimerInfo : PWin32TimerInfo;
|
TimerInfo : PWin32TimerInfo;
|
||||||
Begin
|
begin
|
||||||
Assert(False, 'Trace:TWin32WidgetSet is being destroyed');
|
Assert(False, 'Trace:TWin32WidgetSet is being destroyed');
|
||||||
|
|
||||||
n := FTimerData.Count;
|
n := FTimerData.Count;
|
||||||
@ -78,7 +78,7 @@ Begin
|
|||||||
|
|
||||||
Windows.UnregisterClass(@ClsName, System.HInstance);
|
Windows.UnregisterClass(@ClsName, System.HInstance);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
End;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TWin32WidgetSet.AppInit
|
Method: TWin32WidgetSet.AppInit
|
||||||
|
@ -37,7 +37,7 @@ uses
|
|||||||
Windows,WinCEInt, Forms;
|
Windows,WinCEInt, Forms;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
WidgetSet := TWinCEWidgetSet.Create;
|
CreateWidgetset(TWinCEWidgetSet);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeWidgetSet;
|
FreeWidgetSet;
|
||||||
|
@ -135,9 +135,9 @@ type
|
|||||||
Procedure RemoveCallbacks(Sender: TObject); virtual;
|
Procedure RemoveCallbacks(Sender: TObject); virtual;
|
||||||
|
|
||||||
{ Constructor of the class }
|
{ Constructor of the class }
|
||||||
Constructor Create;
|
constructor Create; override;
|
||||||
{ Destructor of the class }
|
{ Destructor of the class }
|
||||||
Destructor Destroy; Override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
function LCLPlatform: TLCLPlatform; override;
|
function LCLPlatform: TLCLPlatform; override;
|
||||||
|
|
||||||
|
@ -146,6 +146,8 @@ procedure FreeThenNil(var AnObject: TObject);
|
|||||||
{ the LCL interfaces finalization sections are called before the finalization
|
{ the LCL interfaces finalization sections are called before the finalization
|
||||||
sections of the LCL. Those parts, that should be finalized after the LCL, can
|
sections of the LCL. Those parts, that should be finalized after the LCL, can
|
||||||
be registered here. }
|
be registered here. }
|
||||||
|
procedure RegisterInterfaceInitializationHandler(p: TProcedure);
|
||||||
|
procedure CallInterfaceInitializationHandlers;
|
||||||
procedure RegisterInterfaceFinalizationHandler(p: TProcedure);
|
procedure RegisterInterfaceFinalizationHandler(p: TProcedure);
|
||||||
procedure CallInterfaceFinalizationHandlers;
|
procedure CallInterfaceFinalizationHandlers;
|
||||||
|
|
||||||
@ -329,6 +331,7 @@ implementation
|
|||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
|
InterfaceInitializationHandlers,
|
||||||
InterfaceFinalizationHandlers: TFPList;
|
InterfaceFinalizationHandlers: TFPList;
|
||||||
DebugTextAllocated: boolean;
|
DebugTextAllocated: boolean;
|
||||||
DebugText: ^Text;
|
DebugText: ^Text;
|
||||||
@ -611,6 +614,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure RegisterInterfaceInitializationHandler(p: TProcedure);
|
||||||
|
begin
|
||||||
|
InterfaceInitializationHandlers.Add(p);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure CallInterfaceInitializationHandlers;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i:=0 to InterfaceInitializationHandlers.Count-1 do
|
||||||
|
TProcedure(InterfaceInitializationHandlers[i])();
|
||||||
|
end;
|
||||||
|
|
||||||
procedure RegisterInterfaceFinalizationHandler(p: TProcedure);
|
procedure RegisterInterfaceFinalizationHandler(p: TProcedure);
|
||||||
begin
|
begin
|
||||||
InterfaceFinalizationHandlers.Add(p);
|
InterfaceFinalizationHandlers.Add(p);
|
||||||
@ -3303,11 +3319,14 @@ end;
|
|||||||
|
|
||||||
initialization
|
initialization
|
||||||
InitializeDebugOutput;
|
InitializeDebugOutput;
|
||||||
|
InterfaceInitializationHandlers := TFPList.Create;
|
||||||
InterfaceFinalizationHandlers := TFPList.Create;
|
InterfaceFinalizationHandlers := TFPList.Create;
|
||||||
{$IFDEF DebugLCLComponents}
|
{$IFDEF DebugLCLComponents}
|
||||||
DebugLCLComponents:=TDebugLCLItems.Create;
|
DebugLCLComponents:=TDebugLCLItems.Create;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
finalization
|
finalization
|
||||||
|
InterfaceInitializationHandlers.Free;
|
||||||
|
InterfaceInitializationHandlers:=nil;
|
||||||
InterfaceFinalizationHandlers.Free;
|
InterfaceFinalizationHandlers.Free;
|
||||||
InterfaceFinalizationHandlers:=nil;
|
InterfaceFinalizationHandlers:=nil;
|
||||||
{$IFDEF DebugLCLComponents}
|
{$IFDEF DebugLCLComponents}
|
||||||
|
Loading…
Reference in New Issue
Block a user