[Classes] [Prev] [Next] [Methods]

CTdiConnection

Methods Index

Heritage
Description
Usage
Protected Data Members
Public Methods
Constructor and Destructor Methods
Connection Methods
Private Methods

CTdiConnection


Heritage

Superclass: None

Subclasses: CTdiTableConnection, CTdiIndexConnection


Description

CTdiConnection provides a simple interface that encapsulates the implementation and management of TDI connections. By restricting your TDI interactions to the CTdiConnection interface, you eliminate the need to deal with implementation details that can vary in complexity and that may change for different purposes.


Usage

CTdiConnection enables you to create a connection between a TDI provider and a TDI dependent in one line of code. For instance, the following code creates a connection between a DBQuery and a ListBox:

CTdiConnection aConnection(aDBQuery, aListBox);
This connection can be disconnected and reconnected at any time as follows:

aConnection.Disconnect();
...
-or-

aConnection.Connect();
The lifetime of the connection is not tied to the lifetime of the CTdiConnection that created it. Therefore, a connection will remain active even after the CTdiConnection goes out of scope. If either the provider or dependent are destroyed, the connection will break automatically.

Normally, you simply create CTdiConnection objects on the stack and forget about them once the connection is established. However, if you foresee the need to access the connection or its components at a later time, you also can create the CTdiConnection object on the heap and store it while you need it, as follows:

itsConnection = new CTdiConnection(
aDBQuery, aListBox);
...
// Use itsConnection
...
// Delete itsConnection;
CTdiConnection also allows you to associate a prototype CTdiValue with the connection. If provided, this value is used whenever the provider sends TDI messages to the dependent. In essence, whenever the provider sends a TDI message, the prototype is asked to copy that data, using the CTdiValue::Copy(). In addition, if the prototype value contains a context command, that command is used for the TDI message between provider and dependent. (For more information, see CTdiValue).

For example, the following code establishes a connection between a CheckBox and a RadioGroup. The connection causes the RadioGroup to be visible only if the CheckBox is checked.

CTdiConnection aConnection(
aCheckBox,
aRadioGroup,
new CTdiBooleanValue(
aCheckBox, TRUE, TDIVisibleCmd)
);
In the preceding example, aConnection establishes a TDI connection between aCheckBox (the provider) and aRadioGroup (the dependent). Because of this connection, whenever the CheckBox's checked state changes, it sends a TDI message that is propagated to the RadioGroup. However, the connection also has a prototype model:

new CTdiBooleanValue(aCheckBox, TRUE, TDIVisibleCmd)
This CTdiBooleanValue copies the information in the CTdiValue that the CheckBox sent. A pointer to this CTdiBooleanValue is then sent in a TDI message to the RadioGroup, and TDIVisibleCmd will be the TDI command for the message.

In general, prototypes need to be added to a connection only in the following cases:


Protected Data Members

CTdiValue* itsPrototype; Connection's prototype value
CNotifier* itsProvider; TDI provider
CNotifier* itsDependent; TDI dependent
BOOLEAN isConnected; Current connection state


Public Methods

Constructor and Destructor Methods

CTdiConnection(
CNotifier* theProvider,
CNotifier* theDependent,
CTdiValue* thePrototype = NULL,
// consumed by connection
BOOLEAN autoConnect = TRUE);
virtual ~CTdiConnection();

Connection Methods

virtual BOOLEAN Connect();
virtual BOOLEAN Disconnect();
virtual void Request(
long theRequestCommand,
CTdiValue* theData = NULL);
CNotifier* GetProvider() const;
CNotifier* GetDependent() const;
CTdiValue* GetPrototype() const;
void SetPrototype(CTdiValue* thePrototype); 
void SetContext(long theContext);
long GetContext() const;

Private Methods

CTdiConnection(
const CTdiConnection& theCopy);
CTdiConnection& operator=(
const CTdiConnection& theCopy);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.