Skip to content

Commit

Permalink
Added new demo that demonstrates how object interfaces in Object Pasc…
Browse files Browse the repository at this point in the history
…al work.
  • Loading branch information
beNative committed Sep 12, 2018
1 parent 8560abc commit ef019b5
Show file tree
Hide file tree
Showing 21 changed files with 1,992 additions and 98 deletions.
8 changes: 8 additions & 0 deletions Concepts.Registration.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ implementation
Concepts.System.VirtualMethodInterceptor.Form,
Concepts.System.VirtualInterface.Form,
Concepts.System.PublishedFields.Form,
Concepts.System.Interfaces.Form,
{$ENDIF}

{$IFDEF DEVEXPRESS}
Expand Down Expand Up @@ -392,6 +393,13 @@ class procedure TConcepts.RegisterSystemConcepts;
'Demonstrates a form with components without published fields.',
FCategoryColor
);
ConceptManager.Register(
TfrmInterfaces,
'Interfaces',
'System',
'Demonstrates how object interfaces work.',
FCategoryColor
);
{$ENDIF}
end;

Expand Down
11 changes: 8 additions & 3 deletions Concepts.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,25 @@ uses
Concepts.DevExpress.cxGridViewPresenter.Form in 'Forms\Concepts.DevExpress.cxGridViewPresenter.Form.pas' {frmcxGridViewPresenter},
Concepts.VirtualTreeView.Form in 'Forms\Concepts.VirtualTreeView.Form.pas' {frmVirtualTreeView},
Concepts.FireDAC.Form in 'Forms\Concepts.FireDAC.Form.pas' {frmFireDAC},
Concepts.System.PublishedFields.Form in 'Forms\Concepts.System.PublishedFields.Form.pas' {frmPublishedFields};
Concepts.System.PublishedFields.Form in 'Forms\Concepts.System.PublishedFields.Form.pas' {frmPublishedFields},
Concepts.System.Interfaces.DelegatedImplementation in 'Forms\Concepts.System.Interfaces.DelegatedImplementation.pas',
Concepts.System.Interfaces.Form in 'Forms\Concepts.System.Interfaces.Form.pas' {frmInterfaces},
Concepts.System.Interfaces.InterfacedObject in 'Forms\Concepts.System.Interfaces.InterfacedObject.pas',
Concepts.System.Interfaces.Interfaces in 'Forms\Concepts.System.Interfaces.Interfaces.pas',
Concepts.System.Interfaces.WeakReferences in 'Forms\Concepts.System.Interfaces.WeakReferences.pas';

{$R *.res}

{ Used to directly start a concept by name. If empty a list will be shown with
all registered concepts. }
const
// EXECUTE_BY_NAME = '';
EXECUTE_BY_NAME = '';
//EXECUTE_BY_NAME = 'ZeroMQ';
// EXECUTE_BY_NAME = 'FireDAC';
//EXECUTE_BY_NAME = 'ORM';
//EXECUTE_BY_NAME = 'TStringList';
//EXECUTE_BY_NAME = 'Indy';
EXECUTE_BY_NAME = 'Parallel Library';
//EXECUTE_BY_NAME = 'Parallel Library';

begin
{$WARNINGS OFF}
Expand Down
8 changes: 8 additions & 0 deletions Concepts.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@
<DCCReference Include="Forms\Concepts.System.PublishedFields.Form.pas">
<Form>frmPublishedFields</Form>
</DCCReference>
<DCCReference Include="Forms\Concepts.System.Interfaces.DelegatedImplementation.pas"/>
<DCCReference Include="Forms\Concepts.System.Interfaces.Form.pas">
<Form>frmInterfaces</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="Forms\Concepts.System.Interfaces.InterfacedObject.pas"/>
<DCCReference Include="Forms\Concepts.System.Interfaces.Interfaces.pas"/>
<DCCReference Include="Forms\Concepts.System.Interfaces.WeakReferences.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
Expand Down
Binary file modified Concepts.res
Binary file not shown.
115 changes: 115 additions & 0 deletions Forms/Concepts.System.Interfaces.DelegatedImplementation.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
Copyright (C) 2013-2018 Tim Sinaeve [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}

{$I Concepts.inc}

unit Concepts.System.Interfaces.DelegatedImplementation;

interface

uses
System.Classes,

Concepts.System.Interfaces.Interfaces,
Concepts.System.Interfaces.InterfacedObject;

type
TInterfacedObject =
Concepts.System.Interfaces.InterfacedObject.TMyInterfacedObject;

type
{ This simple class descends from TObject and does not implement
IInnerInterface directly. An instance of this object will be used to
let an outer object implement IInnerInterface through the 'implements'
syntax. }
TInnerObject = class(TObject)
// TInnerObject = class(TInterfacedObject, IInnerInterface)
public
procedure InnerMethod;

end;

TOuterObject = class(TInterfacedObject, IOuterInterface, IInnerInterface)
private
FInnerObject : TInnerObject;
//FInnerInterface : IInnerInterface;

//function GetInnerObject: IInnerInterface;

property InnerObject: TInnerObject
read FInnerObject implements IInnerInterface;

public
procedure BeforeDestruction; override;

constructor Create(
AIsRefCounted : Boolean;
AOnAddRef : TRefCountEvent = nil;
AOnRelease : TRefCountEvent = nil;
AOnQueryInterface : TNotifyEvent = nil;
AOnDestroy : TNotifyEvent = nil
); override;

//procedure IInnerInterface.InnerMethod = MyInnerMethod;
procedure MyInnerMethod;

procedure OuterMethod;
end;

implementation

uses
Vcl.Dialogs;

{ TInnerObject }

procedure TInnerObject.InnerMethod;
begin
ShowMessage('TInnerObject.InnerMethod called.');
end;

{ TOuterObject }

procedure TOuterObject.BeforeDestruction;
begin
FInnerObject.Free;
inherited BeforeDestruction;
end;

constructor TOuterObject.Create(AIsRefCounted: Boolean; AOnAddRef,
AOnRelease: TRefCountEvent; AOnQueryInterface, AOnDestroy: TNotifyEvent);
begin
inherited Create(AIsRefCounted, AOnAddRef, AOnRelease, AOnQueryInterface, AOnDestroy);
FInnerObject := TInnerObject.Create;
//FInnerInterface := TInnerObject.Create(AIsRefCounted, AOnAddRef, AOnRelease, AOnQueryInterface, AOnDestroy);
end;

//function TOuterObject.GetInnerObject: IInnerInterface;
//begin
// Result := FInnerInterface;
//end;

procedure TOuterObject.MyInnerMethod;
begin
ShowMessage('TOuterObject.MyInnerMethod called.');
end;

procedure TOuterObject.OuterMethod;
begin
ShowMessage('TOuterObject.OuterMethod called.');
end;

end.
Loading

0 comments on commit ef019b5

Please sign in to comment.