TvPlanIt: Fix ContactGrid crashing when inserted into a frame ("... has no parent" error).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8354 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-07-19 22:32:25 +00:00
parent d82273381f
commit bca465e6dd
2 changed files with 31 additions and 11 deletions

View File

@ -1276,7 +1276,7 @@ begin
if HandleAllocated then
InternalSetDatastore(Value)
else
// Delay linking of the datastore until the Handle has been created.
// Delay assignment of the datastore until the Handle has been created.
FPendingDatastore := Value;
end;

View File

@ -112,6 +112,8 @@ type
private
FComponentHint: TTranslateString;
FHintMode: TVpHintMode;
FPendingDatastore: TVpCustomDatastore;
procedure InternalSetDatastore(const Value: TVpCustomDatastore);
protected{ private }
FColumnWidth : Integer;
FColor : TColor;
@ -176,6 +178,7 @@ type
procedure cgEditInPlace(Sender: TObject);
procedure cgHookUp;
function ContactIsVisible(AIndex: Integer): Boolean;
procedure CreateHandle; override;
procedure Paint; override;
procedure Loaded; override;
procedure cgScrollHorizontal(Rows: Integer);
@ -691,6 +694,16 @@ begin
Result := (rec.WholeRect.Left >= 0) and (rec.WholeRect.Right <= ClientWidth);
end;
procedure TVpContactGrid.CreateHandle;
begin
inherited;
if FPendingDatastore <> nil then
begin
InternalSetDatastore(FPendingDatastore);
FPendingDatastore := nil;
end;
end;
procedure TVpContactGrid.Loaded;
begin
inherited;
@ -1765,25 +1778,32 @@ begin
FControlLink.Printer.NotifyLinked;
end;
end;
{=====}
procedure TVpContactGrid.SetDataStore (const Value : TVpCustomDataStore);
procedure TVpContactGrid.SetDataStore(const Value: TVpCustomDataStore);
begin
if (Assigned (DataStore)) and (not (csDesigning in ComponentState)) then
DataStore.DeregisterWatcher (Handle);
if HandleAllocated then
InternalSetDatastore(Value)
else
// Delay assignment of the datastore until the Handle has been created.
FPendingDatastore := Value;
end;
inherited SetDataStore (Value);
procedure TVpContactGrid.InternalSetDatastore(const Value: TVpCustomDatastore);
begin
if Assigned (DataStore) and not (csDesigning in ComponentState) then
DataStore.DeregisterWatcher(Handle);
if (Assigned (DataStore)) and (not (csDesigning in ComponentState)) then
DataStore.RegisterWatcher (Handle);
inherited SetDataStore(Value);
if not Assigned (DataStore) then
if Assigned (DataStore) and not (csDesigning in ComponentState) then
DataStore.RegisterWatcher(Handle);
if not Assigned(DataStore) then
Exit;
if not Assigned (DataStore.Resource) then
if not Assigned(DataStore.Resource) then
Exit;
DataStore.Resource.Contacts.ContactSort := SortBy;
end;
{=====}
procedure TVpContactGrid.SetSortBy(const Value: TVpContactSort);
begin