type
  TStaTime = class(TThread)
    Fr:Tobject;
    protected
  procedure Execute; override;
  procedure TStaTime.Execute;
  begin
    Fr:=Fr as Fr.className
   //或:Fr:=Fr as Fr.ClassType
    Fr.mothed1;
  end;
end.怎么编译都通不过呢?

解决方案 »

  1.   

    as强制类型转换,Fr:=Fr as Fr.className这样写算什么,真是不懂你的程序想干嘛
      

  2.   

    as......汉ing
    Classes that implement interfaces can use the as operator for dynamic binding on the interface. In the following example:procedurePaintObjects(P: TInterfacedObject)var
      X: IPaint;begin  X := P as IPaint;
    { statements }
    end;the variable P of type TInterfacedObject, can be assigned to the variable X, which is an IPaint interface reference. Dynamic binding makes this assignment possible. For this assignment, the compiler generates code to call the QueryInterface method of P抯 IInterface interface. This is because the compiler cannot tell from P抯 declared type whether P抯 instance actually supports IPaint. At runtime, P either resolves to an IPaint reference or an exception is raised. In either case, assigning P to X will not generate a compile-time error as it would if P was of a class type that did not implement IInterface.When you use the as operator for dynamic binding on an interface, you should be aware of the following requirements:Explicitly declaring IInterface: Although all interfaces derive from IInterface, it is not sufficient, if you want to use the as operator, for a class to simply implement the methods of IInterface. This is true even if it also implements the interfaces it explicitly declares. The class must explicitly declare IInterface in its interface list.
    Using an IID: Interfaces can use an identifier that is based on a GUID (globally unique identifier). GUIDs that are used to identify interfaces are referred to as interface identifiers (IIDs). If you are using the as operator with an interface, it must have an associated IID. To create a new GUID in your source code you can use the Ctrl+Shift+G editor shortcut key.
      

  3.   

    registerclass
    findclass
    最好还是用判断吧
      

  4.   

    可能我也没明白的你的意思, 你看一下下面我写的代吗, 可能对你有帮助
    procedure TForm1.Test(o: TObject);
    begin
      o := o as o.ClassType;
      ShowMessage(o.ClassName);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Test(Form1);
    end;
      

  5.   

    能通过才怪ClassType还差不多,TClass你as还说的过去ClassNam是个字符串,你怎么as!
    还有,你的那段有帮助的代码有什么用?procedure TForm1.Test(o: TObject);
    begin
      o := o as o.ClassType;//这不是多此一举吗?
      ShowMessage(o.ClassName);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Test(Form1);
    end;
      

  6.   

    哦,不是一个人呀,呵呵我对 DWGZ() 说的 procedure TForm1.Test(o: TObject);
    begin
      o := o as o.ClassType;//这不是多此一举吗?
      ShowMessage(o.ClassName);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Test(Form1);//这里应该 Test(self);
    end;
      

  7.   

    改成
    type
      TStaTime = class(TThread)
        Fr:TClass;
        protected
      procedure Execute; override;
      procedure TStaTime.Execute;
      begin
        Fr := 你需要强制转换的类.ClassType;
        你需要强制转换的类(Fr).mothed1;
      end;
    end
      

  8.   

    className 是字符串类型的怎么能转换成成类可以用
      FindClass('Tfr') 返回实例
      

  9.   

    既然你知道你的类是什么的,直接用强度转换不就行了吗?
    你的Fr是怎么创建的,是什么类型就用什么类型去转换啊。
    Fr:=TForm.Create那么,Fr的类名一定是TForm啊。
      

  10.   

    type
      TFormClass = class of TForm;procedure TfrmMain.myCreateForm(FormClass: TFormClass; FormObj: TForm);
    var
      i: integer;
      Found: Boolean;   
    begin
      try
        Found := false;
        for i := 0 to self.MDIChildCount - 1 do
          if self.MDIChildren[i].Name = FormObj.Name then
          begin
            Found := true;
            Break;
          end;
        if not Found then
          FormObj := FormClass.Create(Application);
        FormObj.Show;
      except
      end;
    end;调用:
    ...
      myCreateForm(TForm2, form2);
    ...希望对你有帮助。