可以在数据控件的
BeforePost事件中写入代码
if 字段=null then
Begin
Application.MessageBox('字段不能为空','错误!',0);
Abort;
end;
BeforePost事件中写入代码
if 字段=null then
Begin
Application.MessageBox('字段不能为空','错误!',0);
Abort;
end;
解决方案 »
- Delphi 分割文件
- exe+bpl 的程序,如何将delphi和控件包合并到一个bpl中
- 如何将Delphi的应用程序放入HTML文件中 ,并可以利用IE可浏览
- 求《Delphi+SQL Server数据库应用系统开发与实例》
- 为什么我添加的Outlookbar控件不能用!
- COM+应用服务报错“新事务不能登记到指定的事务处理器中”
- 请教olecontainer的问题,进者有分
- 出去找工作(Delphi的)之前做个什么程序比较好?
- --【¤ Delphi 技术提升、能力升华 讨论大会 ¤】-- 请各位高手指点迷津
- 不好意思,小问题,如何打印在image1.canvas中自定义的图形,请指点
- 你三十岁以后干什么?
- 怎样开关静音?
你只要一个myDBGrid.SelectedIndex就够了,
它表示刚刚退出的列是第几列,0:表示第一列,1:表示第二列。procedure TFSell.myDBGridColExit(Sender: TObject);
var
tmp : ST_WARECODE;
TotalNum : Integer;
FactPrice : Single;
begin
inherited;
if ((myTable.State<>dsEdit) and (myTable.State<>dsInsert)) then
exit; if myDBGrid.SelectedIndex=0 then//SelectedIndex就是第几列!!!!!!!
begin
tmp.sWareCode := myTable.FieldByName('WareCode').AsString;
if Trim(tmp.sWareCode)='' then
exit;
if not MainDataModule.GetWareInfo(tmp) then
begin
WARNING('货号:“'+tmp.sWareCode+'" 不存在');
end
else
begin
if (tmp.sBrandCode<>pData.pCurrentBrand.sBrandCode)then
begin
WARNING('货号:“'+tmp.sWareCode+'" 的品牌不是"'+pData.pCurrentBrand.sBrandName+'"');
exit;
end;
myTable.FieldByName('WareName').AsString := tmp.sWareName;
myTable.FieldByName('Price').AsFloat := tmp.fPrice;
myTable.FieldByName('FactPrice').AsFloat := tmp.fPrice*tmp.fDiscount/100;
myTable.FieldByName('CostPrice').AsFloat := tmp.fCostPrice;
end;
GetKCSL;
exit;
end; with myDataSource.DataSet do
begin
TotalNum := FieldByName('Size_XS').AsInteger
+FieldByName('Size_S').AsInteger
+FieldByName('Size_M').AsInteger
+FieldByName('Size_L').AsInteger
+FieldByName('Size_XL').AsInteger
+FieldByName('Size_XXL').AsInteger
+FieldByName('Size_Other').AsInteger;
if ((myDBGrid.SelectedIndex>=2) and (myDBGrid.SelectedIndex<=8))and((FuncClass<>tfLookAbout) and ((State=dsEdit) or (State=dsInsert))) then
begin
FieldByName('TotalNum').AsInteger := TotalNum;
try
FactPrice := FieldByName('FactPrice').AsFloat;
FieldByName('TotalFactMoney').AsFloat := StrToFloat(Format('%.3f',[TotalNum*FactPrice]));
except
end;
exit;
end;
try //防止除零!
if (myDBGrid.SelectedIndex=11)and((FuncClass<>tfLookAbout) and ((State=dsEdit) or (State=dsInsert))) then
begin//折扣
FactPrice := FieldByName('Price').AsFloat * FieldByName('Discount').AsFloat / 100;
FieldByName('FactPrice').AsFloat := StrToFloat(Format('%.3f',[FactPrice]));
FieldByName('TotalFactMoney').AsFloat := StrToFloat(Format('%.3f',[TotalNum*FactPrice]));
exit;
end; if (myDBGrid.SelectedIndex=12)and((FuncClass<>tfLookAbout) and ((State=dsEdit) or (State=dsInsert))) then
begin//实销价
FactPrice := FieldByName('FactPrice').AsFloat;
FieldByName('Discount').AsFloat := StrToFloat(Format('%.3f',[FactPrice / FieldByName('Price').AsFloat * 100]));
FieldByName('TotalFactMoney').AsFloat := StrToFloat(Format('%.3f',[TotalNum*FactPrice]));
exit;
end;
if (myDBGrid.SelectedIndex=13)and((FuncClass<>tfLookAbout) and ((State=dsEdit) or (State=dsInsert))) then
begin//实销金额
FactPrice := FieldByName('TotalFactMoney').AsFloat / TotalNum;
FieldByName('Discount').AsFloat := FactPrice / FieldByName('Price').AsFloat * 100;
FieldByName('FactPrice').AsFloat := FactPrice;
exit;
end;
except
end;
end;
end;