Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Accessing property values of TFDConnection - Tag or Connected


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Aug 12, 2016 8:33 AM Last Post By: Roy Lambert
Barry Wood

Posts: 73
Registered: 9/3/01
Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 4:05 AM
Hi

This might be a FireDac or database question but I'm thinking it's just some programming thing I may have wrong.

I have a Remote SQL Server holding Live data and a Local SQL Server holding test data. My application needs to display which one it is connected to. To do this I simply have a label displaying a caption of either 'REMOTE-LIVE' or LOCAL-TEST', but to set that caption I need to find out which FireDac connection is connected (I have a separate data module containing the database elements). I have two TFDConnections one for Remote and one for Local connectivity. I thought this would be simple to do - check the Connected property (Boolean). Alas this doesn't work, I get an Access violation.

Hmm, so then I set the Tag property of the Local connection to 1 (Remote defaulted to 0), and checked the Tag property for a 0 or a 1. Does this work? No, I get same Access violation.

Isn't it possible to access the properties of the TFDConnection?
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 4:43 AM   in response to: Barry Wood in response to: Barry Wood
Barry

I don't use FireDAC so its wild guess time. If you're getting an AV the chances are that the object you're trying to access hasn't been created yet.

Roy Lambert

Barry Wood

Posts: 73
Registered: 9/3/01
Re: Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 5:39 AM   in response to: Barry Wood in response to: Barry Wood
Hi Roy, thanks for taking the time to respond.

The property value I'm trying to access is in the TFDConnection. It may be that at the time I'm trying to access those properties the TFDConnection hasn't been made and so do not exist. A good thought. My code is in the Form.Activate event, so that would make sense - I'll move it somewhere else (behind a button after the form (and data connections) are created and see. Thanks for the thought.
Barry Wood

Posts: 73
Registered: 9/3/01
Re: Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 5:43 AM   in response to: Barry Wood in response to: Barry Wood
Hi Roy (again),

Yes, that's it - I moved my code behind a button on the Form and it works OK now. I should have realised this, but thanks for helping out.
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 6:08 AM   in response to: Barry Wood in response to: Barry Wood
Barry

Yes, that's it - I moved my code behind a button on the Form and it works OK now. I should have realised this, but thanks for helping out.

On the basis I just spent 20 minutes trying to understand why I had a . before an = and then found out if I wiped the screen it went away I don't think you're doing to badly <g>

When I have something like this I generally stuff a timer on the form and enable it as the last line on the form's OnCreate event. About 150 seems to do the job most times.

Roy
Anders Isaksson


Posts: 30
Registered: 4/15/00
Re: Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 7:00 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:


When I have something like this I generally stuff a timer on the form
and enable it as the last line on the form's OnCreate event. About
150 seems to do the job most times.

Better to send a custom message to yourself at the end of OnCreate and
do the work in the message handler. Then you'll be sure that everything
is up and running before you try anything.

[code]
...
const
wm_ReallyStarted = wm_user + 1000;

type
TfrmMain
...
procedure WMReallyStarted(var Msg: TMessage); message
wm_ReallyStarted;
...
end;

...

procedure TFrmMain.WMReallyStarted(var Msg: TMessage);
begin
(* whatever *)
end;

[code]
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Accessing property values of TFDConnection - Tag or Connected  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2016 8:33 AM   in response to: Anders Isaksson in response to: Anders Isaksson
Anders

Better to send a custom message to yourself at the end of OnCreate and
do the work in the message handler. Then you'll be sure that everything
is up and running before you try anything.

Possibly. However, my approach means that there's a bit of a gap between the OnCreate event completing and the code running. Posting a message means that its actioned as soon as the message handler gets to it which may still be a bit to early.

An even better method would, in this specific case, be to alter the TFDConnection so that it sends a custom message back once its set things up.

Roy
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02