home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / eXpertDevelopmentKit / DEMO / UDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-26  |  6.1 KB  |  191 lines

  1. unit UDemo;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, StdCtrls,
  7.   Forms, Dialogs,
  8.   XDKMain, // added to call XDK initialization/deinitialization functions
  9.   XDKNotif, XDKMenu, XDKExpt, XDKSnips, XDKGen,
  10.   Proxies,
  11.   DsgnIntf,
  12.   EditIntf;  // added to work with TIFormInterface, etc
  13.  
  14. type
  15.   TDemoDataModule = class(TDataModule)
  16.     xdkAddInMenu1: TxdkAddInMenu;
  17.     AddInMenu: TxdkAddInMenuItem;
  18.     CheckItem: TxdkAddInMenuItem;
  19.     LineItem1: TxdkAddInMenuItem;
  20.     RadioItem1: TxdkAddInMenuItem;
  21.     RadioItem2: TxdkAddInMenuItem;
  22.     RadioItem3: TxdkAddInMenuItem;
  23.     DisabledItem: TxdkAddInMenuItem;
  24.     TestHierarchy: TxdkAddInMenuItem;
  25.     Item1: TxdkAddInMenuItem;
  26.     Item2: TxdkAddInMenuItem;
  27.     Item3: TxdkAddInMenuItem;
  28.     Item4: TxdkAddInMenuItem;
  29.     Item5: TxdkAddInMenuItem;
  30.     Item6: TxdkAddInMenuItem;
  31.     BarItem: TxdkAddInMenuItem;
  32.     DEMOItem: TxdkAddInMenuItem;
  33.     xdkStandardExpert1: TxdkStandardExpert;
  34.     xdkRepositoryExpert1: TxdkRepositoryExpert;
  35.     UnitSnippet: TxdkSnippet;
  36.     UnitCreator: TxdkModuleCreator;
  37.     FormSnippet: TxdkSnippet;
  38.     FormCreator: TxdkModuleCreator;
  39.     DMSnippet: TxdkSnippet;
  40.     DMCreator: TxdkModuleCreator;
  41.     BtnFormCreator: TxdkModuleCreator;
  42.     BtnFormSnippet: TxdkSnippet;
  43.     procedure CheckItemClick(Sender: TObject);
  44.     procedure xdkRadioItemClick(Sender: TObject);
  45.     procedure xdkTestClickItemClick(Sender: TObject);
  46.     procedure DEMOItemClick(Sender: TObject);
  47.     function UnitCreatorSourceWriting(UnitIdent, FormIdent,
  48.       AncestorIdent: String): String;
  49.     function FormCreatorSourceWriting(UnitIdent, FormIdent,
  50.       AncestorIdent: String): String;
  51.     function DMCreatorSourceWriting(UnitIdent, FormIdent,
  52.       AncestorIdent: String): String;
  53.     function BtnFormCreatorSourceWriting(UnitIdent, FormIdent,
  54.       AncestorIdent: String): String;
  55.     procedure BtnFormCreatorFormCreated(Sender: TObject;
  56.       IForm: TIFormInterface);
  57.   private
  58.     { Private declarations }
  59.   public
  60.     { Public declarations }
  61.   end;
  62.  
  63. var
  64.   DemoDataModule: TDemoDataModule;
  65.  
  66. implementation
  67.  
  68. uses
  69.   FDemo;
  70.  
  71. {$R *.DFM}
  72.  
  73. procedure TDemoDataModule.CheckItemClick(Sender: TObject);
  74. begin
  75.   TxdkAddInMenuItem(Sender).Checked:=not TxdkAddInMenuItem(Sender).Checked;
  76.   if TxdkAddInMenuItem(Sender).Checked then
  77.     TxdkAddInMenuItem(Sender).Caption:='Checked'
  78.   else
  79.     TxdkAddInMenuItem(Sender).Caption:='Unchecked';
  80. end;
  81.  
  82. procedure TDemoDataModule.xdkRadioItemClick(Sender: TObject);
  83. begin
  84.   TxdkAddInMenuItem(Sender).Checked:=true;
  85. end;
  86.  
  87. procedure TDemoDataModule.xdkTestClickItemClick(Sender: TObject);
  88. begin
  89.   ShowMessage('Menu item clicked !');
  90. end;
  91.  
  92. procedure TDemoDataModule.DEMOItemClick(Sender: TObject);
  93. begin
  94.   //  calling DemoForm with 'Steps'
  95.   DemoForm:=TDemoForm.Create(nil);
  96.   DemoForm.ShowModal;
  97.   DemoForm.Free;
  98. end;
  99.  
  100. function TDemoDataModule.UnitCreatorSourceWriting(UnitIdent, FormIdent,
  101.   AncestorIdent: String): String;
  102. begin
  103.    UnitSnippet.ParamValues['UnitName']:=UnitIdent; // the first way to set params value
  104.    UnitSnippet.Params.Add('ProcName=MyProc'); // the second way to set params value
  105.    UnitSnippet.DoResultCode;  // replacing all params to neccessary values
  106.    Result:=UnitSnippet.ResultCodeText; //return result code as long string
  107. end;
  108.  
  109. function TDemoDataModule.FormCreatorSourceWriting(UnitIdent, FormIdent,
  110.   AncestorIdent: String): String;
  111. begin
  112.    FormSnippet.ParamValues['UnitName']:=UnitIdent; // the first way to set params value
  113. // note: DoResultCode is not case-sensitive
  114.    FormSnippet.Params.Add('FORMNAME='+FormIdent); // the second way to set params value
  115.    FormSnippet.ParamValues['ancestorname']:=AncestorIdent;
  116.    FormSnippet.DoResultCode;  // replacing all params to neccessary values
  117.    Result:=FormSnippet.ResultCodeText; //return result code as long string
  118. end;
  119.  
  120.  
  121. function TDemoDataModule.DMCreatorSourceWriting(UnitIdent, FormIdent,
  122.   AncestorIdent: String): String;
  123. begin
  124.    DMSnippet.ParamValues['UnitName']:=UnitIdent; // the first way to set params value
  125. // note: DoResultCode is not case-sensitive
  126.    DMSnippet.Params.Add('dmNAME='+FormIdent); // the second way to set params value
  127.    DMSnippet.DoResultCode;  // replacing all params to neccessary values
  128.    Result:=DMSnippet.ResultCodeText; //return result code as long string
  129. end;
  130.  
  131.  
  132. function TDemoDataModule.BtnFormCreatorSourceWriting(UnitIdent, FormIdent,
  133.   AncestorIdent: String): String;
  134. begin
  135.    BtnFormSnippet.ParamValues['UnitName']:=UnitIdent;
  136.    BtnFormSnippet.ParamValues['FormName']:=FormIdent;
  137.    BtnFormSnippet.DoResultCode;  // replacing all params to neccessary values
  138.    Result:=BtnFormSnippet.ResultCodeText; //return result code as long string
  139. end;
  140.  
  141. procedure TDemoDataModule.BtnFormCreatorFormCreated(Sender: TObject;
  142.   IForm: TIFormInterface);
  143. var
  144.   FormIComp : TIComponentInterface;
  145.   Form : TForm;
  146.   BtnIComp : TIComponentInterface;
  147.   Btn  : TButton;
  148.   OnClickMethod:TMethod;
  149.   W,H : integer;
  150.   s   : string;
  151. begin
  152.   FormIComp:=IForm.GetFormComponent;
  153.   with FormIComp do
  154.   try
  155.     W:=260;
  156.     SetPropByName('Width',W); // first way to set properties; set value via variables only, for exam.: use W, but not 260  
  157.     H:=200;
  158.     SetPropByName('Height',H);
  159.     s:='Form with button';
  160.     SetPropByName('Caption',s);
  161.     Form:=TForm(FormIComp.GetComponentHandle); 
  162.  
  163.     Btn:=TButton.Create(nil);  // create button (without owner!)
  164.     try
  165.       Btn.Name:='Button1';
  166.       Btn.Caption:='Click me!';
  167.       Form.InsertComponent(Btn);  // set the button's Owner
  168.       Form.InsertControl(Btn);    // set the button's Parent
  169.       Btn.Left:=30;
  170.       Btn.Top:=40;
  171.       OnClickMethod.Code:=CreateSubClassMethod(Form,'Button1Click'); // creating method with function from 'Proxies' unit
  172.       OnClickMethod.Data:=Form;
  173.       Btn.OnClick:=TNotifyEvent(OnClickMethod);  // set the OnClick-handler for Button
  174.     except
  175.       Btn.Free;
  176.     end;
  177.  
  178.   finally
  179.     FormIComp.Free;
  180.   end;
  181. end;
  182.  
  183. initialization
  184.   // datamodule initialization
  185.   xdkInitModule(TDemoDataModule,DemoDataModule);
  186.  
  187. finalization
  188.   // datamodule deinitialization
  189.   xdkDoneModule(DemoDataModule);
  190. end.
  191.