一.Form
(1)form 支持ESC键的属性,选择‘关闭按钮’BUTTON属性里的Cancel设置成TRUE;
(2)FormCloseQuery,是在关闭窗体之前进行的操作.可以不关闭窗体,
if (FFlag=0) then
begin
BiInBill.DelinBill(lbl3.caption);
Exit;
end;
if FFlag=1 then
begin
CanClose:=MessageBox(Handle,'数据还没有保存,确定关闭窗口吗?','系统提示',MB_YESNO or MB_ICONWARNING)=IDYES;
if CanClose then
begin
BiInBill.DelinBill(lbl3.Caption);
end;
二 combobox1控件
combobox1添加数据
cbb1.Items.Clear;
combobox1.items.add(fieldbyname('a').asstring);
combobox1.Text获取当前值。
Style设置为csDropDownList是下拉列表,我的想法是在这个状态下还可以选择文本,但不能修改。
另外,Style设置为csDropDownList不能通过combobox.text:='XX'来赋值。
三Lable 控件
lalbel 透明:transparent 透明属性
四dbgrid的使用
(1)关于删除记录操作
AdoQuery1BeforeDelete事件:加入提示‘是否删除当前记录’
例:procedure TFrm_GameDiviceClearBi.qry1BeforeDelete(DataSet: TDataSet);
begin
if MessageBox(Handle,'确实删除些记录吗?','系统提示',MB_YESNO or MB_ICONWARNING)<>IDYES then
Abort;
end;
并设置DbGrid属性中的[Option]属性中的[dbconfirmDelete]属性false;
{2}dbgrid回车事件,跳到下一列或一下行的代码
应设置:dbgrd1[KeyPress事件]
procedure TForm3.dbgrd1KeyPress(Sender: TObject; var Key: char);
begin
if key=#13 then
begin
if (ActiveControl is TDBGrid) then
begin
with TDBGrid(ActiveControl) do
if SelectedIndex<(FieldCount-1) then
selectedIndex:=SelectedIndex+1
else
if (not dbgrd1.DataSource.DataSet.Eof) and (dbgrd1.DataSource.DataSet.RecNo<>dbgrd1.DataSource.DataSet.RecordCount) then
begin
dbgrd1.selectedIndex:=0;
dbgrd1.DataSource.DataSet.Next;
end
else
begin
dbgrd1.selectedIndex:=0;
dbgrd1.DataSource.DataSet.Append;
end;
end;
end;
end;
(3)dbgrid遍历第一行记录
qry2.First;
while not qry2.Eof do
begin
sum:=sum+qry2.fieldbyname('bicount').AsInteger;
qry2.Next;
end;
(4)dbgrid插入数据,编辑数据都要调用AdoQuery.post
其中AdoQuery1BeforePost在提交到数据库之前进行的操作,便如数据的全法性,判断
例:procedure TForm3.qry2BeforePost(DataSet: TDataSet);
begin
if DataSet.FieldByName('DeviceType').AsString='' then
begin
qry2.Delete;
Abort;{取消操作}
end;
DataSet.FieldByName('bcode').Value:=2;
if DataSet.FieldByName('bicount').IsNull then
DataSet.FieldByName('bicount').Value:=0;
end;
AdoQuery1alertPost 是提交到数据后进行的操作,例如统计总数:
(5)AdoQuery的状态有时非常管用
例:AdoQuery.state
状态如下
TDataSetState = (dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey,
dsCalcFields, dsFilter, dsNewValue, dsOldValue, dsCurValue, dsBlockRead,
dsInternalCalc, dsOpening);
是进行插入数据时,能知道对DBGRID的操作的状态/.
(6)dbgrid 自动保存,在自动填加一行后,在离开DBGRID时,调用dbgrd1Exit事件 query.post
procedure TFrm_GameDiviceClearBi.dbgrd1Exit(Sender: TObject);
begin
inherited;
if qry1.State in [dsinsert,dsedit] then
qry1.Post
else
sumBi();
end;
(7)
dbgrid 追加一条记录并定位光标
dbgrd1.DataSource.DataSet.Append;
dbgrd1.SetFocus;
qry2.Fields[0].FocusControl;
dbgrid 删除一条记录
if not qry2.IsEmpty then
qry2.Delete;