home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / DLG.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  22KB  |  737 lines

  1. /* DLG.CPP: Dialogbox Expert implementation (DlgExpert class)
  2. */
  3.  
  4. //---------------------------------------------------------------
  5. #include <vcl\vcl.h>
  6. #pragma hdrstop
  7.  
  8. #include <vcl\Proxies.hpp>
  9. #include <vcl\controls.hpp>
  10. #include <vcl\classes.hpp>
  11. #include <vcl\VirtIntf.hpp>
  12. #include <vcl\IStreams.hpp>
  13. #include "dlg.h"          // dialogbox expert class defintion
  14.  
  15. //---------------------------------------------------------------
  16. #pragma resource "*.dfm"
  17. TDlgExpert *DlgExpert;
  18.  
  19. const int
  20.   // page numbers
  21.   pgStyle          = 0,    // multi vs. single page dialog
  22.   pgPages          = 1,    // page names
  23.   pgButtons        = 2,    // button layouts
  24.   SourceBufferSize = 8096;
  25.  
  26. int DlgHeight = 250;
  27. int DlgWidth  = 400;
  28. int BtnHeight =  25;
  29. int BtnWidth  =  75;
  30.  
  31. //========================================[ TDlgExpert ]=========
  32. __fastcall TDlgExpert::TDlgExpert(TComponent* AOwner)
  33.                       :TForm(AOwner)
  34. {
  35. }
  36.  
  37. //========================================[ TDlgExpert ]=========
  38. __fastcall TDlgExpert::TDlgExpert(HWND ParentWindow)
  39.                       :TForm(ParentWindow)
  40. {
  41. }
  42.  
  43. //========================================[ TDlgExpert ]=========
  44. __fastcall TDlgExpert::TDlgExpert(TComponent* AOwner, int Dummy)
  45.                       :TForm(AOwner, Dummy)
  46. {
  47. }
  48.  
  49. //========================================[ TDlgExpert ]=========
  50. __fastcall TDlgExpert::~TDlgExpert(void) {
  51. }
  52.  
  53. //========================================= TDlgExpert ==========
  54. void __fastcall TDlgExpert::FormCreate(TObject *Sender)
  55. {
  56.   DrawBitmap = new Graphics::TBitmap;
  57.   PrevClick(this);
  58.   RefreshButtons();
  59. } // end of TDlgExpert.FormCreate()
  60.  
  61. //========================================= TDlgExpert ==========
  62. void __fastcall TDlgExpert::FormDestroy(TObject *Sender)
  63. {
  64.   delete DrawBitmap;
  65. } // end of TDlgExpert.FormDestroy()
  66.  
  67. //========================================= TDlgExpert ==========
  68. void __fastcall TDlgExpert::CancelClick(TObject *Sender)
  69. {
  70.   Close();
  71. } // end of TDlgExpert.CancelClick()
  72.  
  73. //========================================= TDlgExpert ==========
  74. // Paint the sample pane based on the currently selected options
  75. void __fastcall TDlgExpert::SamplePaint(TObject *Sender)
  76. {
  77.   int X;
  78.   int Y;
  79.  
  80.   // always paint the background dialog
  81.   DrawBitmap = new Graphics::TBitmap;
  82.   DrawBitmap->Handle = LoadBitmap(instance, "DIALOG");
  83.   Sample->Canvas->Draw(0, 0, DrawBitmap);
  84.  
  85.   if (Definition.Contains(daMultPg))
  86.   {
  87.     DrawBitmap->Handle = LoadBitmap(instance, "MULTPG");
  88.     Sample->Canvas->Draw(4, 16, DrawBitmap);
  89.   }
  90.  
  91.   if (Definition.Contains(daBtnsV))
  92.   {
  93.     DrawBitmap->Handle = LoadBitmap(instance, "BTNSV");
  94.     X = 75;
  95.     Y = 22;
  96.  
  97.     if (Definition.Contains(daMultPg))
  98.     {
  99.       X -= 2;
  100.       Y += 4;
  101.     }
  102.  
  103.     Sample->Canvas->Draw(X, Y, DrawBitmap);
  104.   }
  105.  
  106.   if (Definition.Contains(daBtnsH))
  107.   {
  108.     DrawBitmap->Handle = LoadBitmap(instance, "BTNSH");
  109.     X = 50;
  110.     Y = 55;
  111.  
  112.     if (Definition.Contains(daMultPg))
  113.       Y -= 4;
  114.  
  115.     Sample->Canvas->Draw(X, Y, DrawBitmap);
  116.   }
  117.  
  118.   delete DrawBitmap;
  119.   DrawBitmap = 0;
  120. } // end of TDlgExpert::SamplePaint()
  121.  
  122. //========================================= TDlgExpert ==========
  123. void __fastcall TDlgExpert::StyleClick(TObject *Sender)
  124. {
  125.   if (rbMultPg->Checked)
  126.     Definition << daMultPg;
  127.   else
  128.     Definition >> daMultPg;
  129.  
  130.   SamplePaint(this);
  131. } // end of TDlgExpert.StyleClick(
  132.  
  133. //========================================= TDlgExpert ==========
  134. void __fastcall TDlgExpert::BtnClick(TObject *Sender)
  135. {
  136.   if (rbBtnsV->Checked)
  137.     Definition << daBtnsV;
  138.   else
  139.     Definition >> daBtnsV;
  140.  
  141.   if (rbBtnsH->Checked)
  142.     Definition << daBtnsH;
  143.   else
  144.     Definition >> daBtnsH;
  145.  
  146.   SamplePaint(this);
  147. } // end of TDlgExpert.BtnClick()
  148.  
  149. //========================================= TDlgExpert ==========
  150. void __fastcall TDlgExpert::PrevClick(TObject *Sender)
  151. {
  152.   switch(PageControl->ActivePage->PageIndex)
  153.   {
  154.     case pgStyle:
  155.       return;
  156.     case pgPages:
  157.       PageControl->ActivePage = PageControl->Pages[pgStyle];
  158.       break;
  159.     case pgButtons:
  160.       if (Definition.Contains(daMultPg))
  161.         PageControl->ActivePage = PageControl->Pages[pgPages];
  162.       else
  163.         PageControl->ActivePage = PageControl->Pages[pgStyle];
  164.       break;
  165.   }
  166.  
  167.   RefreshButtons();
  168. } // end of TDlgExpert::PrevClick()
  169.  
  170. //========================================= TDlgExpert ==========
  171. void __fastcall TDlgExpert::NextClick(TObject *Sender)
  172. {
  173.   switch(PageControl->ActivePage->PageIndex)
  174.   {
  175.     case pgStyle:
  176.       if (Definition.Contains(daMultPg))
  177.         PageControl->ActivePage = PageControl->Pages[pgPages];
  178.       else
  179.         PageControl->ActivePage = PageControl->Pages[pgButtons];
  180.       break;
  181.     case pgPages:
  182.       PageControl->ActivePage = PageControl->Pages[pgButtons];
  183.       break;
  184.     case pgButtons:
  185.       ModalResult = 1; //mrOK                                    //112596EAS
  186.       return;
  187.   }
  188.  
  189.   RefreshButtons();
  190. } // end of TDlgExpert::NextClick()
  191.  
  192. //========================================= TDlgExpert ==========
  193. void __fastcall TDlgExpert::RefreshButtons(void)
  194. {
  195.   PrevButton->Enabled = PageControl->ActivePage->PageIndex > 0;
  196.   if (PageControl->ActivePage->PageIndex == pgButtons)
  197.     NextButton->Caption = LoadStr(sFinish);
  198.   else
  199.     NextButton->Caption = LoadStr(sNext);
  200. } // end of TDlgExpert::RefreshButtons()
  201.  
  202. //========================================= TDlgExpert ==========
  203. // Create the dialog defined by the user
  204. TForm* __fastcall TDlgExpert::DoFormCreation(const String ffn)
  205. {
  206.   TPoint       BtnPos;
  207.   TPageControl *PgCtrl;
  208.   int          I;
  209.   TForm        *Result;
  210.  
  211.   // Create form symbol based on button orientation and...
  212.   if (!Definition.Contains(daBtnsV) && !Definition.Contains(daBtnsH))
  213.     FormName = "OKNoButDlg";
  214.   else {
  215.     if (Definition.Contains(daBtnsH))
  216.       FormName = "OKBottomDlg";
  217.     else
  218.       FormName = "OKRightDlg";
  219.   }
  220.  
  221.   // ...number associated with the forms's module (file) name.
  222.   FormName += ffn.c_str()[ffn.Length()-1];
  223.  
  224.   // Create the dialog's form and...
  225.   Result = new TForm(this);
  226.  
  227.   // ...a proxy form for it.
  228.   Proxies::CreateSubClass(Result, "T" + FormName, __classid(TForm));
  229.  
  230.   // Give the form its personality and...
  231.   Result->BorderStyle = bsDialog;
  232.   Result->ClientWidth = DlgWidth;
  233.   Result->ClientHeight= DlgHeight;
  234.   Result->Position    = poScreenCenter;
  235.   Result->Name        = FormName;
  236.   Result->Caption     = FormName;
  237.   Font->Name          = "MS Sans Serif";
  238.   Font->Size          = 8;
  239.  
  240.   // ...create its pages (if a paged dialog box was selected).
  241.   if (Definition.Contains(daMultPg))
  242.   {
  243.     PgCtrl         = new TPageControl(Result);
  244.     PgCtrl->Parent = Result;
  245.     PgCtrl->Name   = "PageControl1";
  246.     PgCtrl->Align  = alClient;
  247.  
  248.     if (PageNames->Lines->Count > 0)
  249.     {
  250.       for (I = 0; I < PageNames->Lines->Count; I++)
  251.       {
  252.         TTabSheet *temp   = new TTabSheet(Result);
  253.         temp->PageControl = PgCtrl;
  254.         temp->Caption     = PageNames->Lines[I].GetText();
  255.         temp->Name        = Format("TabSheet%d",
  256.                                    OPENARRAY(TVarRec, (I + 1)));
  257.       }
  258.     }
  259.   }
  260.  
  261.   // Setup and create vertical/horizontal buttons.
  262.   if (Definition.Contains(daBtnsH) || Definition.Contains(daBtnsV))
  263.   {
  264.  
  265.     // Get the starting point for the buttons and...
  266.     if (Definition.Contains(daBtnsH)) {
  267.       BtnPos = Point(Result->ClientWidth-((BtnWidth+2)*3)-(5*3),
  268.                      Result->ClientHeight-(BtnHeight+2)-5);
  269.     }
  270.     else
  271.       BtnPos = Point(Result->ClientWidth-(BtnWidth+2)-5,
  272.                      BtnHeight+5);
  273.  
  274.     // ...finalize positions.
  275.     if (Definition.Contains(daMultPg))
  276.     {
  277.       BtnPos.x -= 5;
  278.       if (Definition.Contains(daBtnsV))
  279.         BtnPos.y += 5;
  280.       else
  281.         BtnPos.y -= 5;
  282.     }
  283.  
  284.    // Create the buttons. This is the 'OK' button,...
  285.     TButton *temp     = new TButton(Result);
  286.     temp->Parent      = Result;
  287.     temp->Left        = BtnPos.x;
  288.     temp->Top         = BtnPos.y;
  289.     temp->Height      = BtnHeight;
  290.     temp->Width       = BtnWidth;
  291.     temp->Caption     = LoadStr(sOKButton);
  292.     temp->Name        = "Button1";
  293.     temp->Default     = True;
  294.     temp->ModalResult = mrOk;
  295.  
  296.     // (Move to the next button position)
  297.     if (Definition.Contains(daBtnsH))
  298.       BtnPos.x += BtnWidth + 5;
  299.     else
  300.       BtnPos.y += BtnHeight + 5;
  301.  
  302.     // ...this is the 'Cancel' button and...
  303.     temp              = new TButton(Result);
  304.     temp->Parent      = Result;
  305.     temp->Left        = BtnPos.x;
  306.     temp->Top         = BtnPos.y;
  307.     temp->Height      = BtnHeight;
  308.     temp->Width       = BtnWidth;
  309.     temp->Name        = "Button2";
  310.     temp->Caption     = LoadStr(sCancelButton);
  311.     temp->Cancel      = True;
  312.     temp->ModalResult = mrCancel;
  313.  
  314.     // (Move to the next button position)
  315.     if (Definition.Contains(daBtnsH))
  316.       BtnPos.x += 75 + 5;
  317.     else
  318.       BtnPos.y += 25 + 5;
  319.  
  320.     // ...this is the 'Help' button.
  321.     temp          = new TButton(Result);
  322.     temp->Parent  = Result;
  323.     temp->Left    = BtnPos.x;
  324.     temp->Top     = BtnPos.y;
  325.     temp->Height  = BtnHeight;
  326.     temp->Width   = BtnWidth;
  327.     temp->Name    = "Button3";
  328.     temp->Caption = LoadStr(sHelpButton);
  329.   }
  330.  
  331.   return Result;
  332. } // end of TDlgExpert::DoFormCreation()
  333.  
  334. //========================================= TDlgExpert ==========
  335. TMemoryStream* __fastcall TDlgExpert::CreateHdrSource(const String UnitIdent,
  336.                                                       const String FormIdent)
  337. {
  338.   int           I;
  339.   TMemoryStream *Result;
  340.  
  341.   SourceBuffer = new char[SourceBufferSize];
  342.   try
  343.   {
  344.     Result = new TMemoryStream;
  345.     try
  346.     {
  347.       // Write header's macro guard and includes:
  348.       //#ifndef tunameH
  349.       //#define tunameH
  350.       //
  351.       //#include <SysUtils.hpp>
  352.       //#include <Windows.hpp>
  353.       //#include <Messages.hpp>
  354.       //#include <Classes.hpp>
  355.       //#include <Graphics.hpp>
  356.       //#include <Controls.hpp>
  357.       //#include <StdCtrls.hpp>
  358.       //#include <ExtCtrls.hpp>
  359.       //#include <Forms.hpp>
  360.       {
  361.       String s = (String)SEPARATOR + CRLF;
  362.       s       += (String)"#ifndef %sH" + CRLF;
  363.       s       += (String)"#define %sH" + CRLF;
  364.       s       += (String)SEPARATOR + CRLF;
  365.       s       += (String)"#include <vcl\\SysUtils.hpp>" + CRLF;
  366.       s       += (String)"#include <vcl\\Windows.hpp>" + CRLF + CRLF;
  367.       s       += (String)"#include <vcl\\Messages.hpp>" + CRLF;
  368.       s       += (String)"#include <vcl\\Classes.hpp>" + CRLF;
  369.       s       += (String)"#include <vcl\\Graphics.hpp>" + CRLF;
  370.       s       += (String)"#include <vcl\\Controls.hpp>" + CRLF;
  371.       s       += (String)"#include <vcl\\StdCtrls.hpp>" + CRLF;
  372.       s       += (String)"#include <vcl\\ExtCtrls.hpp>" + CRLF;
  373.       s       += (String)"#include <vcl\\Forms.hpp>" + CRLF + CRLF;
  374.       FmtWrite(Result, s.c_str(),
  375.                OPENARRAY(TVarRec, (UnitIdent, UnitIdent)));
  376.       }
  377.  
  378.       // If multipage dialogbox, include COMCTLS.HPP
  379.       if (Definition.Contains(daMultPg)) {
  380.         String s  = (String)"#include <vcl\\ComCtrls.hpp>" + CRLF;
  381.                s += (String)CRLF + SEPARATOR + CRLF;
  382.         FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (NULL)));
  383.       }
  384.  
  385.       // The class declaration
  386.       {
  387.       String s  = (String)"class T%s: public TForm" + CRLF;
  388.                s += (String)"{" + CRLF;
  389.                s += (String)"__published:" + CRLF;
  390.       FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (FormName)));
  391.       }
  392.  
  393.       // Add variable declarations
  394.       if (Definition.Contains(daBtnsH) || Definition.Contains(daBtnsV))
  395.       {
  396.         String s  = (String)"%sTButton *Button1;" + CRLF;
  397.                s += (String)"%sTButton *Button2;" + CRLF;
  398.                s += (String)"%sTButton *Button3;" + CRLF;
  399.         FmtWrite(Result, s.c_str(),
  400.                  OPENARRAY(TVarRec, (INDENT, INDENT, INDENT)));
  401.        }
  402.  
  403.       // If this is a multipage dialogbox...
  404.       if (Definition.Contains(daMultPg))
  405.       {
  406.  
  407.         // ...we'll need a page control object and...
  408.         String s = (String)"%sTPageControl *PageControl1;" + CRLF;
  409.         FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (INDENT)));
  410.  
  411.         // ...tabsheet objects for each page.
  412.         if (PageNames->Lines->Count > 0)
  413.           for (I = 0; I < PageNames->Lines->Count; I++) {
  414.             String s = (String)"%sTTabSheet TTabSheet%d;" + CRLF;
  415.             FmtWrite(Result, s.c_str(),
  416.                      OPENARRAY(TVarRec, (INDENT, I + 1)));
  417.           }
  418.       }
  419.  
  420.       // Write the user maintained class sections and the class's
  421.       // constructor prototype:
  422.       //private:
  423.       //public:
  424.       //    virtual __fastcall Tclassname(TComponent *Owner);
  425.       //};
  426.       {
  427.       String s  = (String)"private:" + CRLF;
  428.              s += (String)"public:" + CRLF;
  429.              s += (String)"%svirtual __fastcall T%s(TComponent *Owner);" + CRLF;
  430.              s += (String)"};" + CRLF;
  431.       FmtWrite(Result, s.c_str(),
  432.                OPENARRAY(TVarRec, (INDENT, FormName)));
  433.       }
  434.  
  435.       // Write the form's extern and close the macro guard:
  436.       //---------------------------------------------------------
  437.       //extern TClassname *classname;
  438.       //---------------------------------------------------------
  439.       //
  440.       //#endif // headernameH
  441.       {
  442.       String s  = (String)SEPARATOR + CRLF;
  443.              s += (String)"extern T%s *%s;" + CRLF;
  444.              s += (String)SEPARATOR + CRLF;
  445.              s += (String)"#endif"; // // %sH" + CRLF;
  446.       FmtWrite(Result, s.c_str(),
  447.                OPENARRAY(TVarRec, (FormName, FormName)));
  448.       }
  449.  
  450.       // Finally, rewind to start of stream.
  451.       Result->Position = 0;
  452.  
  453.     } catch(...)
  454.     {
  455.       delete Result;
  456.       Result = NULL;
  457.       MessageBox(NULL, "Header text output failed.", "EXCEPTION", MB_OK);
  458.     }
  459.   } catch(...)
  460.   {
  461.     delete SourceBuffer;
  462.     SourceBuffer = NULL;
  463.     MessageBox(NULL, "Header Stream creation failed.", "EXCEPTION", MB_OK);
  464.   }
  465.  
  466.   delete SourceBuffer;
  467.   SourceBuffer = NULL;
  468.   return Result;
  469. } // end of TDlgExpert::CreateSource()
  470.  
  471. //========================================= TDlgExpert ==========
  472. TMemoryStream* __fastcall TDlgExpert::CreateSource(const String UnitIdent,
  473.                                                    const String FormIdent)
  474. {
  475.   TMemoryStream *Result;
  476.  
  477.   try
  478.   {
  479.     SourceBuffer = new char[SourceBufferSize];
  480.     Result = new TMemoryStream;
  481.     try
  482.     {
  483.       // CPP (source) setup looks like:
  484.       //---------------------------------------------------------
  485.       //#include <vcl.h>
  486.       //#pragma hdrstop
  487.       //
  488.       {
  489.       String s  = (String)SEPARATOR + CRLF;
  490.              s += (String)"#include <vcl.h>" + CRLF;
  491.              s += (String)"#pragma hdrstop" + CRLF;
  492.       FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (NULL)));
  493.       }
  494.  
  495.       // Additional include if multipaged dialog selected
  496.       //#include <ComCtrls.h>
  497.       if (Definition.Contains(daMultPg)) {
  498.         String s = (String)"#include <vcl\\ComCtrls.hpp>" + CRLF;
  499.         FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec, (NULL)));
  500.       }
  501.  
  502.       // Include the source's own header file:
  503.       //#include <modnam.h>
  504.       //---------------------------------------------------------
  505.       //#pragma resource "*.dfm"
  506.       //
  507.       {
  508.       sprintf(SourceBuffer, "\n\r#include \"%s.h\"\n\r\n\r"
  509.                             "#pragma resource \"*.dfm\"\n\r",
  510.               UnitIdent.c_str());
  511.       Result->Write(SourceBuffer, strlen(SourceBuffer));
  512.       }
  513.  
  514.       // Add variable declarations and constructor:
  515.       //TOKRightDlg *OKRightDlg;
  516.       //---------------------------------------------------------
  517.       //__fastcall TOKRightDlg::TOKRightDlg(TComponent *AOwner)
  518.       //                       :TForm(AOwner)
  519.       //{
  520.       //}
  521.       //---------------------------------------------------------
  522.       //
  523.       {
  524.       String s  = (String)"T%s *%s;" + CRLF + SEPARATOR + CRLF + CRLF;
  525.              s += (String)"__fastcall T%s::T%s(TComponent* AOwner)" + CRLF;
  526.              s += (String)"              :TForm(AOwner)" + CRLF;
  527.              s += (String)"{" + CRLF;
  528.              s += (String)"}" + CRLF +  SEPARATOR;
  529.       FmtWrite(Result, s.c_str(), OPENARRAY(TVarRec,
  530.                                             (FormName, FormName,
  531.                                              FormName, FormName)));
  532.       }
  533.  
  534.       // Finally, rewind to start of stream.
  535.       Result->Position = 0;
  536.     } catch(...)
  537.     {
  538.       delete Result;
  539.       Result = NULL;
  540.       MessageBox(NULL, "Source text output failed", "EXCEPTION", MB_OK);
  541.     }
  542.   } catch(...)
  543.   {
  544.     delete SourceBuffer;
  545.     SourceBuffer = NULL;
  546.     MessageBox(NULL, "Source stream creation failed", "EXCEPTION", MB_OK);
  547.   }
  548.  
  549.   delete SourceBuffer;
  550.   SourceBuffer = NULL;
  551.   return Result;
  552. } // end of TDlgExpert::CreateSource()
  553.  
  554. //========================================= TDlgExpert ==========
  555. void __fastcall TDlgExpert::FmtWrite(TStream *Stream, char *Fmt,
  556.                                      const TVarRec *Args,
  557.                                      const int Args_Size)
  558. {
  559.   String p("%");
  560.   String f(Fmt);
  561.  
  562.   if (Stream && SourceBuffer)
  563.   {
  564. /*
  565.     if (f.Pos(p))
  566.     {
  567.       int position;
  568.       for (int i=0; i<Args_Size; i++)
  569.       {
  570.         if (!f.Pos(p)) break;
  571.         position = f.Pos(p);
  572.         f.Delete(position, 2);
  573.         f.Insert(MakeStr(Args[i]), position);
  574.       }
  575.     }
  576. */
  577.     StrLFmt(SourceBuffer, SourceBufferSize, Fmt, Args, Args_Size);
  578.     Stream->Write(SourceBuffer, strlen(SourceBuffer));
  579.   }
  580. } // end of TDlgExpert::FmtWrite()
  581.  
  582. //========================================= TDlgExpert ==========
  583. TMemoryStream* __fastcall TDlgExpert::CreateForm(const String FormIdent)
  584. {
  585.   TForm *DlgForm;
  586.   TMemoryStream *Result = new TMemoryStream;
  587.  
  588.   DlgForm = DoFormCreation(FormIdent);
  589.   try
  590.   {
  591.     Result = new TMemoryStream;
  592.     Result->WriteComponentRes(FormIdent, DlgForm);
  593.     Result->Position = 0;
  594.   } catch(...)
  595.   {
  596.     delete DlgForm;
  597.     delete Result;
  598.   }
  599.  
  600.   delete DlgForm;
  601.   return Result;
  602. } // end of TDlgExpert::CreateForm()
  603.  
  604. //---------------------------------------------------------------
  605. String MakeStr(const TVarRec &Args)
  606. {
  607.   String tmp;
  608.   switch (Args.VType)
  609.   {
  610.     case vtInteger:
  611.       tmp += ::IntToStr(Args.VInteger);
  612.       break;
  613.     case vtBoolean:
  614.       tmp += Args.VBoolean?"TRUE":"FALSE";
  615.       break;
  616.     case vtChar:
  617.       tmp += String(&Args.VChar, 1);
  618.       break;
  619.     case vtExtended:
  620.       tmp += ::FloatToStr(*Args.VExtended);
  621.       break;
  622.     case vtString:
  623.       tmp += *Args.VString;
  624.       break;
  625.     case vtPChar:
  626.       tmp += String(Args.VPChar);
  627.       break;
  628.     case vtObject:
  629.       tmp += "-TObject";
  630.       break;
  631.     case vtClass:
  632.       tmp += "-TClass-";
  633.       break;
  634.     case vtAnsiString:
  635.       tmp += String(reinterpret_cast<char*>(Args.VAnsiString));
  636.       break;
  637.    case vtCurrency:
  638.       tmp += CurrToStr(*Args.VCurrency);
  639.       break;
  640.     case vtVariant:
  641.       tmp += *Args.VVariant;
  642.       break;
  643.     default:
  644.       tmp += "-Other-";
  645.   }
  646.   return tmp;
  647. } // end of MakeStr()
  648.  
  649. //***************************************************************
  650. void __stdcall DialogExpert(TIToolServices *ToolServices)
  651. {
  652.   TDlgExpert     *D;
  653.   TIMemoryStream *ISourceStream;
  654.   TIMemoryStream *IFormStream;
  655.   TIMemoryStream *IHdrStream;
  656.   String         UnitIdent;
  657.   String         FormIdent;
  658.   TFileName      *FileName = new TFileName;
  659.  
  660.   // If we were not pass a toolservices object, forget it.
  661.   if (!ToolServices) exit(1);
  662.  
  663.   if (ToolServices->GetNewModuleName(UnitIdent, *FileName)) {
  664.  
  665.     // Allocate the dialog expert and...
  666.     D = new TDlgExpert(Application);
  667.     try
  668.     {
  669.  
  670.       // ...display the dialog expert dialog box modally.
  671.       if (D->ShowModal() == 1/*mrOK*/) {                         //112496EAS
  672.  
  673.         // Make everything but the first letter of the unit
  674.         // name lowercase.
  675.         UnitIdent.LowerCase();
  676.         UnitIdent[0] &= 0x5F ;
  677.  
  678.         // The form's file name is dependent on the button
  679.         // orientation and we add a number to the end to reduce
  680.         // name conflict when several dialogs are created in
  681.         // quick succession.
  682.         FormIdent = "Form" + UnitIdent.SubString(5, 255);
  683.  
  684.         IFormStream = new TIMemoryStream(D->CreateForm(FormIdent));
  685.         try
  686.         {
  687.           IFormStream->AddRef();
  688.           IHdrStream = new TIMemoryStream(D->CreateHdrSource(UnitIdent,
  689.                                                              FormIdent));
  690.           ISourceStream = new TIMemoryStream(D->CreateSource(UnitIdent,
  691.                                                              FormIdent));
  692.           try
  693.           {
  694.             ISourceStream->AddRef();
  695.             IHdrStream->AddRef();
  696.  
  697.             TCreateModuleFlags CreateFlags;
  698.             CreateFlags << cmAddToProject << cmShowSource
  699.                         << cmShowForm << cmUnNamed << cmMarkModified;
  700.             ToolServices->CreateCppModule(*FileName, "", "", "",
  701.                                           IHdrStream, ISourceStream,
  702.                                           IFormStream, CreateFlags);
  703.  
  704.           } catch(...)
  705.           {
  706.             ISourceStream->OwnStream = true;
  707.             IHdrStream->OwnStream    = true;
  708.             delete ISourceStream;
  709.             delete IHdrStream;
  710.           }
  711.  
  712.         } catch(...)
  713.         {
  714.           IFormStream->OwnStream = true;
  715.           delete IFormStream;
  716.         }
  717.  
  718.       }
  719.     } catch(...)
  720.     {
  721.       delete D;
  722.     }
  723.   }
  724.  
  725.   ISourceStream->OwnStream = true;
  726.   IFormStream->OwnStream   = true;
  727.   IHdrStream->OwnStream    = true;
  728.   delete ISourceStream;
  729.   delete IFormStream;
  730.   delete IHdrStream;
  731.   delete D;
  732. } // end of DialogExpert()
  733.  
  734. //---------------------------------------------------------------
  735.  
  736.  
  737.