Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO Table and locate

Posted on 2010-09-12
7
Medium Priority
?
737 Views
Last Modified: 2012-05-10
I have the following problem. I am getting data from my serial port and I am adding it into a Access table but as the data comes in I use the locate function to lookup the customer ID to display it in a label but the problem is when I want to add/edit a record on that table it is opened and closed by the locate function. Is there maybe a work around this?
0
Comment
Question by:DigitalNam
  • 3
  • 3
7 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 33657319
Calling Locate does not close an ADO Table or any other dataset, you have some other action that is closing your tables.

What dou you do immediately after you call Locate?
0
 
LVL 1

Author Comment

by:DigitalNam
ID: 33657343
The closing isn't the problem. While adding a new client to the database the data on the input form shows the current record that is shown with the locate function. the data from the serial port is received every 1 second so while you are entering new information it jumps back to the customer that is being located.
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 33657541
Thats the default behaviour of the dataset, when a new record is inserted, the dataset sets it as the current record, so it jumps to that record.

Create a record holder for your edits, once your are done adding or editing the record, apply the changes to the live dataset
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:DigitalNam
ID: 33657576
please explain record holder.
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 33657633
type
  PDataRecord = ^TDataRecord
  TDataRecord = record
    ID: Integer;
    FirstName: string;
   //Other fields
  end;

procedure UpdateDataset(ADataset: TDataset; PData: PDataRecord; AUpdateKind: TUpdateKind);
begin
  case AUpdateKind of
    ukModify:
    begin
      if ADataset.Locate('KeyField', 'KeyValue', []) then
      begin
        ADataset.Edit;
        ADataset.FieldByName(FirstName).AsString := PData.FirstName;
        ...
        ADataset.Post;
      end;
    end;
    ukInsert:
    begin
      ADataset.Append;
      ADataset.FieldByName(FirstName).AsString := PData.FirstName;
      ...
      ADataset.Post;
    end;
  end;
end;

When you call your edit form, pass in the Record instead of the live dataset
0
 
LVL 1

Expert Comment

by:josephsprei
ID: 33659129
If I understand correctly, your problem is, that while entering data, the table jumps away from the data you are entering, because it is inserting the data that is coming from your serial port.
If that is the case, I would suggest creating two AdoDatasets pointing to the same table, one for collecting the data from the serial port, the other for the user browse.
This way it will not have to jump back to the record the that is currently being viewed, because it will not jump away in first place......
0
 
LVL 1

Author Closing Comment

by:DigitalNam
ID: 33669742
thank you.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question