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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
kretzschmarConnect With a Mentor Commented:
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.