optim, avoid a lot of heap alloc when assigning btn's glyphs

This commit is contained in:
Basile Burg 2015-09-17 18:22:13 +02:00
parent 546052732f
commit c95c8ff54b
11 changed files with 61 additions and 182 deletions

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Buttons, Menus,ce_widget, ce_common; StdCtrls, ExtCtrls, Buttons, Menus,ce_widget, ce_common, ce_sharedres;
type type
@ -105,25 +105,23 @@ end;
procedure TToolInfo.refreshStatus; procedure TToolInfo.refreshStatus;
var var
pth: string; pth: string;
png: TPortableNetworkGraphic;
begin begin
if (fLabel = nil) or (fStatus = nil) then exit; if (fLabel = nil) or (fStatus = nil) then exit;
// //
fLabel.Caption:= fToolName; fLabel.Caption:= fToolName;
png := TPortableNetworkGraphic.Create; case fKind of
try case fKind of
tikFindable: tikFindable:
begin begin
pth := exeFullName(fToolName + exeExt); pth := exeFullName(fToolName + exeExt);
if pth = '' then if pth = '' then
begin begin
fStatus.Caption:= ' the tool cannot be found'; fStatus.Caption:= ' the tool cannot be found';
png.LoadFromLazarusResource('bullet_red'); AssignPng(fIco, 'bullet_red');
end end
else else
begin begin
fStatus.Caption:= ' the tool is available'; fStatus.Caption:= ' the tool is available';
png.LoadFromLazarusResource('bullet_green'); AssignPng(fIco, 'bullet_green');
end; end;
end; end;
tikRunning: tikRunning:
@ -132,24 +130,20 @@ begin
if pth = '' then if pth = '' then
begin begin
fStatus.Caption:= ' the tool cannot be found'; fStatus.Caption:= ' the tool cannot be found';
png.LoadFromLazarusResource('bullet_red'); AssignPng(fIco, 'bullet_red');
end end
else if AppIsRunning(fToolName + exeExt) then else if AppIsRunning(fToolName + exeExt) then
begin begin
fStatus.Caption:= ' the tool is available and running'; fStatus.Caption:= ' the tool is available and running';
png.LoadFromLazarusResource('bullet_green'); AssignPng(fIco, 'bullet_green');
end end
else else
begin begin
fStatus.Caption:= ' the tool is available but is not running'; fStatus.Caption:= ' the tool is available but is not running';
png.LoadFromLazarusResource('bullet_yellow'); AssignPng(fIco, 'bullet_yellow');
end; end;
end; end;
end; end;
finally
fIco.Glyph.Assign(png);
png.Free;
end;
ReAlign; ReAlign;
Invalidate; Invalidate;
end; end;

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Menus, ComCtrls, Buttons, ce_widget, ce_interfaces, ce_nativeproject, ce_dmdwrap, Menus, ComCtrls, Buttons, ce_widget, ce_interfaces, ce_nativeproject, ce_dmdwrap,
ce_common, ce_dialogs; ce_common, ce_dialogs, ce_sharedres;
type type
@ -64,33 +64,17 @@ const
notav: string = '< n/a >'; notav: string = '< n/a >';
constructor TCELibManEditorWidget.Create(aOwner: TComponent); constructor TCELibManEditorWidget.Create(aOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
inherited; inherited;
png := TPortableNetworkGraphic.Create; AssignPng(btnMoveDown, 'arrow_down');
try AssignPng(btnMoveUp, 'arrow_up');
png.LoadFromLazarusResource('arrow_down'); AssignPng(btnAddLib, 'book_add');
btnMoveDown.Glyph.Assign(png); AssignPng(btnRemLib, 'book_delete');
png.LoadFromLazarusResource('arrow_up'); AssignPng(btnEditAlias, 'book_edit');
btnMoveUp.Glyph.Assign(png); AssignPng(btnSelFile, 'folder_brick');
png.LoadFromLazarusResource('book_add'); AssignPng(btnSelfoldOfFiles, 'bricks');
btnAddLib.Glyph.Assign(png); AssignPng(btnSelRoot, 'folder_add');
png.LoadFromLazarusResource('book_delete'); AssignPng(btnReg, 'book_link');
btnRemLib.Glyph.Assign(png);
png.LoadFromLazarusResource('book_edit');
btnEditAlias.Glyph.Assign(png);
png.LoadFromLazarusResource('folder_brick');
btnSelFile.Glyph.Assign(png);
png.LoadFromLazarusResource('bricks');
btnSelfoldOfFiles.Glyph.Assign(png);
png.LoadFromLazarusResource('folder_add');
btnSelRoot.Glyph.Assign(png);
png.LoadFromLazarusResource('book_link');
btnReg.Glyph.Assign(png);
finally
png.Free;
end;
end; end;
procedure TCELibManEditorWidget.updateRegistrable; procedure TCELibManEditorWidget.updateRegistrable;

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,
lcltype, ce_widget, ActnList, Menus, clipbrd, AnchorDocking, TreeFilterEdit, lcltype, ce_widget, ActnList, Menus, clipbrd, AnchorDocking, TreeFilterEdit,
Buttons, math, process, ce_writableComponent, ce_common, ce_synmemo, GraphType, Buttons, math, process, ce_writableComponent, ce_common, ce_synmemo, GraphType,
ce_dlangutils, ce_interfaces, ce_observer, ce_symstring, ce_processes; ce_dlangutils, ce_interfaces, ce_observer, ce_symstring, ce_processes, ce_sharedres;
type type
@ -248,7 +248,6 @@ end;
constructor TCEMessagesWidget.create(aOwner: TComponent); constructor TCEMessagesWidget.create(aOwner: TComponent);
var var
fname: string; fname: string;
png: TPortableNetworkGraphic;
begin begin
fMaxMessCnt := 500; fMaxMessCnt := 500;
fCtxt := amcAll; fCtxt := amcAll;
@ -306,13 +305,7 @@ begin
fBtns[amcProj]:= btnSelProj; fBtns[amcProj]:= btnSelProj;
// //
btnClearCat.OnClick := @actClearCurCatExecute; btnClearCat.OnClick := @actClearCurCatExecute;
png:= TPortableNetworkGraphic.Create; AssignPng(btnClearCat, 'clean');
try
png.LoadFromLazarusResource('clean');
btnClearCat.Glyph.Assign(png);
finally
png.free;
end;
// //
fname := getCoeditDocPath + optname; fname := getCoeditDocPath + optname;
if fileExists(fname) then if fileExists(fname) then

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics, Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics,
ExtCtrls, Menus, ComCtrls, Buttons, lcltype, strutils, ce_widget, ExtCtrls, Menus, ComCtrls, Buttons, lcltype, strutils, ce_widget,
ce_common, ce_interfaces, ce_observer, ce_writableComponent; ce_common, ce_interfaces, ce_observer, ce_writableComponent, ce_sharedres;
type type
@ -137,24 +137,14 @@ end;
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEMiniExplorerWidget.create(aIwner: TComponent); constructor TCEMiniExplorerWidget.create(aIwner: TComponent);
var var
png: TPortableNetworkGraphic;
fname: string; fname: string;
begin begin
inherited; inherited;
// //
png := TPortableNetworkGraphic.Create; AssignPng(btnAddFav, 'folder_add');
try AssignPng(btnRemFav, 'folder_delete');
png.LoadFromLazarusResource('folder_add'); AssignPng(btnShellOpen, 'flash');
btnAddFav.Glyph.Assign(png); AssignPng(btnEdit, 'pencil');
png.LoadFromLazarusResource('folder_delete');
btnRemFav.Glyph.Assign(png);
png.LoadFromLazarusResource('flash');
btnShellOpen.Glyph.Assign(png);
png.LoadFromLazarusResource('pencil');
btnEdit.Glyph.Assign(png);
finally
png.Free;
end;
// //
fFavorites := TStringList.Create; fFavorites := TStringList.Create;
fFavorites.onChange := @favStringsChange; fFavorites.onChange := @favStringsChange;

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, ExtCtrls, Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, ExtCtrls,
Menus, ComCtrls, Buttons, PropEdits, ObjectInspector, Menus, ComCtrls, Buttons, PropEdits, ObjectInspector, ce_sharedres,
ce_common, ce_widget, ce_interfaces, ce_observer, ce_dialogs; ce_common, ce_widget, ce_interfaces, ce_observer, ce_dialogs;
type type
@ -63,8 +63,6 @@ const
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEOptionEditorWidget.create(aOwner: TComponent); constructor TCEOptionEditorWidget.create(aOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
inherited; inherited;
fIsDockable := false; fIsDockable := false;
@ -73,15 +71,8 @@ begin
inspector.CheckboxForBoolean := true; inspector.CheckboxForBoolean := true;
inspector.PropertyEditorHook.AddHandlerModified(@inspectorModified); inspector.PropertyEditorHook.AddHandlerModified(@inspectorModified);
// //
png := TPortableNetworkGraphic.Create; AssignPng(btnCancel, 'cancel');
try AssignPng(btnAccept, 'accept');
png.LoadFromLazarusResource('cancel');
btnCancel.Glyph.Assign(png);
png.LoadFromLazarusResource('accept');
btnAccept.Glyph.Assign(png);
finally
png.Free;
end;
end; end;
destructor TCEOptionEditorWidget.destroy; destructor TCEOptionEditorWidget.destroy;

View File

@ -7,8 +7,8 @@ interface
uses uses
Classes, SysUtils, FileUtil, RTTIGrids, RTTICtrls, Forms, Controls, Graphics, Classes, SysUtils, FileUtil, RTTIGrids, RTTICtrls, Forms, Controls, Graphics,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Menus, Buttons, rttiutils, typinfo, Dialogs, ExtCtrls, ComCtrls, StdCtrls, Menus, Buttons, rttiutils, typinfo,
PropEdits, ObjectInspector, ce_dmdwrap, ce_nativeproject, ce_widget, ce_interfaces, PropEdits, ObjectInspector, ce_dmdwrap, ce_nativeproject, ce_widget,
ce_observer; ce_interfaces, ce_observer, ce_sharedres;
type type
@ -63,23 +63,14 @@ implementation
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEProjectConfigurationWidget.create(aOwner: TComponent); constructor TCEProjectConfigurationWidget.create(aOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
inherited; inherited;
png := TPortableNetworkGraphic.Create; //
try AssignPng(btnAddConf, 'cog_add');
png.LoadFromLazarusResource('cog_add'); AssignPng(btnDelConf, 'cog_delete');
btnAddConf.Glyph.Assign(png); AssignPng(btnCloneConf, 'cog_go');
png.LoadFromLazarusResource('cog_delete'); AssignPng(btnSyncEdit, 'link_break');
btnDelConf.Glyph.Assign(png); //
png.LoadFromLazarusResource('cog_go');
btnCloneConf.Glyph.Assign(png);
png.LoadFromLazarusResource('link_break');
btnSyncEdit.Glyph.Assign(png);
finally
png.Free;
end;
fSynchroItem := TStringList.Create; fSynchroItem := TStringList.Create;
fSynchroValue := TStringList.Create; fSynchroValue := TStringList.Create;
Tree.Selected := Tree.Items.GetLastNode; Tree.Selected := Tree.Items.GetLastNode;
@ -177,20 +168,12 @@ begin
end; end;
procedure TCEProjectConfigurationWidget.setSyncroMode(aValue: boolean); procedure TCEProjectConfigurationWidget.setSyncroMode(aValue: boolean);
var
png: TPortableNetworkGraphic;
begin begin
if fSyncroMode = aValue then exit; if fSyncroMode = aValue then exit;
// //
fSyncroMode := aValue; fSyncroMode := aValue;
png := TPortableNetworkGraphic.Create; if fSyncroMode then AssignPng(btnSyncEdit, 'link')
try else AssignPng(btnSyncEdit, 'link_break');
if fSyncroMode then png.LoadFromLazarusResource('link')
else png.LoadFromLazarusResource('link_break');
btnSyncEdit.Glyph.Assign(png);
finally
png.Free;
end;
end; end;
function TCEProjectConfigurationWidget.syncroSetPropAsString(const ASection, Item, Default: string): string; function TCEProjectConfigurationWidget.syncroSetPropAsString(const ASection, Item, Default: string): string;

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Graphics, actnlist, Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Graphics, actnlist,
Dialogs, ExtCtrls, ComCtrls, Menus, Buttons, lcltype, ce_nativeproject, ce_interfaces, Dialogs, ExtCtrls, ComCtrls, Menus, Buttons, lcltype, ce_nativeproject, ce_interfaces,
ce_common, ce_widget, ce_observer, ce_dialogs; ce_common, ce_widget, ce_observer, ce_dialogs, ce_sharedres;
type type
TCEProjectInspectWidget = class(TCEWidget, ICEProjectObserver) TCEProjectInspectWidget = class(TCEWidget, ICEProjectObserver)
@ -65,8 +65,6 @@ uses
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEProjectInspectWidget.create(aOwner: TComponent); constructor TCEProjectInspectWidget.create(aOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
fActOpenFile := TAction.Create(self); fActOpenFile := TAction.Create(self);
fActOpenFile.Caption := 'Open file in editor'; fActOpenFile.Caption := 'Open file in editor';
@ -78,21 +76,11 @@ begin
// //
inherited; inherited;
// //
png := TPortableNetworkGraphic.Create; AssignPng(btnAddFile, 'document_add');
try AssignPng(btnRemFile, 'document_delete');
png.LoadFromLazarusResource('document_add'); AssignPng(btnAddFold, 'folder_add');
btnAddFile.Glyph.Assign(png); AssignPng(btnRemFold, 'folder_delete');
png.LoadFromLazarusResource('document_delete'); AssignPng(btnProjOpts, 'wrench_orange');
btnRemFile.Glyph.Assign(png);
png.LoadFromLazarusResource('folder_add');
btnAddFold.Glyph.Assign(png);
png.LoadFromLazarusResource('folder_delete');
btnRemFold.Glyph.Assign(png);
png.LoadFromLazarusResource('wrench_orange');
btnProjOpts.Glyph.Assign(png);
finally
png.Free;
end;
// //
Tree.OnDblClick := @TreeDblClick; Tree.OnDblClick := @TreeDblClick;
fFileNode := Tree.Items[0]; fFileNode := Tree.Items[0];

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics, Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics,
ExtCtrls, LCLProc, ComCtrls, StdCtrls, Buttons, LCLType, ExtCtrls, LCLProc, ComCtrls, StdCtrls, Buttons, LCLType,
ce_observer, ce_interfaces, ce_common, ce_writableComponent; ce_sharedres, ce_observer, ce_interfaces, ce_common, ce_writableComponent;
type type
@ -171,22 +171,12 @@ end;
{$REGION Standard Comp/Object things -------------------------------------------} {$REGION Standard Comp/Object things -------------------------------------------}
constructor TCEShortcutEditor.create(TheOwner: TComponent); constructor TCEShortcutEditor.create(TheOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
inherited; inherited;
fObservers := TCEEditableShortCutSubject.create; fObservers := TCEEditableShortCutSubject.create;
fShortcuts := TShortCutCollection.create(self); fShortcuts := TShortCutCollection.create(self);
fBackup := TShortCutCollection.create(self); fBackup := TShortCutCollection.create(self);
// AssignPng(btnClear, 'clean');
png := TPortableNetworkGraphic.Create;
try
png.LoadFromLazarusResource('clean');
btnClear.Glyph.Assign(png);
finally
png.free;
end;
//
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
end; end;
@ -197,19 +187,11 @@ begin
end; end;
procedure TCEShortcutEditor.UpdateShowing; procedure TCEShortcutEditor.UpdateShowing;
var
png : TPortableNetworkGraphic;
begin begin
inherited; inherited;
if not visible then exit; if not visible then exit;
// //
png := TPortableNetworkGraphic.Create; AssignPng(btnActivate, 'keyboard_pencil');
try
png.LoadFromLazarusResource('keyboard_pencil');
btnActivate.Glyph.Assign(png);
finally
png.free;
end;
end; end;
{$ENDREGION} {$ENDREGION}

View File

@ -8,7 +8,8 @@ uses
Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc, Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc,
SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText, SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText, SynEdit,
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView, SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs; ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs,
ce_sharedres;
type type
@ -357,8 +358,6 @@ end;
{$REGION TCESynMemo ------------------------------------------------------------} {$REGION TCESynMemo ------------------------------------------------------------}
constructor TCESynMemo.Create(aOwner: TComponent); constructor TCESynMemo.Create(aOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
inherited; inherited;
// //
@ -390,13 +389,7 @@ begin
fSyncEdit := TSynPluginSyncroEdit.Create(self); fSyncEdit := TSynPluginSyncroEdit.Create(self);
fSyncEdit.Editor := self; fSyncEdit.Editor := self;
fSyncEdit.CaseSensitive := true; fSyncEdit.CaseSensitive := true;
png := TPortableNetworkGraphic.Create; AssignPng(fSyncEdit.GutterGlyph, 'link_edit');
try
png.LoadFromLazarusResource('link_edit');
fSyncEdit.GutterGlyph.Assign(png);
finally
png.Free;
end;
// //
fCompletionCaseSens:=false; fCompletionCaseSens:=false;
fCompletion := TSyncompletion.create(nil); fCompletion := TSyncompletion.create(nil);

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls,
strutils, Graphics, Dialogs, ExtCtrls, Menus, Buttons, ComCtrls, strutils, Graphics, Dialogs, ExtCtrls, Menus, Buttons, ComCtrls,
ce_widget, process, ce_common, ce_interfaces, ce_synmemo, ce_processes, ce_widget, process, ce_common, ce_interfaces, ce_synmemo, ce_processes,
ce_nativeproject, ce_symstring, ce_writableComponent, ce_observer; ce_nativeproject, ce_symstring, ce_writableComponent, ce_observer, ce_sharedres;
type type
@ -192,7 +192,6 @@ end;
{$REGION Standard Comp/Obj -----------------------------------------------------} {$REGION Standard Comp/Obj -----------------------------------------------------}
constructor TCETodoListWidget.Create(aOwner: TComponent); constructor TCETodoListWidget.Create(aOwner: TComponent);
var var
png: TPortableNetworkGraphic;
fname: string; fname: string;
begin begin
inherited; inherited;
@ -212,15 +211,8 @@ begin
lstfilter.OnChange := @filterItems; lstfilter.OnChange := @filterItems;
btnGo.OnClick := @handleListClick; btnGo.OnClick := @handleListClick;
// //
png := TPortableNetworkGraphic.Create; AssignPng(btnRefresh, 'arrow_update');
try AssignPng(btnGo, 'arrow_pen');
png.LoadFromLazarusResource('arrow_update');
btnRefresh.Glyph.Assign(png);
png.LoadFromLazarusResource('arrow_pen');
btnGo.Glyph.Assign(png);
finally
png.Free;
end;
// //
fname := getCoeditDocPath + OptFname; fname := getCoeditDocPath + OptFname;
if FileExists(fname) then if FileExists(fname) then

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs,
ExtCtrls, Menus, Buttons, StdCtrls, ce_widget, ce_tools; ExtCtrls, Menus, Buttons, StdCtrls, ce_widget, ce_tools, ce_sharedres;
type type
@ -46,28 +46,17 @@ implementation
{$R *.lfm} {$R *.lfm}
constructor TCEToolsEditorWidget.create(aOwner: TComponent); constructor TCEToolsEditorWidget.create(aOwner: TComponent);
var
png: TPortableNetworkGraphic;
begin begin
inherited; inherited;
//
AssignPng(btnMoveUp, 'arrow_up');
AssignPng(btnMoveDown, 'arrow_down');
AssignPng(BtnAddTool, 'application_add');
AssignPng(btnRemTool, 'application_delete');
AssignPng(btnRun, 'application_flash');
AssignPng(btnClone, 'application_double');
//
propsEd.CheckboxForBoolean := true; propsEd.CheckboxForBoolean := true;
png := TPortableNetworkGraphic.Create;
try
png.LoadFromLazarusResource('arrow_up');
btnMoveUp.Glyph.Assign(png);
png.LoadFromLazarusResource('arrow_down');
btnMoveDown.Glyph.Assign(png);
png.LoadFromLazarusResource('application_add');
BtnAddTool.Glyph.Assign(png);
png.LoadFromLazarusResource('application_delete');
btnRemTool.Glyph.Assign(png);
png.LoadFromLazarusResource('application_flash');
btnRun.Glyph.Assign(png);
png.LoadFromLazarusResource('application_double');
btnClone.Glyph.Assign(png);
finally
png.free;
end;
rebuildToolList; rebuildToolList;
end; end;