Posts

Showing posts from May, 2009

Tentative definitions

The ANSI C standard supports the concept of the tentative definition. Any external data declaration that has no storage class specifier and no initializer is considered a tentative definition. If the identifier declared appears in a later definition, then the tentative definition is treated as if the extern storage class specifier were present. In other words, the tentative definition becomes a simple referencing declaration.

If the end of the translation unit is reached and no definition has appeared with an initializer for the identifier, then the tentative definition becomes a full definition, and the object defined has uninitialized (zero-filled) space reserved for it. For example,

int x;

int x; /*legal, one copy of x is reserved */
int y;
int y = 4; /* legal, y is initialized to 4 */
int z = 5;

int z = 6; /* not legal, both are initialized definitions */

Unlike ANSI C, C++ doesn't have the concept of a tentative declaration; an external data declaration without …

TClientDataSet

TClientDataSet implements a database-independent dataset.

Unit

dbclient

Description

TClientDataSet encapsulates a database-independent, distributed dataset. A client dataset can be used as a

Fully-functional, standalone, flat-file dataset for single-tiered database applications. When used in this manner, an application uses the client dataset to read from and write to a user’s hard disk directly, without accessing a database engine.
Client dataset in the client application portion of a multi-tiered database application.

Note: The two functions described above are not mutually exclusive. A multi-tiered application can be designed to support the option of working with data off-line, using the “briefcase” model. On site, the application uses TClientDataSet to communicate with the application server’s data provider. When a user works off site, the client dataset writes a snapshot of the data to the hard disk. The application works with this snapshot off site, with the client dataset acting as …

IAppServer::AS_Execute

Executes the query or stored procedure bound to a specified provider.

virtual HRESULT __safecall AS_Execute(const WideString: ProviderName, const WideString: CommandText, OleVariant &Params, OleVariant &OwnerData) = 0 ;

Description

Use AS_Execute to pass an execute command to a remote provider, using a specified set of parameters. AS_Execute calls the Execute method of the specified provider after assigning any parameters. Output parameters that result from executing a query or stored procedure are returned in the Params parameter.

Note: Different types of provider interpret the Execute command in different ways. Some providers merely generate BeforeExecute and AfterExecute events, while others execute a query or stored procedure.

The ProviderName parameter specifies the name of the provider component associated with the query or stored procedure.

CommandText specifies an optional SQL statement that replaces the SQL of the provider’s query, or the name of a stored procedure that re…

Field Link designer

The Field Link Designer provides a visual way to link (join) master and detail tables.
At design time, drop a TDataSource object on the form and define a datasource. Select the TTable component and double-click the MasterFields property in the Object Inspector to invoke the Field Link designer.

Available Indexes combo box

The Available Indexes combo box shows the currently selected index used to join the tables. Unless you specify a different index name in the table’s IndexName property, the default index used for the link is the primary index for the table. Other available indexes defined on the table can be selected from the drop-down list.

To link master and detail tables:

1 Select the field to use to link the detail table in the Detail Fields list
2 Select the field to link the master table in the Master Fields list.
3 Choose Add.

The selected fields are be displayed in the Joined Fields list box. For example,

OrderNo -> OrderNo

Note: For tables on a database server, the Available I…

BeforeGetRecords, Active, CloneCursor, FetchOnDemand Example

Image
This example shows how to use the BeforeGetRecords event handler to send the application server information it needs for incremental data fetching. Before fetching the next data packet, the client dataset packages up the key value of the last record so that the application server knows where to begin the next data packet. It also sends some application-specific information, which is stored in Memo1.

void __fastcall TForm1::ClientDataSet1BeforeGetRecords(TObject *Sender, OleVariant &OwnerData)
{
OleVariant[2] Values;
Values[0] = NULL;
if (ClientDataSet1->Active)
{
ClientDataSet *CDSClone = new ClientDataSet(Form1);
try
{
CDSClone->CloneCursor(ClientDataSet1, true);
// turn off FetchOnDemand so that the clone only
// fetches the last LOCAL record
CDSClone->FetchOnDemand = false;
CDSClone->Last();
Values[0] = CDSClone->Fields->Fields[0]->Value;
CDSClone->Close();
}
__finally
{
delete CDSClone;
}
}
Values[1] = Memo1->Lines->Text;
OwnerData = VarArrayOf(V…

TClientDataSet::FetchOnDemand

Image
Indicates whether to fetch data packets from the provider on an as needed basis.

__property bool FetchOnDemand = {read=FFetchOnDemand, write
=FFetchOnDemand, default=1};

Description

By default FetchOnDemand is true, meaning that the client dataset fetches additional packets of data as needed (for example, as a user scrolls through data, or conducts a search). If the server does not automatically include BLOB fields or nested detail sets in data packets, setting FetchOnDemand to true causes the client dataset to fetch these values when needed as well.

Set FetchOnDemand to false only if your client application contains code that explicitly fetches data packets as needed using the GetNextPacket method. Similarly, if FetchOnDemand is false, and the provider component does not include BLOB data by default (Options includes poFetchBlobsOnDemand), the client application must fetch BLOB fields explicitly using the FetchBlobs method. If the provider does not include nested detail sets (Options…

TClientDataSet::GetNextPacket

Image
Retrieves the next block of records from the application server.

int __fastcall GetNextPacket(void);

Description

Call GetNextPacket to retrieve the next sequential block of records from the application server. To specify the maximum number of records to return in a packet, set the PacketRecords property before calling GetNextPacket. A packet is appended to those records already stored in the Data property.

GetNextPacket returns the number of records added to Data. If the return value is 0, the client application has already received all available records from the application server.

Warning: If the client dataset uses a stateless application server, you must use a BeforeGetRecords event handler to ensure that the data packet returns the correct set of records.

TClientDataSet::FetchDetails

Retrieves nested detail datasets from the application server.

void __fastcall FetchDetails(void);

Description

Call FetchDetails to retrieve nested detail sets from an application server when this information is not provided automatically. Nested details are automatically included in data packets unless the provider on the application server includes poFetchDetailsOnDemand in its Options property. FetchDetails updates the current record to include the missing detail data sets.

There is no need to call FetchDetails if the provider automatically includes nested detail sets or if the client dataset’s FetchOnDemand property is true.

TBaseProvider::Options

Image
Influences what is included in data packets and how the information in data packets is used.

__property TProviderOptions Options = {read=FProviderOptions, write
=FProviderOptions, default=0};

Description

Set Options to customize how the provider communicates with client datasets. Options is a set that specifies

Whether nested detail sets and BLOB data are included in data packets or fetched separately.
Whether data packets include field component properties such as formats, display names, and maximum & minimum values.
Whether data packets are provided on a read-only basis, and whether specific types of changes (insertions, edits, or deletions) are disabled.
Whether changes to master table fields should cause corresponding updates to detail tables.

Whether a single client update can affect multiple server records.
Whether the clients records are refreshed when it applies updates.
Whether the client can send SQL statements that override the provider’s dataset.

Note: Not all options ar…

TClientDataSet::FetchBlobs

Retrieves BLOB field values from the application server.

void __fastcall FetchBlobs(void);

Description

Call FetchBlobs to retrieve BLOB field values from an application server when this information is not provided automatically. BLOB field values are automatically included in data packets unless the provider on the application server includes poFetchBlobsOnDemand in its Options property.

There is no need to call FetchBlobs if the provider automatically includes BLOB data or if the client dataset’s FetchOnDemand property is true.

cdecl, _cdecl, __cdecl

Category

Modifiers, C++Builder keyword extensions

Syntax

cdecl ;

_cdecl ;

__cdecl ;

Description

Use a cdecl, _cdecl, or __cdecl modifier to declare a variable or a function using the C-style naming conventions (case-sensitive, with a leading underscore appended). When you use cdecl, _cdecl, or __cdecl in front of a function, it affects how the parameters are passed (parameters are pushed right to left, and the caller cleans up the stack). The __cdecl modifier overrides the compiler directives and IDE options.

The cdecl, _cdecl, and __cdecl keywords are specific to C++Builder.

Linkage

Image
An executable program is usually created by compiling several independent translation units, then linking the resulting object files with preexisting libraries. A problem arises when the same identifier is declared in different scopes (for example, in different files), or declared more than once in the same scope. Linkage is the process that allows each instance of an identifier to be associated correctly with one particular object or function. All identifiers have one of three linkage attributes, closely related to their scope: external linkage, internal linkage, or no linkage. These attributes are determined by the placement and format of your declarations, together with the explicit (or implicit by default) use of the storage class specifier static or extern.

Each instance of a particular identifier with external linkage represents the same object or function throughout the entire set of files and libraries making up the program. Each instance of a particular identifier with inter…

OleVariant

OleVariant is a C++Builder implementation of the Object Pascal intrinsic type OleVariant.

Header

sysvari.h

Description

OleVariant is a special descendant of the Variant class that is used to represent COM interfaces or data that is passed over a COM interface. OleVariant inherits from Variant as a protected class so that it can prevent operations on AnsiString objects, which are not compatible with COM.

The syntax for using OleVariant is the same as that for using the Variant class. Like the Variant class, OleVariant has the following characteristics:

OleVariants can contain integer values, real values, string values, boolean values, date-and-time values, and Automation objects. In addition, OleVariants can contain arrays of varying size and dimension with elements of any of these types.
The special OleVariant value Unassigned is used to indicate that a OleVariant has not yet been assigned a value, and the special OleVariant value Null is used to indicate unknown or missing data.
A OleVaria…

TClientDataSet::AppendData

Adds a newly fetched packet of records to those already stored in the client dataset.

void __fastcall AppendData(const System::OleVariant &Data, bool HitEOF);

Description

Use AppendData to add a newly fetched packet of records from the server application to the client dataset. Data indicates the packet of records to add. HitEOF indicates whether or not the application server encountered the end of the dataset when it fetched the records from the database server.

Most applications call GetNextPacket instead to fetch a packet of records and automatically add them to those already available. Use AppendData when fetching data packets directly from the application server rather than letting the client dataset fetch data.

MIDAS technology

1.Understanding MIDAS technology
MIDAS requires MIDAS.DLL, which is used by both client and server applications to manage datasets stored as data packets. Building MIDAS applications may also require the SQL explorer to help in database administration and to import server constraints into the Data Dictionary so that they can be checked at any level of the multi-tiered application.
NB:You must purchase server licenses for deploying your MIDAS applications.

Component and there Description
remote data modules-Specialized data modules that work with a COM Automation server to give client applications access to any providers they contain. Used on the application server.

provider component -A data broker that provides data by creating data packets and resolves client updates. Used on the application server.

client dataset component-A specialized dataset that uses MIDAS.DLL to manage data stored in data packets.
connection components-A family of components that locate the server, form connections, …

Advantages of the multi-tiered database model

The multi-tiered database model breaks a database application into logical pieces. The client application can focus on data display and user interactions. Ideally, it knows nothing about how the data is stored or maintained. The application server (middle tier) coordinates and processes requests and updates from multiple clients. It handles all the details of defining datasets and interacting with the remote database server.
The advantages of this multi-tiered model include the following:

Encapsulation of business logic in a shared middle tier. Different client applications all access the same middle tier. This allows you to avoid the redundancy (and maintenance cost) of duplicating your business rules for each separate client application.

Thin client applications. Your client applications can be written to make a small footprint by delegating more of the processing to middle tiers. Not only are client applications smaller, but they are easier to deploy because they don’t need to worry …

MIDAS Program

Distributing database applications
C++Builder provides support for creating distributed database applications using the MIDAS technology. This powerful technology includes a coordinated set of components that allow you to build a wide variety of multi-tiered database applications. Distributed database applications can be built on a variety of communications protocols, including DCOM, TCP/IP, and OLEnterprise


Creating multi-tiered applications.
A multi-tiered client/server application is partitioned into logical units which run in conjunction on separate machines. Multi-tiered applications share data and communicate with one another over a local-area network or even over the Internet. They provide many benefits, such as centralized business logic and thin client applications.

In its simplest form, sometimes called the “three-tiered model,” a multi-tiered application is partitioned into thirds:
-Client application: provides a user interface on the user’s machine.
-Application server: resides …

__msreturn

__msreturn
Category

Modifiers, C++Builder keyword extensions

Syntax
__msreturn

Description
This calling convention is used for Microsoft compatible __fastcall calling convention return values. Structures with a size that is greater than 4 bytes and less than 9 bytes, and having at least one of its members sized 4 bytes or larger, are returned in EAX/EDX.
Calling convention mangling compatibility option
(Command-line switch: -VC)
When this option is set, the compiler disables the distinction of function names where the only possible difference is incompatible code generation options. For example, with this option set, the linker will not detect if a call is made to a _ _fastcall member function with the cdecl calling convention.
This option is provided for backward compatibility only; it lets you link old library files that you cannot recompile.

Default = OFF

__msfastcall

__msfastcall
Category
Modifiers, C++Builder keyword extensions

Syntax
__msfastcall

Description
This calling convention emulates the Microsoft implementation of the fastcall calling convertion. The first two DWORD or smaller arguments are passed in ECX and EDX registers, all other arguments are passed from right to left. The called function is responsible for removing these arguments from the stack.

_export, __export

Category

Modifiers, C++Builder keyword extensions

Form 1
class _export

Form 2
return_type _export

Form 3
data_type _export

Description
These modifiers are used to export classes, functions, and data.
The linker enters functions flagged with _export or __export into an export table for the module.
Using _export or __export eliminates the need for an EXPORTS section in your module definition file.
Functions that are not modified with _export or __export receive abbreviated prolog and epilog code, resulting in a smaller object file and slightly faster execution.

NB:If you use _export or __export to export a function, that function will be exported by name rather than by ordinal (ordinal is usually more efficient).
If you want to change various attributes from the default, you'll need a module definition file.

pascal, _pascal, __pascal

Category
Modifiers, C++Builder keyword extensions

Syntax
pascal ;
_pascal ;
__pascal ;

Description
Use the pascal, _pascal, and __pascal keywords to declare a variable or a function using a Pascal-style naming convention (the name is in uppercase).

In addition, pascal declares Pascal-style parameter-passing conventions when applied to a function header (parameters pushed left ot right; the called function cleans up the stack).
In C++ programs, functions declared with the pascal modifer will still be mangled.

cdecl, _cdecl, __cdecl

Category

Modifiers, C++Builder keyword extensions
Syntax

cdecl ;

_cdecl ;

__cdecl ;

Description
Use a cdecl, _cdecl, or __cdecl modifier to declare a variable or a function using the C-style naming conventions (case-sensitive, with a leading underscore appended). When you use cdecl, _cdecl, or __cdecl in front of a function, it affects how the parameters are passed (parameters are pushed right to left, and the caller cleans up the stack). The __cdecl modifier overrides the compiler directives and IDE options.
The cdecl, _cdecl, and __cdecl keywords are specific to C++Builder.

_fastcall, __fastcall

Category
Modifiers, C++Builder keyword extensions
Syntax
return-value _fastcall function-name(parm-list)
return-value __fastcall function-name(parm-list)


Description
Use the __fastcall modifier to declare functions that expect parameters to be passed in registers. The first three parameters are passed (from left to right) in EAX, EDX, and ECX, if they fit in the register. The registers are not used if the parameter is a floating-point or struct type.

All form class member functions must use the __fastcall convention.

The compiler treats this calling convention as a new language specifier, along the lines of _cdecl and _pascal
Functions declared using _cdecl or _pascal cannot also have the _fastcall modifiers because they use the stack to pass parameters. Likewise, the __fastcall modifier cannot be used together with _export

The compiler prefixes the __fastcall function name with an at-sign ("@"). This prefix applies to both unmangled C function names and to mangled C++ function names.

TClientDataSet::AppendData and TClientDataSet::BeforeGetRecords

Image
TClientDataSet::AppendData
Adds a newly fetched packet of records to those already stored in the client dataset.
void __fastcall AppendData(const System::OleVariant &Data, bool HitEOF);


Description

Use AppendData to add a newly fetched packet of records from the server application to the client dataset. Data indicates the packet of records to add. HitEOF indicates whether or not the application server encountered the end of the dataset when it fetched the records from the database server.

Most applications call GetNextPacket instead to fetch a packet of records and automatically add them to those already available. Use AppendData when fetching data packets directly from the application server rather than letting the client dataset fetch data.

TClientDataSet::BeforeGetRecords
Occurs before the client dataset fetches a data packet from the application server.

__property TRemoteEvent BeforeGetRecords = {read=FBeforeGetRecords, write=FBeforeGetRecords};

Description
Write a BeforeGetRecords…

TClientDataSet::AfterGetRecords

TClientDataSet::AfterGetRecords
Occurs after the client dataset fetches a data packet from the application server.

__property TRemoteEvent AfterGetRecords = {read=FAfterGetRecords, write=FAfterGetRecords};

Description
Write an AfterGetRecords event handler to respond to custom information returned to the client dataset from a provider’s AfterGetRecords event handler. AfterGetRecords is part of the mechanism by which a client dataset and a remote provider communicate information about data fetching. When working with a provider on a stateless application server, this mechanism allows the client dataset and the provider to communicate persistent state information.

When the client dataset fetches data from the application server, the following events occur:

1.The client dataset receives a BeforeGetRecords event, where it can encode custom information into an OleVariant that is passed to the application server as the OwnerData parameter.
2.The provider on the application server receives a Before…

TClientDataSet::GetNextPacket

TClientDataSet::GetNextPacket
Retrieves the next block of records from the application server.

int __fastcall GetNextPacket(void);

Description

Call GetNextPacket to retrieve the next sequential block of records from the application server. To specify the maximum number of records to return in a packet, set the PacketRecords property before calling GetNextPacket. A packet is appended to those records already stored in the Data property.

GetNextPacket returns the number of records added to Data. If the return value is 0, the client application has already received all available records from the application server.

Warning:If the client dataset uses a stateless application server, you must use a BeforeGetRecords event handler to ensure that the data packet returns the correct set of records.

TClientDataSet
TClientDataSet implements a database-independent dataset.
Unit

dbclient

Description
TClientDataSet encapsulates a database-independent, distributed dataset. A client dataset can be used as a
-Fully…

__thread, multithread variables

Category

C++Builder keyword extensions

Description

The keyword __thread is used in multithread programs to preserve a unique copy of global and static class variables. Each program thread maintains a private copy of a __thread variable for each thread.

The syntax is Type __thread variable__name. For example

int __thread x;

declares an integer type variable that will be global but private to each thread in the program in which the statement occurs.

Using thread-local variables
The thread function and any of the routines it calls have their own local variables, just like any other C++ routines. These routines also can access any global variables. In fact, global variables provide a powerful mechanism for communicating between threads.
Sometimes, however, you may want to use variables that are global to all the routines running in your thread, but not shared with other instances of the same thread class. You can do this by declaring thread-local variables. Make a variable thread-local by adding …

Creating and using a client dataset

TClientDataSet is a dataset component designed to work without the connectivity support of the Borland Database Engine (BDE) or ActiveX Data Objects (ADO). Instead, it uses MIDAS.DLL, which is much smaller and simpler to install and configure. You don’t use database or ADO connection components with client datasets, because there is no database connection.
Client datasets provide all the data access, editing, navigation, data constraint, and filtering support introduced by TDataSet. However, the application that uses a client dataset must provide the mechanism by which the client dataset reads data and writes updates. Client datasets provide for this in one of the following ways:

Reading from and writing to a flat file accessed directly from a client dataset component. This is the mechanism used by flat-file database applications.
-Reading from another dataset. Client datasets provide a variety of mechanisms for copying data from other datasets. These are described in Copying data from…