我想把ComboBox1里输入的内容存到数据表Comp_Pipe_Name的Pipe_Name字段中,存之前想判断一个数据库表里是否里已经存过这个记录,如 没存过再存入,判断过程我是在ComboBox1的OnExit事件中触发这个事件:代码如下:
procedure TInputDlg.ComboBox1Exit(Sender: TObject);
begin
with DataModule1.ADOquery1 do
begin
  close;
  sql.clear;
  sql.add('select * from Comp_Pipe_Name where field =:Pipe_Name');
  parameters.ParamByName('Pipe_Name').value:=combobox1.text;
  open;
end;
if DataModule1.ADOquery1.recordcount>0 then
begin
  Application.messagebox('已经输入过此数据','提示',0+mb_iconquestion)  ;
  combobox1.setfocus;
  combobox1.text:='';
end;
end;
----------------------------------------------------------------------------------------
下面我想在主程序里调用这个函数(祝程序就是用来往数据库的表里存数据的),主程序是这样的:
begin
    if InputDlg.ShowModal = mrok then
    begin
      Close;
      SQL.Clear;
      with DataModule1.ADOQuery1 do
      begin
        if not TInputDlg.ComboBox1Exit(string,Tobject) then-------------我感觉引用这好像不太对
          SQL.Add('Insert Comp_Pipe_Name(Pipe_Name) Values(:a)');
          Parameters.ParamByName('a').value:= InputDlg.ComboBox1.Text;
          ExecSQL;
      end;
    end;
end;
-----------------------------------------------------------
结果编译不过去啊,[Error] digitizer_input.pas(69): Declaration expected but end of file found
请问高手是哪里的毛病呢,调用的不对,还是有逻辑错误。

解决方案 »

  1.   

    function TInputDlg.ValidCheck: boolean; 
    begin
      Result := True; 
    with DataModule1.ADOquery1 do 
    begin 
      close; 
      sql.clear; 
      sql.add('select * from Comp_Pipe_Name where field =:Pipe_Name'); 
      parameters.ParamByName('Pipe_Name').value:=combobox1.text; 
      open; 
    end; 
    if DataModule1.ADOquery1.recordcount>0 then 
    begin 
      Application.messagebox('已经输入过此数据','提示',0+mb_iconquestion)  ; 
      combobox1.setfocus; 
      combobox1.text:=''; 
      Result := False;
    end; 
    end; 
    ////////////////////////////////////////////
    begin 
        if InputDlg.ShowModal = mrok then 
        begin 
          Close; 
          SQL.Clear; 
          with DataModule1.ADOQuery1 do 
          begin 
            if InputDlg.ValidCheck then
              SQL.Add('Insert Comp_Pipe_Name(Pipe_Name) Values(:a)'); 
              Parameters.ParamByName('a').value:= InputDlg.ComboBox1.Text; 
              ExecSQL; 
          end; 
        end; 
    end; 
      

  2.   

    谢谢您!请教个问题,你加了2句Result := True; Result := False;是什么意思呢?
    我先加了Result := True,运行提示:[Error] digitizer_input.pas(40): Undeclared identifier: 'Result',请问'Result'怎么定义呢?
    当我不加Result := True时,运行提示:[Error] digitizer_main.pas(292): Undeclared identifier: 'SQL',SQL怎么会没定义呢?
    谢谢!!!!!!!
      

  3.   

    Result是function的返回定义。
    function TInputDlg.ValidCheck: boolean; 在这个函数中,result:=true跟:validcheck:=true是一样的。
    -------------
      

  4.   

    您好,我把result定义后这个错误就消失了,但是出现了别的错误,就是在主程序里调用函数哪里:代码是倒数第七行:
    if InputDlg.ValidCheck then
    错误总是说:[Error] digitizer_main.pas(295): Not enough actual parameters;
    并且倒数第10行说:[Error] digitizer_main.pas(292): Undeclared identifier: 'SQL';怎么会没定义呢
    希望高手帮解答下