Hi Corina,
Corinna John wrote:
when I place a TQuery component, on a form, it consumes memory until the application quits.
The amount of memory that your query will consume is directly related to the amount of data which you are retrieving from the database, and as such cannot be helped. What you could do is look at how many fields are being returned and reducing that amount to only those fields that you need.
Corinna John wrote:
When I create/free the TQuery everytime I actually need it, the construction/destruction consumes time.
I've found that creating/destroying the components dynamically isn't time consuming. What will take time is establishing the connection to the database and the subsequent retrieval of the data from the query. Since I hardly every use data-aware controls, most of the time I dynamically load the data to the screen(s) by creating a data controller which will provide the functionality for retrieving/updating the data from the database. Ideally this controller will have some database connection object within it, and a query/command object to query the database with. These data objects should be created and destroyed in the controller's constructor/destructor respectively. Then, by using events, you can perform some kind of action on the resulting query which you executed. So a controller would look something like this (I see you are using the TQuery component, and although I am using ADO, the theory is still basically the same):
unit uDataController;
interface
uses
ADODB;
type
// my uber-super user defined event :P
TOnRetrieveData = procedure (ASender : TObject; AResultData : TADOQuery) of object;
TDataController = class(object)
private
FOnRetrieveData : TOnRetrieveData;
FDBConnection : TADOConnection;
FADOCommand : TADOCommand;
procedure InitialiseDBStuff;
public
constructor Create(AOnRetrieveDataEvent : TOnRetrieveData);
procedure ExecuteSQL(const ASQLString : string);
end;
implementation
constructor TDataController.Create(AOnRetrieveDataEvent : TOnRetrieveData);
begin
inherited Create;
InitialiseDBStuff;
// Assign the event...
FOnRetrieveData := AOnRetrieveDataEvent;
end;
procedure TDataController.InitialiseDBStuff;
begin
// Initialise the connection and command components
FDBConnection := TADOConnection.Create(nil);
FADOCommand := TADOCommand