你在form的oncloerquery里面写代码,任意处理。
procedure TForm1.FormCloseQuery
begin
end;