You've already forked lazarus-ccr
tvplanit: Simplify linking of runtime created datastores to dependent controls.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5121 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -9,7 +9,6 @@
|
|||||||
<Title Value="project1"/>
|
<Title Value="project1"/>
|
||||||
<ResourceType Value="res"/>
|
<ResourceType Value="res"/>
|
||||||
<UseXPManifest Value="True"/>
|
<UseXPManifest Value="True"/>
|
||||||
<Icon Value="0"/>
|
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<StringTable ProductVersion=""/>
|
<StringTable ProductVersion=""/>
|
||||||
|
@ -38,8 +38,6 @@ implementation
|
|||||||
|
|
||||||
procedure TForm1.FormCreate(Sender: TObject);
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
ControlLink := TVpControlLink.Create(self);
|
|
||||||
|
|
||||||
Datastore := TVpBufDSDatastore.Create(self);
|
Datastore := TVpBufDSDatastore.Create(self);
|
||||||
Datastore.Directory := '.';
|
Datastore.Directory := '.';
|
||||||
Datastore.AutoCreate := true;
|
Datastore.AutoCreate := true;
|
||||||
@ -48,30 +46,28 @@ begin
|
|||||||
DayView := TVpDayview.Create(self);
|
DayView := TVpDayview.Create(self);
|
||||||
DayView.Parent := self;
|
DayView.Parent := self;
|
||||||
DayView.Align := alLeft;
|
DayView.Align := alLeft;
|
||||||
DayView.ControlLink := ControlLink;
|
|
||||||
DayView.Datastore := Datastore;
|
|
||||||
|
|
||||||
WeekView := TVpWeekView.Create(self);
|
WeekView := TVpWeekView.Create(self);
|
||||||
WeekView.Parent := self;
|
WeekView.Parent := self;
|
||||||
Weekview.Align := alClient;
|
Weekview.Align := alClient;
|
||||||
WeekView.ControlLink := ControlLink;
|
|
||||||
WeekView.Datastore := Datastore;
|
|
||||||
|
|
||||||
MonthView := TVpMonthView.Create(self);
|
MonthView := TVpMonthView.Create(self);
|
||||||
MonthView.Parent := self;
|
MonthView.Parent := self;
|
||||||
MonthView.Align := alRight;
|
MonthView.Align := alRight;
|
||||||
MonthView.ControlLink := ControlLink;
|
|
||||||
MonthView.Datastore := Datastore;
|
|
||||||
|
|
||||||
Combo := TVpResourceCombo.Create(Self);
|
Combo := TVpResourceCombo.Create(Self);
|
||||||
Combo.Parent := Panel1;
|
Combo.Parent := Panel1;
|
||||||
Combo.Left := 8;
|
Combo.Left := 8;
|
||||||
Combo.Top := 8;
|
Combo.Top := 8;
|
||||||
Combo.Width := 200;
|
Combo.Width := 200;
|
||||||
Combo.Datastore := Datastore;
|
|
||||||
|
ControlLink := TVpControlLink.Create(self);
|
||||||
|
ControlLink.Datastore := Datastore;
|
||||||
|
// This establishes the links to all controls that depend on Datastore.
|
||||||
|
// Must be called when all dependent controls are created.
|
||||||
|
|
||||||
if Datastore.Resources.Count > 0 then
|
if Datastore.Resources.Count > 0 then
|
||||||
Datastore.ResourceID := Datastore.Resources.Items[0].ResourceID;
|
Datastore.Resource := Datastore.Resources.Items[0];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -222,6 +222,7 @@ type
|
|||||||
FResource : TVpResource;
|
FResource : TVpResource;
|
||||||
dsAlertTimer : TTimer; { fires the alerts }
|
dsAlertTimer : TTimer; { fires the alerts }
|
||||||
FNotifiers : TList;
|
FNotifiers : TList;
|
||||||
|
FLinkedOwner: TComponent;
|
||||||
|
|
||||||
{events}
|
{events}
|
||||||
FOnConnect : TNotifyEvent;
|
FOnConnect : TNotifyEvent;
|
||||||
@ -242,6 +243,8 @@ type
|
|||||||
procedure SetDayBuffer(Value: Integer);
|
procedure SetDayBuffer(Value: Integer);
|
||||||
procedure SetRange(StartTime, EndTime: TDateTime);
|
procedure SetRange(StartTime, EndTime: TDateTime);
|
||||||
procedure NotifyLinked;
|
procedure NotifyLinked;
|
||||||
|
procedure LinkToControls(AOwner: TComponent);
|
||||||
|
procedure UnlinkFromControls(AOwner: TComponent);
|
||||||
|
|
||||||
property AutoConnect: Boolean
|
property AutoConnect: Boolean
|
||||||
read FAutoConnect write SetAutoConnect;
|
read FAutoConnect write SetAutoConnect;
|
||||||
@ -279,6 +282,7 @@ type
|
|||||||
procedure PostResources; virtual; abstract;
|
procedure PostResources; virtual; abstract;
|
||||||
procedure RegisterWatcher (Watcher : THandle);
|
procedure RegisterWatcher (Watcher : THandle);
|
||||||
procedure PlaySound(const AWavFile: String; APlaySoundMode: TVpPlaySoundMode);
|
procedure PlaySound(const AWavFile: String; APlaySoundMode: TVpPlaySoundMode);
|
||||||
|
|
||||||
property Loading : Boolean
|
property Loading : Boolean
|
||||||
read FLoading write FLoading;
|
read FLoading write FLoading;
|
||||||
property Resource: TVpResource
|
property Resource: TVpResource
|
||||||
@ -291,6 +295,7 @@ type
|
|||||||
read FActiveDate write SetActiveDate;
|
read FActiveDate write SetActiveDate;
|
||||||
property TimeRange: TVpTimeRange
|
property TimeRange: TVpTimeRange
|
||||||
read FTimeRange;
|
read FTimeRange;
|
||||||
|
|
||||||
published
|
published
|
||||||
property CategoryColorMap: TVpCategoryColorMap
|
property CategoryColorMap: TVpCategoryColorMap
|
||||||
read FCategoryColorMap write FCategoryColorMap;
|
read FCategoryColorMap write FCategoryColorMap;
|
||||||
@ -407,6 +412,7 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -420,8 +426,6 @@ uses
|
|||||||
{ TVpCustomDataStore }
|
{ TVpCustomDataStore }
|
||||||
|
|
||||||
constructor TVpCustomDataStore.Create(AOwner: TComponent);
|
constructor TVpCustomDataStore.Create(AOwner: TComponent);
|
||||||
var
|
|
||||||
I: Integer;
|
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
@ -452,40 +456,7 @@ begin
|
|||||||
|
|
||||||
{ If the DataStore is being dropped onto a form for the first time... }
|
{ If the DataStore is being dropped onto a form for the first time... }
|
||||||
if (csDesigning in ComponentState) and not (csLoading in ComponentState) then
|
if (csDesigning in ComponentState) and not (csLoading in ComponentState) then
|
||||||
begin
|
LinkToControls(Owner);
|
||||||
I := 0;
|
|
||||||
{ Auto connect to the first available ControlLink component found }
|
|
||||||
while (I < Owner.ComponentCount) do begin
|
|
||||||
if (Owner.Components[I] is TVpControlLink)
|
|
||||||
and (TVpControlLink(Owner.Components[I]).DataStore = nil) then begin
|
|
||||||
TVpControlLink(Owner.Components[I]).DataStore := self;
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
Inc(I);
|
|
||||||
end;
|
|
||||||
|
|
||||||
I := 0;
|
|
||||||
{ Then Auto connect to all available LinkableControl components found }
|
|
||||||
while (I < Owner.ComponentCount) do begin
|
|
||||||
if (Owner.Components[I] is TVpLinkableControl) then begin
|
|
||||||
if TVpLinkableControl(Owner.Components[I]).DataStore = nil then
|
|
||||||
TVpLinkableControl(Owner.Components[I]).DataStore := self;
|
|
||||||
end
|
|
||||||
else if (Owner.Components[I] is TVpResourceCombo) then begin
|
|
||||||
if TVpResourceCombo(Owner.Components[I]).DataStore = nil then
|
|
||||||
TVpResourceCombo(Owner.Components[I]).DataStore := self;
|
|
||||||
end
|
|
||||||
else if (Owner.Components[I] is TVpBaseDialog) then begin
|
|
||||||
if TVpBaseDialog(Owner.Components[I]).DataStore = nil then
|
|
||||||
TVpBaseDialog(Owner.Components[I]).DataStore := self;
|
|
||||||
end
|
|
||||||
else if (Owner.Components[I] is TVpControlLink) then begin
|
|
||||||
if TVpControlLink(Owner.Components[I]).DataStore = nil then
|
|
||||||
TVpControlLink(Owner.Components[I]).DataStore := self;
|
|
||||||
end;
|
|
||||||
Inc(I);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ enable the event timer }
|
{ enable the event timer }
|
||||||
if not (csDesigning in ComponentState) then
|
if not (csDesigning in ComponentState) then
|
||||||
@ -494,43 +465,13 @@ end;
|
|||||||
{=====}
|
{=====}
|
||||||
|
|
||||||
destructor TVpCustomDataStore.Destroy;
|
destructor TVpCustomDataStore.Destroy;
|
||||||
var
|
|
||||||
I: Integer;
|
|
||||||
begin
|
begin
|
||||||
DeregisterAllWatchers;
|
DeregisterAllWatchers;
|
||||||
FNotifiers.Free;
|
FNotifiers.Free;
|
||||||
FNotifiers := nil;
|
FNotifiers := nil;
|
||||||
|
|
||||||
{ Remove self from all dependent controls }
|
{ Remove self from all dependent controls }
|
||||||
if Owner <> nil then begin
|
UnlinkFromControls(FLinkedOwner);
|
||||||
I := 0;
|
|
||||||
{ Remove self from dependent Control Links first }
|
|
||||||
while (I < Owner.ComponentCount) do begin
|
|
||||||
if (Owner.Components[I] is TVpControlLink) then begin
|
|
||||||
if TVpControlLink(Owner.Components[I]).DataStore = self then
|
|
||||||
TVpControlLink(Owner.Components[I]).DataStore := nil;
|
|
||||||
end;
|
|
||||||
Inc(I);
|
|
||||||
end;
|
|
||||||
|
|
||||||
I := 0;
|
|
||||||
{ Then remove self from dependent controls }
|
|
||||||
while (I < Owner.ComponentCount) do begin
|
|
||||||
if (Owner.Components[I] is TVpLinkableControl) then begin
|
|
||||||
if TVpLinkableControl(Owner.Components[I]).DataStore = self then
|
|
||||||
TVpLinkableControl(Owner.Components[I]).DataStore := nil;
|
|
||||||
end
|
|
||||||
else if (Owner.Components[I] is TVpResourceCombo) then begin
|
|
||||||
if TVpResourceCombo(Owner.Components[I]).DataStore = self then
|
|
||||||
TVpResourceCombo(Owner.Components[I]).DataStore := nil;
|
|
||||||
end
|
|
||||||
else if (Owner.Components[I] is TVpBaseDialog) then begin
|
|
||||||
if TVpBaseDialog(Owner.Components[I]).DataStore = self then
|
|
||||||
TVpBaseDialog(Owner.Components[I]).DataStore := nil;
|
|
||||||
end;
|
|
||||||
Inc(I);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
FResources.Free;
|
FResources.Free;
|
||||||
FTimeRange.Free;
|
FTimeRange.Free;
|
||||||
@ -546,8 +487,8 @@ end;
|
|||||||
procedure TVpCustomDataStore.DeregisterAllWatchers;
|
procedure TVpCustomDataStore.DeregisterAllWatchers;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if FNotifiers <> nil then
|
||||||
for i := FNotifiers.Count - 1 downto 0 do
|
for i := FNotifiers.Count - 1 downto 0 do
|
||||||
if Assigned(FNotifiers[i]) then begin
|
if Assigned(FNotifiers[i]) then begin
|
||||||
FreeMem(FNotifiers[i]);
|
FreeMem(FNotifiers[i]);
|
||||||
@ -559,8 +500,8 @@ end;
|
|||||||
procedure TVpCustomDataStore.DeregisterWatcher (Watcher : THandle);
|
procedure TVpCustomDataStore.DeregisterWatcher (Watcher : THandle);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if FNotifiers <> nil then
|
||||||
for i := FNotifiers.Count - 1 downto 0 do
|
for i := FNotifiers.Count - 1 downto 0 do
|
||||||
if Assigned(FNotifiers[i]) then
|
if Assigned(FNotifiers[i]) then
|
||||||
if PVpWatcher (FNotifiers[i]).Handle = Watcher then begin
|
if PVpWatcher (FNotifiers[i]).Handle = Watcher then begin
|
||||||
@ -913,8 +854,91 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{=====}
|
|
||||||
|
|
||||||
|
{ This code links the datastore to the Datastore property of all dependent
|
||||||
|
components.
|
||||||
|
AOwner is normally a TForm and is stored in FLinkedOwner to be unlinked by
|
||||||
|
destructor.
|
||||||
|
The method is useful if datastores are created at runtime. }
|
||||||
|
procedure TVpCustomDatastore.LinkToControls(AOwner: TComponent);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
UnlinkFromControls(FLinkedOwner);
|
||||||
|
|
||||||
|
if (AOwner = nil) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
{ Auto connect to the first available ControlLink component found }
|
||||||
|
for i := 0 to AOwner.ComponentCount - 1 do begin
|
||||||
|
if (AOwner.Components[I] is TVpControlLink) and
|
||||||
|
(TVpControlLink(AOwner.Components[I]).DataStore = nil) then
|
||||||
|
begin
|
||||||
|
TVpControlLink(AOwner.Components[I]).DataStore := Self;
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Then Auto connect to all available LinkableControl components found }
|
||||||
|
for i := 0 to AOwner.ComponentCount - 1 do begin
|
||||||
|
if (AOwner.Components[I] is TVpLinkableControl) then begin
|
||||||
|
if TVpLinkableControl(AOwner.Components[I]).DataStore = nil then
|
||||||
|
TVpLinkableControl(AOwner.Components[I]).DataStore := Self;
|
||||||
|
end
|
||||||
|
else if (AOwner.Components[I] is TVpResourceCombo) then begin
|
||||||
|
if TVpResourceCombo(AOwner.Components[I]).DataStore = nil then
|
||||||
|
TVpResourceCombo(AOwner.Components[I]).DataStore := Self;
|
||||||
|
end
|
||||||
|
else if (AOwner.Components[I] is TVpBaseDialog) then begin
|
||||||
|
if TVpBaseDialog(AOwner.Components[I]).DataStore = nil then
|
||||||
|
TVpBaseDialog(AOwner.Components[I]).DataStore := Self;
|
||||||
|
end;
|
||||||
|
{
|
||||||
|
else if (AOwner.Components[I] is TVpControlLink) then begin
|
||||||
|
if TVpControlLink(AOwner.Components[I]).DataStore = nil then
|
||||||
|
TVpControlLink(AOwner.Components[I]).DataStore := Self;
|
||||||
|
end;
|
||||||
|
}
|
||||||
|
end;
|
||||||
|
|
||||||
|
FLinkedOwner := AOwner;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Removes the "Datastore" links from dependent controls.
|
||||||
|
Is called automatically by destructor. }
|
||||||
|
procedure TVpCustomDatastore.UnlinkFromControls(AOwner: TComponent);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if AOwner = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
{ Remove self from dependent Control Links first }
|
||||||
|
for i:= 0 to AOwner.ComponentCount-1 do begin
|
||||||
|
if (AOwner.Components[I] is TVpControlLink) then begin
|
||||||
|
if TVpControlLink(AOwner.Components[I]).DataStore = self then
|
||||||
|
TVpControlLink(AOwner.Components[I]).DataStore := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Then remove self from dependent controls }
|
||||||
|
for i := 0 to AOwner.ComponentCount-1 do begin
|
||||||
|
if (AOwner.Components[I] is TVpLinkableControl) then begin
|
||||||
|
if TVpLinkableControl(AOwner.Components[I]).DataStore = self then
|
||||||
|
TVpLinkableControl(AOwner.Components[I]).DataStore := nil;
|
||||||
|
end
|
||||||
|
else if (AOwner.Components[I] is TVpResourceCombo) then begin
|
||||||
|
if TVpResourceCombo(AOwner.Components[I]).DataStore = self then
|
||||||
|
TVpResourceCombo(AOwner.Components[I]).DataStore := nil;
|
||||||
|
end
|
||||||
|
else if (AOwner.Components[I] is TVpBaseDialog) then begin
|
||||||
|
if TVpBaseDialog(AOwner.Components[I]).DataStore = self then
|
||||||
|
TVpBaseDialog(AOwner.Components[I]).DataStore := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
FLinkedOwner := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TVpEventDragObject }
|
{ TVpEventDragObject }
|
||||||
|
|
||||||
@ -1425,8 +1449,10 @@ end;
|
|||||||
|
|
||||||
procedure TVpControlLink.SetDataStore(const Value: TVpCustomDataStore);
|
procedure TVpControlLink.SetDataStore(const Value: TVpCustomDataStore);
|
||||||
begin
|
begin
|
||||||
if FDataStore <> Value then
|
if FDataStore <> Value then begin
|
||||||
FDataStore := Value;
|
FDataStore := Value;
|
||||||
|
if FDatastore <> nil then FDatastore.LinkToControls(Owner);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
{=====}
|
{=====}
|
||||||
procedure TVpControlLink.SetDefaultCountry (const v : string);
|
procedure TVpControlLink.SetDefaultCountry (const v : string);
|
||||||
|
Reference in New Issue
Block a user