Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: FDConnection.Create() but without an Owner?


This question is answered.


Permlink Replies: 3 - Last Post: Aug 29, 2014 6:54 PM Last Post By: Michael Leahy
Michael Leahy

Posts: 239
Registered: 5/9/07
FDConnection.Create() but without an Owner?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 29, 2014 11:29 AM
I'm a newbie at all things FireDAC.

I need a solution in code. Placing components on a form will not work.

My object (TBook) is in its own unit and it descends from TObject in Firemonkey. TBook has a protected variable fFireDACConnection of type TFDConnection.


constructor TBook.Create;
begin
  inherited Create;
 
  fFireDACConnection.Create(Self);


This does not compile because the TBook descends from TObject and not TComponent.

How do I create a TFDConnection without an owner?
Michael Leahy

Posts: 239
Registered: 5/9/07
Re: FDConnection.Create() but without an Owner?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 29, 2014 5:05 PM   in response to: Michael Leahy in response to: Michael Leahy
It turns out nil can be passed as the Owner.

Can anyone point me to documentation on "owner-less" TComponents?
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: FDConnection.Create() but without an Owner?
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 29, 2014 6:15 PM   in response to: Michael Leahy in response to: Michael Leahy
Michael Leahy wrote:
It turns out nil can be passed as the Owner.

Can anyone point me to documentation on "owner-less" TComponents?

OOPS> As I said in my MISSING post a couple of hours AGO

OOPS> you also need to use the constructor correctly
OOPS>
OOPS>   fFireDacConnection := TFDConnection.Create( nil );
OOPS> 


OOPS> ie create instance from class constructor

As to Ownerless controls no real need for "special" stuff apart from the need to manage them yourself (Destruction)

All the owner property does is add the new Component to the OWNERS managed list (see nil is allowed) FComponents
  if AOwner <> nil then AOwner.InsertComponent(Self);


So that when the owner is destroyed its Components are also destroyed ... and that about it - you now have to manage the destruction of the control you create !

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

Edited by: Linden ROTH on Aug 29, 2014 6:18 PM
OOPS> Double thread
Michael Leahy

Posts: 239
Registered: 5/9/07
Re: FDConnection.Create() but without an Owner?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 29, 2014 6:54 PM   in response to: Linden ROTH in response to: Linden ROTH
Thanks, Linden.

My actual code had the correct constructor syntax. :)

Linden ROTH wrote:
Michael Leahy wrote:
It turns out nil can be passed as the Owner.

Can anyone point me to documentation on "owner-less" TComponents?

OOPS> As I said in my MISSING post a couple of hours AGO

OOPS> you also need to use the constructor correctly
OOPS>
OOPS>   fFireDacConnection := TFDConnection.Create( nil );
OOPS> 


OOPS> ie create instance from class constructor

As to Ownerless controls no real need for "special" stuff apart from the need to manage them yourself (Destruction)

All the owner property does is add the new Component to the OWNERS managed list (see nil is allowed) FComponents
  if AOwner <> nil then AOwner.InsertComponent(Self);


So that when the owner is destroyed its Components are also destroyed ... and that about it - you now have to manage the destruction of the control you create !

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

Edited by: Linden ROTH on Aug 29, 2014 6:18 PM
OOPS> Double thread
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02