home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / objects / frm2comp / newcomp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  2.6 KB  |  123 lines

  1. unit NewComp;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: FRM2COMP }
  5.  
  6. {
  7.  
  8.   Converting Forms into Components
  9.   ================================
  10.  
  11.   The description below is of a kluge, but it is a very
  12.   useful kluge.
  13.  
  14.   This is a form that has been converted into a component.
  15.   You can still edit it in the form designer as if it were a
  16.   form, however, you should not try to make it part of
  17.   project, but should choose, File | Open File, and load
  18.   it into Delphi, edit as you please, then close it out.
  19.  
  20.   Make sure that its DFM file does not include the
  21.   following lines:
  22.  
  23.     PixelsPerInch = 96
  24.     TextHeight = 16
  25.  
  26.   More generally, make sure it does not contain any properties
  27.   that are not part of TPanel. To get rid of them, you need to
  28.   translate the DFM file to text, delete them, then translate
  29.   the file back into a DFM file. Do it either in the editor, or
  30.   else use the CONVERT.EXE command line utility. After
  31.   you have converted the Text file back into a DFM,
  32.   rebuild your project.
  33.  
  34.   Inside the DFM file, give the main object its own name:
  35.  
  36. object CompForm: TCompForm
  37.   Left = 15
  38.   Top = 22
  39.   Width = 435
  40.   Height = 300
  41.   Caption = 'Form2'
  42.   Font.Color = clWindowText
  43.   Font.Height = -13
  44.   Font.Name = 'System'
  45.   Font.Style = []
  46.   object SpeedButton1: TSpeedButton
  47.     Left = 168
  48.     Top = 96
  49.     Width = 25
  50.     Height = 25
  51.   end
  52.   object BitBtn1: TBitBtn
  53.     Left = 32
  54.     Top = 24
  55.     Width = 89
  56.     Height = 33
  57.     Caption = 'BitBtn1'
  58.     TabOrder = 0
  59.   end
  60.   object BitBtn2: TBitBtn
  61.     Left = 136
  62.     Top = 24
  63.     Width = 89
  64.     Height = 33
  65.     Caption = 'BitBtn2'
  66.     TabOrder = 1
  67.   end
  68. end
  69.  
  70.  
  71. }
  72.  
  73. interface
  74.  
  75. uses
  76.   SysUtils, WinTypes, WinProcs,
  77.   Messages, Classes, Graphics,
  78.   Controls, Forms, Dialogs,
  79.   StdCtrls, Buttons, ExtCtrls;
  80.  
  81. type
  82.   TCompForm = class(TPanel)
  83.     BitBtn1: TBitBtn;
  84.     BitBtn2: TBitBtn;
  85.     Panel1: TPanel;
  86.     Label1: TLabel;
  87.     procedure BitBtn1Click(Sender: TObject);
  88.     procedure BitBtn2Click(Sender: TObject);
  89.   private
  90.     { Private declarations }
  91.   public
  92.     Constructor Create(AOwner: TComponent); override;
  93.     { Public declarations }
  94.   end;
  95.  
  96. var
  97.   CompForm: TCompForm;
  98.  
  99.  
  100. implementation
  101.  
  102. {$R *.DFM}
  103.  
  104. constructor TCompForm.Create(AOwner: TComponent);
  105. begin
  106.   inherited Create(AOwner);
  107.   IsControl := True;
  108.   Caption := '';
  109.   ReadComponentRes(ClassName, Self);
  110. end;
  111.  
  112. procedure TCompForm.BitBtn1Click(Sender: TObject);
  113. begin
  114.   Label1.Caption := BitBtn1.Caption;
  115. end;
  116.  
  117. procedure TCompForm.BitBtn2Click(Sender: TObject);
  118. begin
  119.   Label1.Caption := BitBtn2.Caption;
  120. end;
  121.  
  122. end.
  123.