procedure TForm1.FormCreate(Sender: TObject);
 var
  Check1: TCheckBox;
   Check2: TCheckBox;
    Check3: TCheckBox;
     Check4: TCheckBox;  begin
   check1.tag=0;
     check2.tag=1;
     check3.tag=2;      
    check4.tag=3;
   if Not (Sender is TCheckBox) then Exit;//²»ÕýÈ·µÄʼþ¾Í²»×ö´¦Àí
  Check1 := Sender as TCheckBox;
  Check2 := Sender as TCheckBox;
  Check3 := Sender as TCheckBox;
  Check4 := Sender as TCheckBox;end; procedure TForm1.dadbgrid1onmouseup(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  begin
    adotable2.Close;
    adotable2.Filter:=' kh='''+form1.DBGrid1.Fields[0].AsString+'''' ;
    adotable2.Filtered:=true;
    adotable2.Open; while not adotable2.Eof   do
   begin
       if inttostr((Sender as TCheckBox).Tag)=(form1.adotable2.fieldbyname('bkdm').asstring) then            (sender as TCheckBox).Checked:=true
      else
            (sender as TCheckBox).Checked:=false;         end;
          // form1.ADOTable2.Next;
end;这一句if inttostr((Sender as TCheckBox).Tag)=(form1.adotable2.fieldbyname('bkdm').asstring) then   提示invalid class typecast 错误,

解决方案 »

  1.   

    1、在FormCreate中,Check1、Check2、Check3、Check4没有Create,可以直接使用吗?不会报地址错误啊?
    2、在dadbgrid1onmouseup中,筛选不是adotable2.Close,adotable2.Open,而是adotable2.Filterd := False;
    adotable2.Filtered := True;
    3、在Grid的控件中 Sender as TCheckBox,然后再(Sender as TCheckBox).Checked := True,不知道你是什么意图,这样做转换也是不正确的。
      

  2.   


    while not adotable2.Eof do  
    begin  
    if inttostr((Sender as TCheckBox).Tag)=(form1.adotable2.fieldbyname('bkdm').asstring) then
       (sender as TCheckBox).Checked:=true //原因是此处转换失败
    else  
    (sender as TCheckBox).Checked:=false; 
    end; // form1.ADOTable2.Next; end;
      

  3.   

    dadbgrid1onmouseup里 鼠标触发时sender 不是TCheckBox,
    自己循环慢慢找吧
      

  4.   


    有3个checkbox 如下操作
    for i:= 0 to  3 do
     check &i .Checked:=true;
     
    check & i 怎么写啊!!            字符串 连接 变量