做软键盘的时候,下面是一个action事件,每个按扭的action被赋值这个事件,报错为:Invaled class typecast而且我更改SpeedButton的caption属性后,还是显示为Action里的captionprocedure TFrmLogin.AddKeyExecute(Sender: TObject);
begin
  if uid.Focused then
    uid.Text := uid.Text + (Sender as TSpeedButton).Caption;
  if pwd.Focused then
    pwd.Text := pwd.Text + (Sender as TSpeedButton).Caption;
end;

解决方案 »

  1.   

    procedure TFrmLogin.AddKeyExecute(Sender: TObject);    
                //这里的Sender传近来的应该是TAction
    begin
      if uid.Focused then
        uid.Text := uid.Text + (Sender as TAction).Caption;   //这样试试!
      if pwd.Focused then
        pwd.Text := pwd.Text + (Sender as TAction).Caption;
    end;还有你设置了TSpeedButton之后,再去设置Action,他会用Action对应的一些相关属性来更改
    TSpeedButton的
      

  2.   

    楼上的,改了TButton的Caption后,其相关联的TAction的Caption并不会改变
      

  3.   

    好象改了TAction.Caption之后,TSpeedButton会改变,但是反之则不会!
      

  4.   

    呵呵,问题已经解决啦,把action赋给SpeedButton的onClick事件就可以了....郁闷不哇!~~~
      

  5.   

    (Sender as TSpeedButton) 这样是强制类型转换之前错,是因为 事件不是从TSpeedButton 触发,即Sender不能强制类型转换转换为TSpeedButton而将action赋给SpeedButton的onClick事件,即可以了一般来说,在转换之前,可以判断一下calss type,进行容错