有一个variant类型的变量从服务器传递过来,通过该variant类型的变量可以调用服务器端的函数,又有一个TForm的窗口变量完成同样的工作,但是是在不同的版本中使用这两个变量,我想通过一个variant类型的中间变量将这两个不同类型的变量统一起来,这样就便于操作,但无论我用什么方法都无法将tform类型转换为variant类型。不知道我说得是否清楚。
请问,可以做到将tform类型转换为variant类型吗?如果可以,请举个例子;如果不可以,请说明原因。

解决方案 »

  1.   

    你看这样行不行unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        Procedure ShowForm(a:Variant);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      a:Variant;
      c:Integer;
    begin
      form2:=TForm2.Create(nil);
      c:=Integer(Form2);
      a:=c;
      showform(a);
    end;procedure TForm1.ShowForm(a: Variant);
    var
      f:TForm;
      b:Integer;
    begin
      b:=a;
      f:=TForm(b);
      f.Show;
    end;end.
      

  2.   

    好像没有这个必要吧,ole对象才能使用variant来执行后期绑定的方法,
    tform使用variant只是用它来作为一个指针传递的途径,和你传个指针没有什么两样。
      

  3.   

    我是这个意思:
    a:tform1;
    b:variant;b:=a;
    b.show;//能直接调用里面的属性和方法,不需要用tform1(b).show;这样的想法可以实现吗?
      

  4.   

    这样不行的,只能这样:
    var
      a:variant;
    begin
      a:=integer(button1);
      tbutton(integer(a)).Show;
    end;但是这和:
    var
      a:=TButton;
    begin
      a:=button1;
      a.show;
    end;
    有什么区别呢?