BeforeDelete
Posted: Mon 16 Jul 2007 09:29
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
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