Componentes.Terceros.RemObj.../internal/6.0.43.801/1/Data Abstract for Delphi/Source/uDAScriptingProvider.pas

151 lines
4.6 KiB
ObjectPascal
Raw Permalink Normal View History

unit uDAScriptingProvider;
{----------------------------------------------------------------------------}
{ Data Abstract Library - Core Library }
{ }
{ compiler: Delphi 6 and up, Kylix 3 and up }
{ platform: Win32, Linux }
{ }
{ (c)opyright RemObjects Software. all rights reserved. }
{ }
{ Using this code requires a valid license of the Data Abstract }
{ which can be obtained at http://www.remobjects.com. }
{----------------------------------------------------------------------------}
{$I DataAbstract.inc}
interface
uses
Classes, SysUtils, uROClient;
type
TScriptableComponent = class;
TDAScriptingProvider = class(TROComponent)
private
FScriptableComponent: TScriptableComponent;
procedure SetScriptableComponent(const Value: TScriptableComponent);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property ScriptableComponent: TScriptableComponent read FScriptableComponent write SetScriptableComponent;
end;
IDAScriptingProvider = interface
['{6D19A2F9-233A-4EE6-95EC-CDFCD7410C15}']
end;
EDAScriptError = class(Exception);
EDAScriptCompileError = class(EDAScriptError);
TScriptableComponent = class(TROComponent)
private
fScriptingProvider: TDAScriptingProvider;
procedure SetScriptingProvider(const Value: TDAScriptingProvider);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property ScriptingProvider: TDAScriptingProvider read fScriptingProvider write SetScriptingProvider;
end;
implementation
{ TScriptableComponent }
procedure TScriptableComponent.Assign(Source: TPersistent);
var
lSource: TScriptableComponent;
begin
inherited;
if Source is TScriptableComponent then begin
lSource := TScriptableComponent(Source);
ScriptingProvider := lSource.ScriptingProvider;
end;
end;
destructor TScriptableComponent.Destroy;
begin
ScriptingProvider := nil;
inherited;
end;
procedure TScriptableComponent.Notification(AComponent: TComponent;
Operation: TOperation);
begin
if (Operation = opRemove) then begin
if (AComponent = fScriptingProvider) then fScriptingProvider := nil;
end;
inherited;
end;
procedure TScriptableComponent.SetScriptingProvider(const Value: TDAScriptingProvider);
begin
if fScriptingProvider <> Value then begin
if fScriptingProvider <> nil then begin
fScriptingProvider.RORemoveFreeNotification(self);
fScriptingProvider.ScriptableComponent:=nil;
end;
if Value <> nil then Value.ScriptableComponent := Self;
if Assigned(fScriptingProvider) then fScriptingProvider.ROFreeNotification(self);
end;
end;
{ TDAScriptingProvider }
procedure TDAScriptingProvider.Assign(Source: TPersistent);
var
lSource: TDAScriptingProvider;
begin
inherited;
if Source is TDAScriptingProvider then begin
lSource := TDAScriptingProvider(Source);
ScriptableComponent := lSource.ScriptableComponent;
end;
end;
destructor TDAScriptingProvider.Destroy;
begin
ScriptableComponent := nil;
inherited;
end;
procedure TDAScriptingProvider.Notification(AComponent: TComponent;
Operation: TOperation);
begin
if (Operation = opRemove) then begin
if (AComponent = FScriptableComponent) then begin
FScriptableComponent.fScriptingProvider:=nil;
FScriptableComponent := nil;
end;
end;
inherited;
end;
procedure TDAScriptingProvider.SetScriptableComponent(
const Value: TScriptableComponent);
begin
if FScriptableComponent <> Value then begin
if FScriptableComponent <> nil then begin
FScriptableComponent.RORemoveFreeNotification(Self);
FScriptableComponent.fScriptingProvider:=nil;
end;
FScriptableComponent := Value;
if Assigned(FScriptableComponent) then begin
FScriptableComponent.fScriptingProvider := Self;
FScriptableComponent.ROFreeNotification(Self);
end;
end;
end;
end.