为什么这个程序不能正常工作?

时间:2016-12-23 09:08:49

标签: delphi devexpress

我按下按钮点击:

procedure TMain_Form.cxButton1Click(Sender: TObject);
begin
  if (trim(cxmemo1.lines.Text) = '')  then  begin
    showmessage('Memo is empty');
    abort;
  end else begin
    if cxBarEditItem1.EditValue = False then begin   //this does not execute
      showmessage('No user');
      abort;
    end else begin
      DataModule.MYQUERY.Close;
      DataModule.MYQUERY.SQL.Clear;
      DataModule.UniTransaction1.AddConnection(DataModule.UniConnection1);
      DataModule.UniTransaction1.StartTransaction;
      DataModule.MYQUERY.SQL.Add('INSERT INTO MYTABLE (FIELD1,FIELD2,FIELD3,FIELD4,FIELD5) VALUES(:p1,:p2,:p3,0,:p4);');
      DataModule.MYQUERY.Params.ParamByName('p1').asDate :=cxDateNavigator1.date;
      DataModule.MYQUERY.Params.ParamByName('p2').asDateTime := Now;
      DataModule.MYQUERY.Params.ParamByName('p3').Value :=cxMemo1.Lines.Text ;
      if cxBarEditItem1.EditValue = True then
        DataModule.MYQUERY.Params.ParamByName('p4').asString := dxStatusbar1.Panels[1].Text
      else
        DataModule.MYQUERY.Params.ParamByName('p4').asString := cxLookUpComboBox1.Text;
      DataModule.MYQUERY.Prepare;
      DataModule.MYQUERY.ExecSQL;
      try
        DataModule.UniTransaction1.Commit;
      except on E:exception do
        begin
          DataModule.UniTransaction1.Rollback;
          raise exception.create('Error: '+e.message);
        end;
      end;
      DataModule.UniStoredProc2.Refresh;
      cxMemo1.Lines.Clear;
      cxMemo1.SetFocus;
      cxLabel2.Caption:='';
      AdvSmoothWin8Marquee1.Enabled:=False;
      AdvSmoothWin8Marquee1.Visible:=False;
      cxLookUpComboBox1.Clear;
    end;
  end;
end;

第一部分,它检查备忘录是否为空,执行OK。 如果为空,则中止该过程。

然而,第二个条件(它应该检查复选框的状态)不会。它只是激发查询。

在某个地方,我可能搞砸了if then声明,但不知道在哪里。请帮忙......

1 个答案:

答案 0 :(得分:-4)

你可以这样开始:

procedure TMain_Form.cxButton1Click(Sender: TObject);
begin
  if (trim(cxmemo1.lines.Text) = '')  then 
  begin
    showmessage('Memo is empty');
    abort; //you can also use exit instead of abort
  end 
  else 
    if cxLookUpComboBox1.Text = '' then 
    begin
      showmessage('user is empty');
      abort;  //you can also use exit instead of abort
    end  
  else  
  begin
    ...

删除行:

if cxBarEditItem1.EditValue = True then
  DataModule.MYQUERY.Params.ParamByName('p4').asString := dxStatusbar1.Panels[1].Text
else
  DataModule.MYQUERY.Params.ParamByName('p4').asString := cxLookUpComboBox1.Text;

然后做:

procedure TMain_Form.cxBarEditItem1PropertiesChange(Sender: TObject);
begin
  if cxBarEditItem1.EditValue = True then  
  begin
    cxLookUpComboBox1.Text := dxStatusbar1.Panels[1].Text;
    cxLookUpComboBox1.Enabled:=False; //just in case value does not get changed
  end 
  else 
  begin
    cxLookUpComboBox1.Text :='';
    cxLookUpComboBox1.Enabled:=True;
  end;
end;

只是我的2美分......

编辑:删除了不需要的application.processmessages。

编辑:对不起,第一部分错了(剪切和粘贴快点)。纠正。

相关问题