From d82273381f1f34c70bc5854686ac7e7d4ccc8ef4 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 19 Jul 2022 22:07:26 +0000 Subject: [PATCH] TvPlanIt: Fix TVpResourceCombo crashing when used in a frame ("... has no parent") git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8353 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpbaseds.pas | 37 +++++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/components/tvplanit/source/vpbaseds.pas b/components/tvplanit/source/vpbaseds.pas index f470b4653..ed498db2c 100644 --- a/components/tvplanit/source/vpbaseds.pas +++ b/components/tvplanit/source/vpbaseds.pas @@ -150,12 +150,16 @@ type end; TVpResourceCombo = class(TCustomComboBox) - protected {private} + private FDataStore: TVpCustomDataStore; + FPendingDatastore: TVpCustomDatastore; + procedure InternalSetDatastore(const Value: TVpCustomDatastore); + protected {private} {internal variables} rcLoading: Boolean; OldItemIndex: Integer; FResourceUpdateStyle: TVpResourceUpdate; + procedure CreateHandle; override; procedure VpDataStoreChanged(var Msg: {$IFDEF DELPHI}TMessage{$ELSE}TLMessage{$ENDIF}); message Vp_DataStoreChanged; procedure SetDataStore(const Value: TVpCustomDataStore); @@ -1256,24 +1260,39 @@ begin end; end; end; -{=====} + +procedure TVpResourceCombo.CreateHandle; +begin + inherited; + if FPendingDatastore <> nil then + begin + InternalSetDatastore(FPendingDatastore); + FPendingDatastore := nil; + end; +end; procedure TVpResourceCombo.SetDataStore(const Value: TVpCustomDataStore); +begin + if HandleAllocated then + InternalSetDatastore(Value) + else + // Delay linking of the datastore until the Handle has been created. + FPendingDatastore := Value; +end; + +procedure TVpResourceCombo.InternalSetDatastore(const Value: TVpCustomDatastore); begin if FDataStore <> Value then begin - if (Assigned (FDataStore)) and - (not (csDesigning in ComponentState)) then - FDataStore.DeregisterWatcher (Handle); + if Assigned (FDataStore) and not (csDesigning in ComponentState) then + FDataStore.DeregisterWatcher(Handle); FDataStore := Value; - if (Assigned (FDataStore)) and - (not (csDesigning in ComponentState)) then - FDataStore.RegisterWatcher (Handle); + if Assigned (FDataStore) and not (csDesigning in ComponentState) then + FDataStore.RegisterWatcher(Handle); if not (csDesigning in ComponentState) then LoadItems; Invalidate; end; end; -{=====}