Board index » delphi » Cloning a result TDataset (or TQuery)?

Cloning a result TDataset (or TQuery)?

I have developed a component, that has a prepared Query-component to
retrieve data fast from a table in a fixed format.  I use this for
history data, so the component has a function like

Load(firstTime, lastTime): TDataset
begin
 ...
  Query.SetParamByName(...
  Query.Open;
  result := Query;
end

The component uses the Query to get the data between the given times.
I return the Query as a result, so that whoever uses the component can
browse the result set as he likes.  But there are two drawbacks:

1. The query is accessible outside the component and can be freed
accidentally.

2. It is not possible to ask two result sets and use them at the same
time, because the previous result set is lost each time Load is called.

I have no idea, how I could clone the query, so that I could return a
new copy of the dataset.  This might be a bad idea anyway.  It might
be better to give your own dataset for the Load-method, which would
then fill it with the query results.  But how do I do this?  I want to
use a predefined Query, so that I can Prepare the SQL-statement.  If
I use a different Query-component every time, I lose this benefit.  Any
suggestions?

Jouni Aro
Prosys PMS Oy

 

Re:Cloning a result TDataset (or TQuery)?


To be more precise, I am interested in getting just a copy of the
result set in memory.  I don't like copying the data to a temporary
TTable, as it is written to a file.  Or have I misunderstood
something?

Of course I could copy the result set to an array, but then I get
different problems.

Re:Cloning a result TDataset (or TQuery)?


In article <y2v90nl1fyi....@zetor.clinet.fi>, Prosys PMS Oy <pro...@zetor.clinet.fi> wrote:

Quote
>To be more precise, I am interested in getting just a copy of the
>result set in memory.  I don't like copying the data to a temporary
>TTable, as it is written to a file.  Or have I misunderstood
>something?

>Of course I could copy the result set to an array, but then I get
>different problems.

In the "meta-solutions" page on my web site, there is a product called
TMemDataSet that may be exactly what you are looking for it.  The author is
Alain Brunet.

[* k...@kylecordes.com            |  For Delphi developers:  *]
[* Kyle Cordes Software Solutions |  BDE Alternatives Guide  *]
[* http://www.kylecordes.com      | MIDAS Alternatives Guide *]

Other Threads