Accessing DataSet records

I'm trying to read all fields and records in a dataset to update some ohter objects with data from the dataset. Is there a simple way to read all fields for all records without changing the user's current (acitve) record? - Also which event would you suggest I use to trigger saving of data?
LVL 1
runebjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

victor_christovCommented:
You can use additional TQuery with SQL statement 'SELECT * FORM ....', or you can use BookMark.

Second part of your question is not clear enough for me. Pls send more details.

Regards, Victor
0
MotazCommented:
What did you want to do ?

You may use Calculated fields, did you know how to use it?

Motaz
0
victor_christovCommented:
Sorry ... 'SELECT * FROM ...'
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

kretzschmarCommented:
hi,

victor said the both possibilities.
i would prefer the query solution, because its mostly faster than an iterating through the table.

meikl
0
MotazCommented:
If you want to use calculated fields see this example:

Suppose that you have two integer fields A and B, and you want a summation of A+B into new calculated field (C) you can do this:

- Double click in Table1 object, then right click mouse button, then click on add all fields.

- Right click again Table1 then click New field, name it C, Integer type, the name will be Table1C, of type calculated

- At OnCalcFields event of Table one write this code:

  Table1C.AsInteger:= Table1A.AsInteger+ Table1B.AsInteger;

Motaz
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DonBartholomewCommented:
I don't think there is another way if you want to operate on the same dataset. But you can assign the dataset.ActiveRecord prop to a var, then browse through the dataset, and then set the ActiveRecord prop back to the var.

<Lastindex: integer>
Lastindex := dataset.ActiveRecord;
Dataset.First;
while not dataset.Eof do
begin
<Assign field values to other object>
Dataset.Next;
end;
Dataset.ActiveRecord := Lastindex;

But I'm not sure I understand your question properly. What other objects do you have to update? Why not do it the obvious way: use databound controls for this purpose?
Anyway, events for saving: afterscroll event of dataset for individual records.

Ciao
0
yk030299Commented:
yeah, updating on the same dataset may cause dead-locking.
0
runebjAuthor Commented:
I guess I was pretty unclear about this - sorry for that...

I have a rather complex structure of non visual objects that exists in memory only. I'm using a TdxMemData component to "fake" a database so that I can update some of the information from databound controls. My problem is catching the changes and storing them back to the objects in memory.

I have now used Motaz' idea of catching all changes in the OnCalcFields event and it seems to work. But, I would still like to know if it is possible to access the data in memory directly.
0
MotazCommented:
>But, I would still like to know if it is possible to access the data in memory directly

If I can understand you, you can access all records and fields without using any database controls such as:

var
  i: Integer;
begin
  Table1.First;
  while not Table1.Eof do
  begin
    for i:= 0 to Table1.Fields.Count - 1 do
      Memo1.Lines.Add(Table1.Fields[i].AsString);
    Memo1.Lines.Add('--------------');
    Table1.Next;
  end; // while
end;

this will display all records in a memo1

you do not need DataSoure nor DataControl only you need a TTable

Motaz
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.