如果窗体有数据操作,在未保存时关闭窗体,进行一个提示。
procedure TFrmSave.FormCloseQuery(Sender: TObject; var CanClose: Boolean); //窗体关闭时提示变动的保存
begin
if ADODataSet1.State in [dsInsert, dsEdit] then
begin
if MessageBox(0, '发现未保存的数据,需要保存吗?', '', MB_YESNO +
MB_ICONQUESTION) = IDYES then
begin
SaveData;
end;
end;
end;
{保存数据}
procedure TFrmSave.SaveData;
begin
with ADODataSet1 do
begin
Edit;
FieldByName('Number').AsString := Trim(EDNumber.Text);
FieldByName('Name').AsString := Trim(EDName.Text);
FieldByName('Old').AsInteger := StrToIntDef(Trim(EdOld.Text), 0);
if CBxSex.Text = '男' then
FieldByName('Sex').AsInteger := 1
else
FieldByName('Sex').AsInteger := 0;
FieldByName('TelePhone').AsString := Trim(EdTelePhone.Text);
FieldByName('DepartMent').AsString := Trim(CBXdePartMent.Text);
FieldByName('JoinDate').AsDateTime := DTPJoinDate.Date;
Post;
end;
end;
0 条评论
沙发空缺中,还不快抢~