Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. #include "Unit2.h"
  6. #include "Unit3.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13.         : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TForm1::Button1Click(TObject *Sender)
  18. {
  19.   int ii;
  20.   for(ii=0;ii<Application->ComponentCount;ii++)
  21.   {
  22.     ShowMessage(Application->Components[ii]->ClassName());
  23.   }
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::Button2Click(TObject *Sender)
  27. {
  28.   TForm *fm;
  29.   AnsiString ass,mss;
  30.   int ii;
  31.   mss=Application->MainForm->Name;
  32.   ii=0;
  33.   for(;;)
  34.   {
  35.     if(ii>=Application->ComponentCount)break;
  36.     ass=Application->Components[ii]->Name;
  37.     if((ass!=mss)&&(ass!=""))
  38.     {
  39.       ShowMessage(ass);
  40.       fm=(TForm *)Application->Components[ii];
  41.       delete fm;
  42.     }
  43.     else
  44.       ii++;
  45.   }
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TForm1::Button3Click(TObject *Sender)
  49. {
  50.   Form2->Show();
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::Button4Click(TObject *Sender)
  54. {
  55.   Form3->Show();
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::Button5Click(TObject *Sender)
  59. {
  60.   try
  61.   {
  62.     Form2->Show();
  63.   }
  64.   catch(...)
  65.   {
  66.     Application->CreateForm(__classid(TForm2), &Form2);
  67.     Form2->Show();
  68.   }
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::Button6Click(TObject *Sender)
  72. {
  73.   try
  74.   {
  75.     Form3->Show();
  76.   }
  77.   catch(...)
  78.   {
  79.     Application->CreateForm(__classid(TForm3), &Form3);
  80.     Form3->Show();
  81.   }
  82. }
  83. //---------------------------------------------------------------------------