From 6509b909e803f541eb9f59359bf18f4a393ee219 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 18 Jun 2016 11:17:39 +0000 Subject: [PATCH] tvplanit: Fix dayview's inplace editor being destroyed (no issue at the moment, but could be - the other controls failed due to that). git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4767 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpdayview.pas | 37 ++++++++++++------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/components/tvplanit/source/vpdayview.pas b/components/tvplanit/source/vpdayview.pas index 72d315afa..5245e8f86 100644 --- a/components/tvplanit/source/vpdayview.pas +++ b/components/tvplanit/source/vpdayview.pas @@ -824,6 +824,8 @@ end; destructor TVpDayView.Destroy; begin + FreeAndNil(dvInplaceEditor); + FTimeSlotColors.Free; FHeadAttr.Free; FRowHeadAttr.Free; @@ -2254,14 +2256,18 @@ begin if AllowIt then begin { create and spawn the in-place editor } - dvInPlaceEditor := TVpDvInPlaceEdit.Create(Self); - dvInPlaceEditor.Parent := self; - dvInPlaceEditor.OnExit := EndEdit; - dvInPlaceEditor.SetBounds(dvActiveIconRec.Right + FGutterWidth + - TextMargin, - dvActiveEventRec.Top + TextMargin, - dvActiveEventRec.Right, - dvActiveEventRec.Bottom - 1); + if dvInPlaceEditor = nil then begin + dvInPlaceEditor := TVpDvInPlaceEdit.Create(Self); + dvInPlaceEditor.Parent := self; + dvInPlaceEditor.OnExit := EndEdit; + end; + dvInPlaceEditor.SetBounds( + dvActiveIconRec.Right + FGutterWidth + TextMargin, + dvActiveEventRec.Top + TextMargin, + dvActiveEventRec.Right, + dvActiveEventRec.Bottom - 1 + ); + dvInPlaceEditor.Show; dvInPlaceEditor.Text := FActiveEvent.Description; Invalidate; dvInPlaceEditor.SetFocus; @@ -2275,7 +2281,7 @@ begin Exit; dvEndingEditing := True; try - if dvInPlaceEditor <> nil then begin + if (dvInPlaceEditor <> nil) and dvInplaceEditor.Visible then begin if dvInPlaceEditor.Text <> FActiveEvent.Description then begin FActiveEvent.Description := dvInPlaceEditor.Text; FActiveEvent.Changed := true; @@ -2283,12 +2289,7 @@ begin if Assigned(FAfterEdit) then FAfterEdit(self, FActiveEvent); end; - try - dvInPlaceEditor.Free; - dvInPlaceEditor := nil; - except - // The editor was already freed. - end; + dvInplaceEditor.Hide; Invalidate; end; finally @@ -2359,7 +2360,7 @@ begin { for simplicity, bail out of editing while scrolling. } EndEdit(Self); - if dvInPlaceEditor <> nil then Exit; + if (dvInPlaceEditor <> nil) and dvInplaceEditor.Visible then Exit; case Msg.ScrollCode of SB_LINEUP : dvScrollVertical(-1); @@ -4050,7 +4051,7 @@ begin RenderCanvas.Brush.Color := WindowColor; - if (dvInPlaceEditor <> nil) then begin + if (dvInPlaceEditor <> nil) and dvInplaceEditor.Visible then begin if FActiveEvent = Event then EventIsEditing := True else @@ -4234,7 +4235,7 @@ begin if Assigned (FActiveEvent) then OKToDrawEditFrame := not (FActiveEvent.AllDayEvent); - if (dvInPlaceEditor <> nil) and (OKToDrawEditFrame) then begin + if (dvInPlaceEditor <> nil) and dvInplaceEditor.Visible and OKToDrawEditFrame then begin { paint extra borders around the editor } if Assigned (DataStore) then RenderCanvas.Brush.Color := DataStore.CategoryColorMap.GetColor(