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; -{=====}