Page 1 of 1

BeforeDelete

Posted: Mon 16 Jul 2007 09:29
by mierlp
hi,

I have 2 tables :
- city (with fields cityID(int), cityName)
- user (with lastname, firstname and cityID(int))

when i add a user i use the table city for selecting a city.
Now i must prevent that customers can deleted city names from
the table CITY when this id exists in table USER.

So i used this code at the table CITY BEFOREDELETE event :


dmTables.qry_user.IndexFieldNames:='user_cityID';
if dmTables.qry_user.FindKey([dmTables.qry_city.FieldByName('city_id').asString]) then begin
Application.MessageBox('Record can't be deleted.', 'Warning', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Abort;
end;
dmTables.qry_user.IndexFieldNames:='user_lastname';


The result is that there's NO warning and the record
will be deleted in the table CITY.

What's wrong with this code/solutions...are there better solutions.
Using MyISAM tables.

Greetz Peter

Posted: Mon 16 Jul 2007 14:35
by Antaeus
Please check once again whether the BeforeDelete event handler is assigned correctly.
Place the breakpoint within this event handler, and check whether the execution will stop when you try to delete a record. Trace program execution by F7.