Searching records in edit state

I want to insert new record into TTable pointing to local FoxPro table. Before the new record is actually posted (TTable itself is in dsEdit or dsInsert state) I need to know if table already contains record with some of the fields identical to my new record ones. If this is not truth, changes can be posted, otherwise cancelled.
Can you help me how to implement this feature?
LVL 2
ivobauerAsked:
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.

rwilson032697Commented:
One way is to use a separate TTable pointing to the same table and do the search with the second table...

Cheers,

Raymond.
0
kretzschmarCommented:
hi ivobauer,

just create a new table-instance and try a locate for the given fields.
returns locate true then a record exists and the table-instance pointed to it, if false the record does not exist.

sample follows ;-)

meikl
0
kretzschmarCommented:
hi again,

the sample

procedure TForm1.Button1Click(Sender: TObject);
var t : TTable;
begin
  if table1.State = dsInsert then
  begin
    t := TTable.Create(Self);
    try
      t.DatabaseName := Table1.DatabaseName;
      t.TableName := Table1.TableName;
      t.open;
      if t.Locate('Name',table1.FieldByName('Name').Value,[]) then
      begin
        Showmessage('Record exists! Insert will be canceled and'+
                    ' positioned to existing record');
        table1.Cancel;
        Table1.GotoCurrent(t);
      end;
    finally
      t.free;
    end;
  end;
end;

meikl
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
JaymolCommented:
You could, alternatively, set the field in question (the field you locate with) to be unique.  That way, you can handle the TTable.Post error message.  (Saves coding a seperate locate procedure.)

Hope this helps,

John.
0
ivobauerAuthor Commented:
I guess I'll Accept your answer. Many thanks.
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.