summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2009-02-17 09:58:26 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2009-02-17 09:58:26 +0000
commit71a84dc3eb2dfcdc391da78557873943edd959cd (patch)
tree7f115a02f987465f7f91114d9412a10fd31e0fad
parent1a34744695bea3bf1d663040fbe8a81f5610968b (diff)
downloadfpGUI-71a84dc3eb2dfcdc391da78557873943edd959cd.tar.xz
* Fixed memory leaks in Calendar Combobox.
-rw-r--r--examples/gui/calendar/calendartest.lpi5
-rw-r--r--examples/gui/calendar/calendartest.lpr20
-rw-r--r--src/gui/fpg_popupcalendar.pas48
3 files changed, 46 insertions, 27 deletions
diff --git a/examples/gui/calendar/calendartest.lpi b/examples/gui/calendar/calendartest.lpi
index 7e9271ef..33da74c7 100644
--- a/examples/gui/calendar/calendartest.lpi
+++ b/examples/gui/calendar/calendartest.lpi
@@ -40,6 +40,11 @@
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
+ <Parsing>
+ <SyntaxOptions>
+ <CStyleOperator Value="False"/>
+ </SyntaxOptions>
+ </Parsing>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
diff --git a/examples/gui/calendar/calendartest.lpr b/examples/gui/calendar/calendartest.lpr
index 1587d753..67e94651 100644
--- a/examples/gui/calendar/calendartest.lpr
+++ b/examples/gui/calendar/calendartest.lpr
@@ -18,16 +18,6 @@ uses
type
TMainForm = class(TfpgForm)
private
- procedure btnDateFormatClicked(Sender: TObject);
- procedure btnTodayClicked(Sender: TObject);
- procedure btnMinDateClicked(Sender: TObject);
- procedure btnMaxDateClicked(Sender: TObject);
- procedure cbWHolidayChange(Sender: TObject);
- procedure cbName1Change(Sender: TObject);
- procedure cbCloseOnSelectChanged(Sender: TObject);
- procedure btnClearClicked(Sender: TObject);
- procedure DrawCalendar(month, year: integer);
- public
{@VFD_HEAD_BEGIN: MainForm}
btnClear: TfpgButton;
lblWHoliday: TfpgLabel;
@@ -47,6 +37,16 @@ type
lblName1: TfpgLabel;
bvlName1: TfpgBevel;
{@VFD_HEAD_END: MainForm}
+ procedure btnDateFormatClicked(Sender: TObject);
+ procedure btnTodayClicked(Sender: TObject);
+ procedure btnMinDateClicked(Sender: TObject);
+ procedure btnMaxDateClicked(Sender: TObject);
+ procedure cbWHolidayChange(Sender: TObject);
+ procedure cbName1Change(Sender: TObject);
+ procedure cbCloseOnSelectChanged(Sender: TObject);
+ procedure btnClearClicked(Sender: TObject);
+ procedure DrawCalendar(month, year: integer);
+ public
FDropDown: TfpgPopupCalendar;
procedure AfterCreate; override;
end;
diff --git a/src/gui/fpg_popupcalendar.pas b/src/gui/fpg_popupcalendar.pas
index d252783d..f6dbfeac 100644
--- a/src/gui/fpg_popupcalendar.pas
+++ b/src/gui/fpg_popupcalendar.pas
@@ -108,6 +108,7 @@ type
procedure grdName1DrawCell(Sender: TObject; const ARow, ACol: Integer; const ARect: TfpgRect; const AFlags: TfpgGridDrawState; var ADefaultDrawing: boolean);
procedure TearDown;
protected
+ FntNorm, FntBold: TfpgFont;
FOrigFocusWin: TfpgWidget;
procedure HandlePaint; override;
procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override;
@@ -116,6 +117,7 @@ type
property CallerWidget: TfpgWidget read FCallerWidget write FCallerWidget;
public
constructor Create(AOwner: TComponent; AOrigFocusWin: TfpgWidget); reintroduce;
+ destructor Destroy; override;
procedure AfterCreate;
property CloseOnSelect: boolean read FCloseOnSelect write SetCloseOnSelect default True;
property Day: Word index 1 read GetDateElement write SetDateElement;
@@ -235,13 +237,9 @@ end;
procedure TfpgPopupCalendar.grdName1DrawCell(Sender: TObject; const ARow, ACol: Integer; const ARect: TfpgRect;
const AFlags: TfpgGridDrawState; var ADefaultDrawing: boolean);
-var
- FntNorm,FntBold: TfpgFont;
begin
with grdName1 do
begin
- FntNorm:= fpgApplication.GetFont('arial-9');
- FntBold:= fpgApplication.GetFont('arial-9:bold');
if FThisMonthDays[ACol,ARow] then
if (ACol = FocusCol) and (ARow = FocusRow) then
Canvas.SetTextColor(FSelectedColor)
@@ -462,19 +460,24 @@ procedure TfpgPopupCalendar.UpdateCalendar;
var
lD, lM, lY: Word;
begin
- if (FDate >= FMinDate) and (FDate <= FMaxDate) then
- begin
- CalculateMonthOffset;
- PopulateDays;
- edtYear.Text := IntToStr(Year);
- edtMonth.Text := LongMonthNames[Month];
- DecodeDate(FDate, lY, lM, lD);
-
- grdName1.FocusCol := (lD - FMonthOffset - FWeekStartDay) mod 7;
- grdName1.FocusRow := (lD - FMonthOffset - FWeekStartDay) div 7;
- if (FMonthOffset + FWeekStartDay) > 1 then
- grdName1.FocusRow := grdName1.FocusRow + 1;
- grdName1.Invalidate;
+ try
+ grdName1.BeginUpdate;
+ if (FDate >= FMinDate) and (FDate <= FMaxDate) then
+ begin
+ CalculateMonthOffset;
+ PopulateDays;
+ edtYear.Text := IntToStr(Year);
+ edtMonth.Text := LongMonthNames[Month];
+ DecodeDate(FDate, lY, lM, lD);
+
+ grdName1.FocusCol := (lD - FMonthOffset - FWeekStartDay) mod 7;
+ grdName1.FocusRow := (lD - FMonthOffset - FWeekStartDay) div 7;
+ if (FMonthOffset + FWeekStartDay) > 1 then
+ grdName1.FocusRow := grdName1.FocusRow + 1;
+// grdName1.Invalidate;
+ end;
+ finally
+ grdName1.EndUpdate;
end;
end;
@@ -628,6 +631,9 @@ end;
constructor TfpgPopupCalendar.Create(AOwner: TComponent; AOrigFocusWin: TfpgWidget);
begin
inherited Create(AOwner);
+ FntNorm:= fpgApplication.GetFont('arial-9');
+ FntBold:= fpgApplication.GetFont('arial-9:bold');
+
FOrigFocusWin := AOrigFocusWin;
AfterCreate;
FDate := Date;
@@ -641,6 +647,13 @@ begin
UpdateCalendar;
end;
+destructor TfpgPopupCalendar.Destroy;
+begin
+ FntBold.Free;
+ FntNorm.Free;
+ inherited Destroy;
+end;
+
procedure TfpgPopupCalendar.AfterCreate;
begin
{@VFD_BODY_BEGIN: fpgPopupCalendar}
@@ -927,6 +940,7 @@ var
begin
if (not Assigned(FDropDown)) or (not FDropDown.HasHandle) then
begin
+ FreeAndNil(FDropDown); // safety measure
FDropDown := TfpgPopupCalendar.Create(nil, FocusRootWidget);
ddw := TfpgPopupCalendar(FDropDown);
ddw.DontCloseWidget := self;