请高手看一下这一段程序: 
  name1,cz1都为椼string;   
  name1:=table6.FieldValues['11']; 
    while table6.Eof=false do 
    begin 
      if dyxm=name1 then 
      begin 
      table7.Open; 
      table7.Append; 
      table7.FieldValues['日期']:=table6.FieldValues['日期']; 
      table7.FieldValues['姓名']:=table6.FieldValues['姓名']; 
      table7.Post; 
      table7.Refresh; 
      end; 
      table6.Next; 
      name1:=table6.FieldValues['11']; 
      cz1:=table6.FieldValues['日期']; 
      if cz1>edit3.Text then break; 
    end; 
这只是其中的一段程序,在我和程序中要调用到三次这段程序,但是在每一次用到时没有错,而在第二次用到时在“cz1:=table6.FieldValues['日期'];”出现了错误:Invalid variant type Concersion 无效的变量类型转换。 
  请问应如何写才会不出现这个错误。谢谢了!!!!

解决方案 »

  1.   

    日期数据要用FORMAT转换成STRING的
      

  2.   

    table7.Fieldbyname('日期').asstring:=table6.Fieldbyname('日期').asstring; 
      

  3.   

    table6.FieldValues['11'] 
    ->
    table6.FieldByName('11').AsString 如果table6.FieldValues['11'] 可能为空的话,肯定会出问题的;
    建议取值时用下面这种方式;
      

  4.   

    另外,还有几点建议:
    1、
      while table6.Eof=false do 
      =》
      while not table6.eof do2、
      if dyxm=name1 then 
      =》
      if UpperCase(dyxm) = UpperCase(name1) then3、
      table7.FieldValues['日期']:=table6.FieldValues['日期']; 
      =》
      table7.FieldValues['日期'] := table6.FieldByName('日期').AsVariant;