procedure MyProcedure(Num:integer);
 begin
  case Num of
    3:
     begin
      if not assigned(TestForm) then
        begin
            TestForm:=TTestForm.Create(panel2);
            TestForm.Parent:=panel2;
            TestForm.Show;
        end;
     end;
    5:
     begin
       if not assigned(BasicInfoForm) then
         begin
            BasicInfoForm:=TBasicInfoForm.Create(panel2);
            BasicInfoForm.Parent:=panel2;
            BasicInfoForm.Show;
         end;
     end;
   else
     begin
       showmessage('Else');
     end;
   end;
 end;

解决方案 »

  1.   

    调用
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        MyProcedure(3);
    end;
      

  2.   

    这里用case很好使,也可以用if,不过不如case,最好加上default
      

  3.   

    type
      TFormClass = class of TForm;procedure ShowSpecialForm(var AForm: TForm; AClass: TFormClass);
    begin
      if not assgined(AForm) then
        AForm := AClass.Create(panel2);
      AForm.parent := panel2;
      aform.show;
    end;调用:3: showspecialform(tform(testform), tformclass(testform.classtype));
    5: showspecialform(tform(basicinfoform), tformclass(basicinfoform.classtype));
    6:
    7:....
      

  4.   

    不知道这样行不行procedure FormShow(ThisForm: TForm);
    begin  if not assigned(ThisForm) then
      ThisForm:=TThisForm.Create(panel2);
      ThisForm.Parent:=panel2;
      ThisForm.Show;end;我保守估计,是不行的^_^
      

  5.   

    这里应该用case吧!这样写的话结构还是比较严谨的!case mum of
                                                  :1
                                                  :2
      

  6.   

    楼上的已经说了,不过,我觉的case(枚举)这样可能会更好一点,明白
      

  7.   

    我还是觉得还是procedure MyProcedure(Num:integer);本分些:)
      

  8.   

    还是觉得procedure MyProcedure(Num:integer);本分。踏实些:)
      

  9.   

    lizhenjia(暴雪)写的就没有问题啊。干嘛还那么烦琐的。这个就没有问题的。
      

  10.   

    其实我想要的就是 Idle_(阿呆) 的程序。在调用下句时说类型不对
    3: showspecialform(tform(testform), tformclass(testform.classtype));
    只好改成
    3: showspecialform(tform(testform), Ttestform);谢谢大家。