[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Accessing a property of TCollectionItem's owner component

Posted on 2004-10-17
10
Medium Priority
?
498 Views
Last Modified: 2013-11-23
I am creating a component that has a collection.  Within the creation of the collection item, I need to get access to a property of the component object that owns the collection.  Here is the component code:

TSubject = class(TCollectionItem)
private
  {Private declarations
  FName: String;
  FListener: ITibrvListener;
  FOnMessage: TTIbrvComLibITibrvListenerEvents;

  FOnMessageReceived: TMessageReceived;

  procedure SetName(const Value: String);
protected
  {Protected declarations}
  function GetDisplayName: String; override;

  procedure MessageReceived(Sender: TObject; const listener: ITibrvListener; const message: ITibrvListener; const Message: ITibrvMsg); dynamic;
published
  {Published declarations}
  property Name: String read FName write SetName;

  property OnMessageReceived: TMessageReceived read FOnMessageReceived write FOnMessageReceived;
public
  {Public declarations}
  constructor Create(Collection: TCollection); override;
  destructor Destroy; override;
end;

TSubjects = class(TOwnedCollection)
private
  {Private declarations}
  function GetItem(Index: Integer): TSubject;
  procedure SetItem(Index: Integer; const Value: TSubject);
protected
  {Protected declarations}
published
  {Published declarations}
public
  {Public declarations}
  function Add: TSubject;
  procedure Delete(Index: Integer);
  function Insert(Index: Integer): TSubject;
  property Items[Index: Integer]: TSubject read GetItem write SetItem; default;
end;

TtbrvListener = class(TComponent)
private
  {Private declarations}
  FTibrv: ITibrv;
  FNetTransport: ITibrvTransport;
  FSubjects: TSubjects;
protected
  {Protected declarations}
public
  {Public declarations}
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
published
  {Published declarations}
  property Subjects: TSubjects read FSubjects write FSubjects;
end;

Now, within the create procedure of the TSubject object, I need to access the FTibrv and FNetTransport objects of the collection's owning component (the TtbrvListener object).  Here is the constructor code for the TSubject collection item object where I need to do this.  Note that I have simply inserted [OwnerComponent] in the code where I need to get into the TtbrvListener owner component and access the FTibrv and FNetTransport objects because I don't know how to do this.

constructor TSubject.Create(Collection: TCollection);
begin
  inherited Create(Collection);
  FListener.initialize([OwnerComponent].FTibrv.GetDefaultQueue, [OwnerComponent].FNetTransport, FName, 0);
end;
 
0
Comment
Question by:meyousikmann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 9

Accepted Solution

by:
ginsonic earned 2000 total points
ID: 12336190
FListener.Initialize(TtbrvListener(Self.Collection.Owner).FTibrv.GetDefaultQueue,TtbrvListener(Self.Collection.Owner).FNetTransport, FName, 0);
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 12336200
Your collection item owner is : TtbrvListener(Self.Collection.Owner)

With it you can do everthing.
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 12336869
Add a FListener variable to your TSubject object which has a type of TtbrvListener. At that time you'll have a link to the TtbrvListener object but you need to change your TSubject's constructor like this :

constructor TSubject.Create(Collection: TCollection; AListener: TtbrvListener);
begin
  FListener := AListener;
  ..
  ..
end;

For to access the private properties of a TtbrvListener, you need to put TSubject and TtbrvListener to the same unit. And then you can access like this :

FListener.FTibrv := ...

Or you may choose to add share the FTibrv and FNetTransport properties by declaring a couple of property which will make them read only into the public section :

TtbrvListener = class(TComponent)
private
  {Private declarations}
  FTibrv: ITibrv;
  FNetTransport: ITibrvTransport;
  FSubjects: TSubjects;
protected
  {Protected declarations}
public
  {Public declarations}
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
  property Tibv: ITibrv read FTibrv;
  property NetTransport: ITibrvTransport read FNetTransport;
published
  {Published declarations}
  property Subjects: TSubjects read FSubjects write FSubjects;
end;

Regards,

Oktay
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:ceoworks
ID: 12336906
<Or you may choose to add share the FTibrv and FNetTransport properties by declaring a couple of property which will make them read only into the public section>

should be :

"Or you may choose to share the FTibrv and FNetTransport fields by declaring a couple of property which will make them read only into the public section" :)
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 12336931
If TSubject objects will need to set some new values to the FTibrv and FNetTransport, you can change their properties from readonly to read/write :

property Tibrv: ITibrv read FTibrv write FTibrv;
property NetTransport: ITibrvTransport read FNetTransport write FNetTransport;

Cheers,

Oktay Sancak
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 12338189
Why do you complicate the code when is so easy to get the collection owner :)

I use NOW on my new VCL exactly proposed solution. And work PERFECT!
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 12338468
Sorry i didn't notice that TCollectionItem has a Collection property.. Of course the thing you said is the easier way to do it. Anyway, my example can be use for an another situation :)

Thanks for you to remind ginsonic, cheers..

Oktay
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 12338539
Just a friendly comment. See on net ! :)
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 12341363
<Just a friendly comment>

I know :) have a nice day, see ya :)
0
 

Author Comment

by:meyousikmann
ID: 12347867
Thanks for all the responses........the help is much appreciated
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question