使用easygrid1进行第一次录入,然后保存
使用easygrid2进行第二次录入
使用easygrid3读取第一次录入的数据怎样判断第二次录入和第一次录入的数据不同,如 If
 EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText <> EasyGrid3.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText
 Then
  begin
  MessageBeep(0);
  EasyGrid2.Colors[EasyGrid2.Col,EasyGrid2.Row]:=clred;
  end;还有怎样限制录入字段的长度为3,只能输入数字和 ‘-’符号

解决方案 »

  1.   

    只能输入数字和 ‘-’符号:
    if not (key in['0'..'9',#109]) then 报错限制录入字段的长度为3:
    if length(EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText)<>3 then 报错 ,在Uses中加入StrUtils至于判断第一次和第二次输入的不同,还是用一个全局变量来表示easygrid1中输入的数据吧。在EasyGrid1的保存事件中写入:
    var
      data1:string;在EasyGrid1的保存事件中写入:
      data1:=EasyGrid1.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText;然后EasyGrid3读取时,比较EasyGrid2和data1变量的值,如果需要比较输入时间的先后,可以用两个Tdatatime型的变量,在EasyGrid保存时,分别记录两者的保存时间,通过时间对比就知道谁输入的次序先后了
      

  2.   

    先用EasyGrid3读取出第一次录入的数据
    然后在EasyGrid2里每输入一个单元格就判断一下和EasyGrid3里的是否一样,还有if not (key in['0'..'9',#109]) then 报错 
     
    if length(EasyGrid2.Cells[EasyGrid2.Col,EasyGrid2.Row].ForeText) <>3 then 报错
     
    在哪里判断呢
      

  3.   

    你是怎么输入数据的?在保存按钮的onclick事件中输入吗?还是直接在EasyGrid中手动输入?如果是在按钮点击事件中输入,那么判断也在这中间,如果是在EasyGrid中手动输入,就在EasyGrid的OnKeyPress事件中输入判断语句
      

  4.   

    怎样让easygrid1的数据长度为3时自动跳到下一单元格呢
    procedure TForm1.EasyGrid1KeyPress(Sender: TObject; var Key: Char);
    label
    nexttab;
    begin
    if not (key in['0'..'9',#109,#32]) then
    begin
    key:=#0;
    MessageBeep(0);
    end;
    if (key=#32) or (length(EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText) = 3) then
    begin
    key:=#0;
    nexttab:
    if (EasyGrid1.Col < EasyGrid1.ColCount - 1) then
     begin
     EasyGrid1.Col:=EasyGrid1.Col+1;
     end
    else
    begin
    if EasyGrid1.Row>=EasyGrid1.RowCount-1 then
    EasyGrid1.RowCount:=EasyGrid1.rowCount+1;
    EasyGrid1.Row:=EasyGrid1.Row+1;
    EasyGrid1.Col:=0;
    goto nexttab;
    end;
    end;
    end;空格键能自动跳到下一单元格,但是数据长度为3时却没有反应
      

  5.   

    EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row]  必须指定是哪一个单元格,比如EasyGrid1.Cells[2,2]如果需要在程序中动态指定,那在单元格获得输入焦点时先判断出当前是在哪个单元格,直接在这段keypress段中指定也可以
      

  6.   

    第一个问题已解决
    怎样让easygrid1的数据长度为3时自动跳到下一单元格呢
      

  7.   

    唉,都跟你说了,EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row] 这样的写法要改,改完了,也就解决数据长度为3时自动跳到下一单元格的问题你写的 length(EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText) = 3 只是判断表格中右下角最后一个单元格的长度判断,这肯定是不对,必须判断当前输入焦点的单元格,所以要重新写,例如 length(EasyGrid1.Cells[2,2].ForeText) = 3 ,程序中需要动态指定,所以[2,2]里面的数值要你在程序中动态判断
      

  8.   

    Cells[EasyGrid1.Col,EasyGrid1.Row] 就是当前输入焦点的单元格,
    只是光标在输入框里时 用edit1.text := Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText显示不出来当前选择的单元格里的数据
    不显示光标时,用edit1.text := Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText就可以显示出当前选择的单元格里的数据
      

  9.   

    不好意思,表述错误,你把length(EasyGrid1.Cells[2,2].ForeText) = 3 中的3改成2就可以了,因为是onkeypress事件,你在按最后一位数字的时候,就已经先判断之前的输入长度了,而之前的输入长度是2,所以......不好意思,前面理解错误了
      

  10.   

    还是不可以,可能easygrid的单元格在编辑状态下不能提取里面的数据
      

  11.   

    设定一个全局变量s, s:integer;然后在EasyGrid1KeyPress事件中写入:if not (key in['0'..'9',#109,#32]) then 
    begin 
      key:=#0; s:=0;
      MessageBeep(0); 
    end else s:=1;最后给EasyGrid1添加一个onkeyup事件,把你所需的代码写在onkeyup事件中,如:procedure TForm1.StringGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    begin
      if s=1 then
      begin
        if length(EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText) = 3  then
        edit1.Text:=EasyGrid1.Cells[EasyGrid1.Col,EasyGrid1.Row].ForeText;
      end;
    end;你再试一下,我这边没有EasyGrid的控件,用stringgrid测试通过
      

  12.   

    多谢了,我现在不用easygrid,改用string了