Performance of visual components
-
Hello, when I place a TQuery component, on a form, it consumes memory until the application quits. When I create/free the TQuery everytime I actually need it, the construction/destruction consumes time. What do you think is better for the application's performance? Do you keep the visual component in memory all the time, or do you prefer to create objects on demand?
This statement is false.
-
Hello, when I place a TQuery component, on a form, it consumes memory until the application quits. When I create/free the TQuery everytime I actually need it, the construction/destruction consumes time. What do you think is better for the application's performance? Do you keep the visual component in memory all the time, or do you prefer to create objects on demand?
This statement is false.
Hi, By default it should works properly and without consuming much memory, I use Delphi too but I never had that problem. Check if somewhere else is problem and if you figure out then notify me,ok? Regards.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hi, By default it should works properly and without consuming much memory, I use Delphi too but I never had that problem. Check if somewhere else is problem and if you figure out then notify me,ok? Regards.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
Blue_Boy wrote:
if somewhere else is problem
There is no problem at all. I only asked what people think about memory usage and performance. I made a test with - a DataModule with a TQuery and - a simple class that creates the TQuery on the fly both containing the same method. Strangley, the method ran a few milliseconds faster in the class without visual components. The DataModule with visual components worked a few milliseconds slower, though (in theory) the components involved should have been the same. That means, the way you create instances - by drag&drop or create/free - actually does matter.
This statement is false.
-
Hello, when I place a TQuery component, on a form, it consumes memory until the application quits. When I create/free the TQuery everytime I actually need it, the construction/destruction consumes time. What do you think is better for the application's performance? Do you keep the visual component in memory all the time, or do you prefer to create objects on demand?
This statement is false.
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