      

     8 

      Delphi    .   
           
      . 
      6. "  Delphi",  7, "  
 Win32"       
.           
   ,  ,       
.          ,  
       . 

       

      ,     , 
    .    ,   
  .     ,   
    . 
    Delphi      TForm,   , 
     (Form Designer),   
,     . 

      
     TForm     TWinControl. ,   
      6, "  Delphi". 

     TForm 

     TForm         
    . 

    Active 

     Active ,     .  ,  
 True,    False. Windows     
,    . 

       

            ,    
Delphi,           . 

       

           (SDI), 
 (MDI)  . 

       

          (TApplication 
 TScreen). 

      

          ( ,  )   . 

212


      
    11         . 

               
  .      ,   
   MDI-  "" .   
     Active  MDI-    
 True. 
     ActiveForm  TScreen,     , 
 ,        

    [  I 

    ActiveControl 

     ActiveControl    TWinControl,   
   .        
, ,         
.  ActiveControl       
      .      
  ,    edtCustNameTnepei  . 

    procedure  TDataEntryForm.FormCloseQuery(Sender:   Tobject; 
    var  CanClose:   Boolean); begin 
    {,        .} 
    if edtCustName.Text  =   ''   then 
    begin 
    { .} CanClose   :=  False; 
    {          .} ActiveControl   
:=  edtCustName; ; 
    end; end; 

     SetFocus  TWinControl      
  ActiveControl. 

     * 
        Sender  . Sender 
,       .  
      . 

      1 
          i  

    AutoScroll, HorzScrollBar  VertScrollBar 

     AutoScroll      ,  
       .    
True     ,      ,   
   .     False, 
     ,     . 

      1 
     TScrollBar,    6, "  
Delphi",       AutoScroll. 

     8.        213 

            HorzScrollBar  
VertScrollBar.     ,   
 .        
 ,     , AutoScroll  , 
      ,  
    .    ,      . 

    {   .} VetrScrollBar.Range   :=  
Height   *   2; {   .} VertScrollBar. 
Visibl--   :=  True; 
    (   .} HorzScrollBar.Range   
:=  Width   *   2; {   .} 
HorzScrollBar.Visible   := True; 

      ,      ? 
  6, "  Delphi",  
     TScrollBar,  Position. 

    Border-Icons 

     Borderlcons     , 
       . 
     biMinimize  biMaximize  ,   
      . 

      
        biMinimize  biMaximize ,  
  

    derStyle  bsSizeable  bsSizeToolWin. 

     biHelp     .    
 - ,  ,    
Hint, ..   Windows Help.  . 8.1   . 
     biSystemMenu    ,  
  ,    . 8.2. 

    . 8.1.   -      
        

    . 8.2.       ,         


    214        II.   


      
        biMinimize, biMaximize  biHelp , 
   

    Borderlcons biSystemMenu. 
    BorderStyle 

     BorderStyle    : 
    | li     ;     ! 
           ; 
          ; 
          . 

     . 8.3      BorderStyle.   
    200x200 . 

    . 8.3.   BorderStyle   .    
,     , : bssizeable, bsDialog, 
bsSingle, bsSizeToolWin, bsToolWindow  bsNone 
       BorderStyle   bsSizeable,  
    .      
         .   
   Explorer  Notepad. 
     bsDialog   ,  ,  
           
 . 16-  Windows       
    ,   . ,    
   ,    ^^^^^^, 
   !       
    ,      ,    
,     .-?1 .  . 

    | ( 
     biMinimize  biMaximize  Borderlcons   , 
  Border-Style   bsDialog. 

          bsSingle,  ,   
     .    bsDialog, bsSingle  
   '   , 
   ,  ,   
().     Calculator. 
     . 8.4      bsSingle. 

     8.          215 


    . 8.4.  bssingle ,      
  

      (Toolbar)      
 .  Delphi    , 
   TSpeedButton  ,   bsSizeTocl 
-Win  bsToolWindow.    bsSizeToolWin      
  biMinimize, b: -Maximize  biHelp.    bsToolWindow 
  ,     . 
     bsNone      .    
      ,   
        .  . 8.5 
     bsNone. 

     . 
    I 
      

    . 8.5.       -t... ,..,.      
   bsNone 

         BorderStyle ,    
  , Delphi    
AutoScroll  True. 
       bsDialog  bsNone     . 

    Height  Width 

               
           
 .        
 . 

    216        II.   

    {        .} Left   :=   0;      
:=   0; 
    {  .} Width     :=   Screen.Width; Height   :=   Screen.Height; 
    ( TScreen.     ,    Screen 
       .) 

     , , ,  ,     
 .       
SetBoundsopeee   TWinControl: 

    SetBounds(0,   0,   Screen.Width,   Screen.Height); 
    ClientHeight  ClientWidth 

             .  
      ,   
   ClientHeight  ClientWidth.    
  ,  ,       
  .       
      ,   
 TImage, imgPicture. 

    with  imgPicture.Picture  do begin 
    {  .} 
    ClientWidth      :=  Width; 
    ClientHeight   :=  Height; end; 

    _    Windows    
,    .     ~ ,  
 WM_NCPAINT (      4, "Object Pascal: 
 "). 

    FormStyle 

     FormStyle   ,   
     Windows.     
  MDI (Multiple Document Interface   )  -MDI. 
      MDI- (f sMDIForm  f sMDIChild),   
   . 
    He-MDI       fsNormal  fsStayOnTop. 
   f sNormal,    , 
  ,    SDI-. 

    . 8.6.  f sStayOnTop      
  

     f sStayOnTop     ,   
    ,        
   .      
 Chat,      (. 8.6). 

     8.               217 

       ,   Chat,    
     . 

    procedure^ TForml.mnuAlwaysOnTopClick(Sender: TObject); begin . 
    with .mnuAlwaysOnTop do begiii 
    {    .} Qhecked := not Checked; 
    {  .} if Checked then 
    {  fsStayOnTop.} FormStyle := fsStayOnTop else 
    {  .} FormStyle := fsNormal; end; end; 

      FormStyle   OnShow. 

      
    Icon 
     Icon  ,  Windows   
 .   Windows 95       
      .      
  ,    Icon   Application. 

    KeyPreview 

     TForm    TWinControl   OnKeyDown, 
OnKeyUp  OnKeyPress,   KeyPreview  ,    
 .   KeyPreview  False,  
     ,    
.   ,      ,  
 .       True,  
  ,     ,   . 
      <>      
 ,     .  
       KeyPreview    
,      ^    
~ ~"~"                                                                 
             
    ,    
  .     
   (       ),  
     KeyPressed. 
            OnKeyDown, 
OnKeyUp  OnKeyPress    ""    
     OnKeyDown .    
    <F2>. 

    procedure  TForml.FormKeyDown(Sender:   TObject;   var Key:   Word; 
    Shift:     TShiftState): begin 
    {,        <F2>.} if Key = VK_F2  then {  
.} Close; end; 


    218                  //.   


      
           ,   
  KeyPreview  True! 

        ,   ,   
OnKeyDown  OnKeyUp    (     
WINDOWS . PAS). (     6, " )| 

    Menu 

        TMainMenu,    
 .  Menu    -   
  OLE-        
-.  . 8.7   Wordpad    
MediaClip.  ,         , 
   Media Player. 

    . 8.7.    -     Menu 

       Menu      (TMainMenu 
  ): 

    Menu := mnuMainMenu; 
    Position 
    Position     ,    
  . 

       (poDesigned)     , 
   .       
   Left, Top, Height  Width.      
,       ,  ,  
          
    . 
       poScreenCenter,     
   Width  Height,     Left  , 
     . 
       Position  poDefault, Windows  
    ,       
  .     200x200,  
   640x480. - ,  ,   
    MDI-. 
     poDef aultPosOnly  ,     
  ,     (    
MDI-,       ). 
      cBoficTBaT{poDefauTtSizeOnly)   
,    .     ,  
    ,    . 
      Position  ,    
 ,       
       __     
  .  , ,      
Registry   INI-,    ,    .  
           
  . 

    procedure TForml.FormDestroy(Sender:   TObject); var 
    sAppPath  :   String; 


     8.        219 


    iniSettings : TINIFile; begin                                              
    {   - .} 
    sAppPath := ExtractFilePath(Application.EXEName); 
    {  TINIFile.} 
    iniSettings := TINIFile.Create(sAppPath + 'SETTINGS.INI') 
    try 
    {   INI-.} 
    iniSettings.Writelnteger(Name,'Left',Left); 
    iniSettings.Writelnteger(Name, 'Top',Top); 
    iniSettings.Writelnteger(Name,'Width',Width); 
    iniSettings.Writelnteger(Name,'Height',Height); 
    finally 
    iniSettings.Free; end; 
    end; 

    Ha  
            uses  INIFiles. 
        INI-     

    [Forml] 
    Left=108 
    =174 
    Width=540 
    Height=165 

    ,       Name  . 
           (  
- ,    ,  INI- ). 

    procedure  TForml.Create(Sender:   TObject); const 
    cNOTFOUND  =   -1; var 
    sAppPath   :   String; 
    iniSettings   :   TINIFile;    
    liValue  :   EongTH^T 
    begin 
    (     -  .} 
    sAppPath   :=  ExtractFilePath(Application.ExeName); 
    {   TINIFile.} 
    iniSettings   :=  TINIFile.Create(sAppPath  +   'SETTINGS.INI1); 
    try 
    {   Left.} 
    liValue := iniSettings.Readlnteger(Name,'Left',cNOTFOUND); 
    {,   .} if liValue = cNOTFOUND then begin 
    {  INI-     .} 
    Left := (Screen.Width - Width) div 2; 
    Top  := (Screen.Height - Height) div 2; end else begin 
    {   INI-.} 
    Left   := iniSettings.Readlnteger(Name,'Left',Left); 
    Top    := iniSettings.Readlnteger(Name,'Top',Top); 


    220       II.   


    Height := iniSettings.Readlnteger(Name, 'Heighr' , Heignti ; Width  := 
iniSettings.Readlnteger(Name,'Width',Width); end; finally 
    iniSettings.Free; end: end; 

    WindowState 

       WindowState    
,   .      
wsNormal (     ,   
Position, Left, Top, Height  Width).     , 
  wsMinimize  wsMaximize. 

     TForm 

     TForm       
TWinControl.         
          
  . 
        ,    . 
    1.    OnCreate        
   .   ,     Position, 
         . 
    2.    OnShow       .  
         . 
       ,    OnShow,    , 
 Visible   True.                               
    3. OnResize         
.           
  ,    Align.  
OnResize     ^*6^111^
   . 

OnResize       . 
      

    4.    OnActivate      . OnActivate 
             
 .     Delphi  
 OnActivate   Application. 
    5.    OnPaint ,    .   
,      ,    
     .  ,   
 -   . 
     OnCreate        , 
     .  

     8.            221 

             . 
    1.    OnCloseQuery     ,  . 
    CanClose, ,   
  .      True,     
  False,   .   
         
.    . 

    procedure  TForml.FormCloseQuery(Sender:   TObject; 
    var CanClose:   Boolean); begin 
    CanClose   := MessageDlg('Close  form?',   mtConfirmation, 
    [mbYes,mbNo],   0)   = mrYes; end; 

    2.    OnClose     .  
        .  
 Delphi      Action,   
    : caHide, caMinimize, caNone  caFree.  
  -MDf-  caHid e,  .   
MDI-   ,  ,  caMinimize.  
Action   caNone,   . caFree  
Delphi         .    
   ,   . 
    OnClose           
   - Close, ^   
,         OnClose. 
 OnCloseQuery  ,     '. 
    3.    OnDeActivate      .  
    ,     OnActivate. 
    4.    OnHide    ,    . 

       OnHide   ,   Visible  
 False. 
      

    5.   OnDestroy     . 
     ,   OnCreate. 
? OnDestroy         , 
    .        



       

              
-  Delphi.  TForm   
,-   ,   .  
       .   
  Object Repository,        
    2, "  Delphi". 

      

      (Form Templates)     .  
     .  Delphi    
(Object Repository),       , 
  . 

    222                       .   


       

          . 
       .         .  
       . 
        Use.        . 
     ,   ,  . 
           ,   
 About box,  . 
    1.     File^New Application.   . 
    2.     File^New.    New Items. 
    3.      Forms   . Delphi  
  ,    . 8.8. 
    4.   ,      Use. 
    5.      .   About box     . 
        ,       
       -.   
Use             
^^^     Use. ~ 

       

           ,  
     .   
 -     ,     
   .          
(, ...),         . 
    1.    ,          
  . ,        
 . 
    2.       OB JREPOS Delphi. 

      
    Object Repository     ,    
_ DFM-  PAS-.     ~ . 
    
    3.             Add to 
Repository.   Delphi    Add To Repository, 
  . 8.9. 
    
    . 8.8.        

    . 8.9.    Add To Repository   
      

    4.     Forms  ,     . 
    5.         Title (    
       New Items). 
    6.       Page  ,    
 . 
    7.      ,      Object Repository. 

      //?/p/waw&VAw          223 

    Delphi        .  
  ,      Use.      } 

      

        ,       
Delphi. ,    Delphi ( ,   
 ,         ,   
     ). , ,    
          
.        . 
      (shared repository)      
,       .  
    ,   . 
    1.      Tools^Options,       
 Environment Options,   . 8.10. 
    2.       Preferences   . 
    3.       Directory    ,    
    . 
    4.      .      New Items Delphi 
      . 
         ,      
  . 

       

           ,   
     .    ,  
  Object Repository,   . 8.11.    
  Tools1* Repository. 
      Pages,     ,  
,     New Items.     
   Add Page, Delete Page  Rename Page. 

    . 8.10.  Shared Repository    
  

    . 8.11.    Object Repository     

            Objects , 
   .     [Object Repository], 
     .       
   Objects      Pages. 
     Edit Object     Edit Object Info, 
  . 8.12.         
 . 

    224    II.   

     Delete Object    ,      
 . 
    ,    ,   . 
 , New Form,   ,   
  . , Main Form,  ,   
      .   
       Objects   
 . 

    . 8.12.         
  Edit Object Info 

       ,   ,    
    New Project.    
5*,     . 

      

           
 Use  .          
    .      ,  
    .   Use    
  ,         . 
         ,  
    ,    .    
1.,    ,     Use. 

       

           .  
      ,   . 
    1.      File1* New Application.     . 
    2.      File^New,      New Items. 
    3.       Dialogs,     . 
    4.        Help,    
    . 
    5.                                     Inherit. 
    6.       ,  Delphi    . 
        OKHelpRightDlg2.  Delphi  
    OKHel-pRightDlg?     
.          Forml, 
OKHelpRightDlg, OKHelpRightDlg2  OKRightDlg.     
  OKHel-pRightDlg, Delphi         
 .         
OKHelpRightDlg2.        .   
, OKHelpRightDlg   OKRightDlg,     
  . 

     
     poflMTeflbCKMe_^ppMU,,QKHeipRightDig  OKRightDlg,   
  ,    ^  !  
',   Object Repository. 

          .  
 OKHelpRightDlg2  . 

    TOKHelpRightDlg2 = class (TOKHelpRightDlg) private 
    { .} public 
    { .} end; 

      
           . 


     8.   225 
    8  Delphi 3.   

         .    
   ,  , OKHelpRightDlg2    
 ,    .   TOKHelpRightDlg 
 . 

    TOKHelpRightDlg  =  class(   TOKRightDlg   ) 
    HelpBtn:   TButton; 
    procedure  HelpBtnClick(Sender:   TObject); private 
    (  .} public 
    {  .} end; 

       , OKHelpRightDlg      
OKRightDlg    HelpBtn  TButton,     HelpBtnClick. 

      . 

       ,      
            
   .    ,   
  .   . 
    1.      File^New Application,    . 
    2.      ,    Forml. 
    3.      File^New,      New Items. 
    4.       Dialogs,     . 
    5.      (Standard)   ,  
   . 
    6.      Inherit. 
    7.       ,  Delphi     OKRightDlg2. 
    8.       View=>Forms,      View Form. 
    9.       OKRightDlg,    ,  Delphi 
   ,  Dialog    
  . 
       .      
   Delphi.   ,    OKRightDlg2 
 ?    ,  Delphi   Left   
     . 
          .    
,   . 
    1.      View^Forms,     View Form. 
    2.     OKRightDlg2    . 
    3.     OKRightDlg2    . 

         ,   . 8.13. 

      -   -  
  ,        
.       4, "Object Pascal: 
 ". 

      SDI 

     SDI (Single Document Interface)    
   ,     
   .  Notepad,   . 
8.14,      . 
          .   
  , ..      , 
      .      
    .   
 Wordpad (. . 8.7),     OLE-   
.      SDI-,      
   (      ) Wordpad. 

    226                     II.   


    . 8.13.         
   

    . 8.14.  Notepad   SDI- 

             
   ,   ,  
   ( . 8.15      
Wordpad).      Delphi     
      FormStyle   f sSizeToolWin  
f sToolWindow. 
          Delphi     
, ,   ,  
  ...      SDl-,    
      . 

     8.         227 


    . 8.15.  Wordpad  SDI-    


     SDI- 

      SDI     . 
              
 EgSDIApp. 

      

           .  
       . 
    1.     File^New Application,    . 
      
    
    Delphi     SDI-.   
        . 
    2.      . 

        

    Caption    Image Viewer 
    Name       frmMain 
    ShowHint   True 

    3.     TPanel  .    . 

      

    Align alTop 
    Caption 

    4.      TSpeedButton  TPanel    
spbtnLoad, spbtnStretch  spbtnCenter.    . 

      

    spbtnLoad.Hint     Load 
    spEtrrnciSctTLerr" 8 
    spbtnLoad.Top 8 
    spbtnStretch.AllowAllUp True 


    228         II.   


    spbtnStretch.GroupIndex          1 
    spbtnStretch.Hint                     Stretch 
    spbtnStretch.Left       48 
    spbtnStretch.Top      8 
    spbtnCenter.AllowAHUp   True 
    spbtnCenter.Grouplndex     2 
    spbtnCenter.Hint     Center 
    spbtnCenter.Left     80 
    spbtnCenter.Top     8 

    5.       TPanel       . 
      
    Align alClient 
    Caption  


    6.      TImage    TPanel   
  . 

      

    Align alClient 
    Name imgMain 

    7.       TOpenDialog   . 

      

    Filter Bitmaps    (*.bmp) I *.bmp 
    Name opndlgLoad 
    Options [ofPathMustExist,ofFileMustEx 

    Delphi                     
TSpeedButton;             IMAGESXBOTTONS.    
    Glyph. 

      

    spbtnLoad.Glyph     FLDROPEN.BMP 
    spbtnStretch.Glyph FONTSIZE.BMP 
    spbtnCenter.Glyph PICTURE.BMP 

        ,     FileOSave 
Project As.  Unitl  Main, a    EgSDIApp. 
         ,    . 8.16. 

    . 8.16. SDI-       


      

    ,   ,      
 .     . 
    1.       spbtnLoad,  Delphi   
      OnClick. 

     8.       229 

    2.    . 

    if opndlgLoad.Execute  then 
    imgMain.Picture.LoadFromFile(opndlgLoad.FileName); 

     opndlgLoad. Execute      
.        ,   True  
   FileName     .    Cancel 
   <Esc>   False. 
     TImage   Picture,   
_ TPicture.       
," ~".    ^ 
LoadFrorr-File,       . 
      Run^Run        
 . ,   ? 
        . 
    1.       spbtnStretch,  Delphi   
      OnClick. 
    2.     . 

    imgMain.Stretch   :=   spbtnStretch.Down; 

     TSpeedButton   Down,   True   
.  Stretch  TImage   . 
            
 (   spbtnCenter)    : 

    imgMain.Center   :=  spbtnCenter.Down; 


      MDI 

     MDI (Multiple Document Interface)   
    ,    
     .   
     (File Manager),   . 8.17. 

    . 8.17. MDI- 

     MDI-         
.    FormStyle   f sMDIForm. 
     f sMDIChild. 
       ,   ,  
      ,  , 
  .       
  ,      ,     
  . 

    230      .   


      

     MDI-,  ,     
 .      ,   
     ,      
. Delphi    ,     
 . 

       

         Delphi     
           
.     Delphi   
 . 
           . 

    type 
    TForml   =  class    (TForm) 
    private 
    {  . } 
    public 
    {  . } 
    end; 

          TForml (   
   4, "Object Pascal:  "). 
      ,     . 

    var Forml: TForml; 

       Forml,     TForml  
   .        
  . 
          ,     
    View=>Project Source.    : 

    Application.CreateForm(TForml,   Forml); 

            
:   ,    , 
  .      - 
Application     . 

       

           SDI-, 
  MDI- ,  , . 
           Create  
.       TForml    
     Caption  'New Form'. 

    Forml   := TForml.Create(Application); Forml.Caption   :=   'New   Form'; 

     Create        
TComponent,      .    
  Application,        
  .      Nil,  
   (        " 
     .    
-1 ~   ,     
 " ... 
        Forml      
.     ,      
,      : 

    with TForml.Create(Application)   do Caption   :=   'New  Form'; 

    j,       MDI-  Show  ,  ^ Delphi 
  .    MDI-.   
SDI-     Show. 

     


     8.         231 

         Delphi     
   _ .    , 
 "  Project Options,   . 8.18,  
-    Auto-create forms. 

    . 8.18.   Project Options     
  

             , 
  MDIChildrer    . 

    MDI- TForm 

     TForm   ,   MDI-. 

    ActiveMDIChild 

         TForm,     
 .  ,      
  ,       . 
    , ,     ,  
 ,  -DailyNotes.       Tf 
rmMDIChild.     Clear   , 
   memDailyNotes    .   
 . 

    procedure TfrmMDIParent.spbtnClearClick(Sender:   TObject); begin 
    if not   (ActiveMDIChild = Nil)   then 
    if ActiveMDIChild  is  TfrmMDIChild then 
    TfrmMDIChild(ActiveMDIChild).memDailyNotes.Clear; end; T~~' 

       ,   AjbtiveMDIChild  Nil,  
         .         
    ActiveMDIChild  Ni?,        
FormStyle   fsMDIForm. 

     
     ActiveMDIChild   TForm,    
  memDailyNotes   Tf rmMDIChild.    
 , ..   ActiveMDIChild    
Tf rmMDIChild. 

       ?    Clear 
 memDailyNotes. 

    232        II.   


    MDIChildren  MDIChildCount 

     MDIChildren    TForm,  
    . MDIChildCount   
   MDIChildren. 
          -   
   .       
 Minimize All. 

    procedure  TForml.mnuMinimizeAllClick(Sender:   TObject); var 
    iCount   :   Integer; begin 
    for  iCount   := MDIChildCount-1  downto  0  do 
    MDIChildren[iCount].WindowState   :=  wsMinimized; end; 

             , 
   ,       
 MDIChildren   ^    
 . 

    TileMode 

        , ,    
     Tile.   tbHorizontal 
( )  tbVertical       . 
      . 8.19. 

    . 8.19.   TileMode    
   


    WindowMenu 

     MDI-    
 ,      .  WindowMenu  
 TMenuItem,  Delphi      
  . 
       TMenuItem     .   
  Caption,  swindow.  . 8.20   
  . 

    MDI- TForm 

     MDI-  OnActivate     
  .      -1-  
MDI-,   OnActivate  ,   
 Active      True.    
   : ,   OnActivate    
 ,           
  . 

    MDI- TForm 

      MDI-   . 
       Arrangelcons       
   . 
    *   Cascade    ,      . 

     8.      233 

       Next  Previous        ,   
   <Ctrl+Tab>  
    <Ctrl+Shift+Tab>.    Tile    ,    
 (     

    . 8.20). 

    . 8.20.   windowMenu      


     MDI- 

              
.         
 EgMDIApp. 

      

     MDI-       
SDI-,      ,     
.       . 
    1.      File^New Application,    . 
    2.     . 

      

    Caption Image  Viewer 
    FormStyle fsMDIForm 
    Name -                                                                     
    ShowHint True 

    3.     TPanel  .    . 

      

    Align alTop 
    Caption _ 

    4.      TSpeedButton  TPanel    
spbtnLoad, spbtnStretch  spbtnCenter.    . 

      

    spbtnLoad.Hint     Load 
    spbtnLoad.Left     8 


    234          II.   


    spbtnLoad.Top 8 
    spbtnStretch.AllowAHUp True 
    spbtnStretch.GroupIndex 1 
    spbtnStretch.Hint Stretch 
    spbtnStretch.Left 48 
    spbtnStretch.Top 8 
    spbtnCenter.AllowAllUp True 
    spbtnCenter.Grouplndex 2 
    spbtnCenter.Hint Center 
    spbtnCenter.Left 80 
    spbtnCenter.Top 8 

     Glyph   ,    SDI-. 

    5.       TOpenDialog     . 

      

    Filter Bitmaps    (*.bmp)|*.bmp 
    Name opndlgLoad 
    Options [ofPathMustExist,ofFileMustExist] 
    
       . 
    1.      File1* New Form,    . 
    2.      . 

      

    FormStyle fsMDIChild 
    Name TrmMDIChi. 
    Position poDefaultPosOnly 

    3.     TImage        
 . 

      

    Align alClient 
    Name imgMain 

             . 
    1.      Project^Options,     Project 
Options,   . 8.18. 
    2.     f rmMDichild   Auto-create forms. 
    3.       >.  f rmMDIChild      
 Available forms. 
    4.      . 
        ,   File^Save Project As. 
 Unitl  MDIParent, a    EgMDIApp. 

      

     ,      , 
       SDI-. 
      .       
OnClick  spbtnLoad. 

    procedure  TfrmMDIParent.spbtnLoadClick(Sender:   TObject); begin 
    if opndlgLoad.Execute  then 
    with TfrmMDIChild.Create(Application)   do begin       "                   
    Caption   := opndlgLoad.FileName; 
    imgMain.Picture.LoadFromFile(opndlgLoad.FileName); ClientWidth     :=  
imgMain.Picture.Width; ClientHeight   :=  imgMain.Picture.Height; end; end; 


     8.              235 

              
  .       
,      . 
          ,   . 
     Tf rmMDIChild,    
MDIChild,   implementation     : 

    uses MDIChild; 

           .  
, ,      Close,    
,    .    , 
     OnClose  Tf rmMDIChild  
    Action: 

    Action := caFree; 

     TSpeedButton Stretch  Center    ,    
SDI-,     OnClick   
 . 

    if not   (ActiveMDIChild = Nil)   then 
    if ActiveMDIChild  is  TfrmMDIChild  then 
    TfrmMDIChild(ActiveMDIChild).imgMain.Stretch   := spbthStretch.Down; 

     

    if not (ActiveMDIChild = Nil) then 
    if ActiveMDIChild is TfrmMDIChild then 
    TfrmMDIChild(ActiveMDIChild).imgMain.Center := spbthCenter.Down; 

          Stretch  Center  
   .         
OnActivate  TfrmMDIChild . 

    frmMDIParent.spbtnStretch.Down   :=   imgMain.Stretch; 
frmMDIParent.spbtnCenter.Down     :=  imgMain.Center; 

    , ,        MDIChild 
   implementation . 

    uses__MD_IParent ; 

,   : MDI- ! 

     
           Down  
TSpeedButton   -ciick.      
 ,       
 ,       . 

       

          ,     
        ! 
   ,        
.     ,     
  ,      DO S      
Windows API    ,     (    , 
   16-   640-   
 ). ,  Delphi    
,   32-     
         Windows API   . 
       ,     
         .   
   ,   "Hello, world!",    
 TLabel  ,     150 ,     
 "Hello, world!"   10... 

    236                              II.   


       

            "Hello, 
world!".          
EgConsoleHello.      . 
    1.      File^New Application. 
    2.      File^Remove From Project,    
 Remove From Project,   . 8.21. 
    3.         .      
 .    Save changes to Unitl .pas?. 
    4.       No,      . 
       EgConsoleHello. 

    . 8.21.   Remove From Project     
   

       "" ,      
  ^,,  ,     . 
  View1*Project Source,   "  . 

    program EgConsoleHello; 
    uses Forms; 
    {$R *.RES} 
    begin 
    Application.Initialize; 
    Application.Run; end; 

      ,   .  ,   
 Forms,    ,     . 
  Application       OLE-  
 .    ^^ ,    
.    ,     
, ,   .     
  $APPTYPE.      . 

    program EgConsoleHello; 
    {$APPTYPE   CONSOLE} 
    ($R  *.RES} 
    begin 
    end; 

    Ax !      !     
begin  end  WriteLnCHello,   world!'); 
    ,       . , 
 ?         
  -,  ,     
Read, ReadLn, Write  WriteLn. 

     Windows API    

           ,   
   .    40  Windows API  
  ,       
  . 

     8.         237 

      8.1  ,     . 
     i      EgConsoleTitle. 

     8,1.     

    program EgConsoleTitle; 
    {$APPTYPE  CONSOLE} 
    uses 
    Windows,   SysUtils; 
    {$RTKE5T~..... 
    sNewTitle, sErrMsg : String; begin 
    sNewTitle  := 'Welcome to Console World'; 
    if not SetConsoleTitle(PChar(sNewTitle)) then 
    begin 
    sErrMsg := 'Unable to set caption - '+SysErrorMessage(GetLastError); 
    MessageBox(0,PChar(sErrMsg),'Error',MB_ICONEXCLAMATION+MB_OK); end; 
    ReadLn; end. 

      API SetConsoleTitle  False,    
 . GetLastError     
 API,  SysErrorMessage       . 

      
      Delphi    Win32   
 API.       Console Reference   
  . 

       

     Object Repository    ,   
  (        
)~ ^^, ,    
         . 

       

    Delphi     . 
     MDI Application    MDI-. 
   ,  Speed Button   . 
    ,      
   . 
     SDI Application   SDI-.    
,  Speed Button   .     
  About    . 
     Win95 Logo Application  ,   , 
  Microsoft   Win95 Logo certification. 
EcJ?2??r^r^e     Microsoft,    
^25]?^ fprJ|Vjn95". 
       SDI-     
 . 

    238       II.   

    1.      File^>New,     New Items 
(. . 8.8). 
    2.       Projects,     
 . 
    3.      SDI Application,    ,  
   Select Directory,   . 8.22. 
    4.        . 
        , Delphi    . 

    I  ] 

    5.      ,     . 
      
          .    
             
  . 
      Projects      Application Expert. 
 ,   . 8.23,      
  . 

    . 8.22.   Select Directory    . 8.23. 
Application Expert           

      
           ,    
,         ! 

       

     , , ,     . 
     Object Repository  . 
    1.     ,         . 
    2.     .    " ",  
  ,     . 
    3.      Projects Add To Repository,    
   Add to Repository,   . 8.24. 
    4.      ,    ,   
   Object Repository   . 

    . 8.24.   Add to Repository   
    Object Repository 

     8.         239 


      

       ,     
 .   <    Project 
Options (. . 8.18). 
          ,   
Default       Project Options. 
     

    Forms 

      Main form     
,  Delphi    ,   
 . 
     , Auto-create forms  Available forms,   
  .       
" ". 

    Application 

     Title    ,    
 (, Delphi      ).   
  ,   ,    (DELPHI32). 
     Help file   ,    , 
     . 
     Load Icon    ,  
        . 
       , Target file extension,   
    (DLL     
, OCX    ActiveX  ..).      
,   Delphi     . 

    Compiler 

         , 
   .    , Show 
hints  Show warnings,     (    
  ,    
 ). 

    Linker 

     Map file    ,   
 ,   ,   
  .. 
    Linker output ,       Delphi 
Compiled Unit (DCU)    (OBJ).   , 
       (  
30, " Delphi  C++"). 
       DLL    ,   
 "  ",    ,  
     27, "  ". 
    Memory sizes       
        DLL.  
         
,   .     ,   
    ,   . 
    EXE Description       DLL  
  (-  "MixFix () 1993-1997 KIV without Co"). 

    Directories/Conditionals 

     Output  Unit output ,     
 DLL,    .    , 
     ,    ,  
    DLL    . 

    240                II.   

    Conditional defines  ,      
,  ,         
 . 
    Unit Aliases       Delphi ( 
   Windows           
       Windows  ). 

    Versionlnfo 

     Versionlnfo        
DLL    Major Version, Minor Version  File Description. 
        Auto-increment build 
number,  Delphi        . 
     Module Attributes   ,   Debug Build, 
 .           
   . 

    Packages 

     Packages  ,     
   ,      
 . 
     Design packages    , 
      . 
     Runtime packages   ,   
      .   
 Build with runtime packages ,__ ,    
 VCL 6^^1^__ .   ,   
      D elphi   . 
      15, "  ". 

       

    ,          
       ,  
  "   ",  ,     
 TApplication  TScreen.      
        
   

     TApplication 

     TApplication    . Delphi 
   Application  TApplication   
.       Forms   uses. 

     TApplication 

    TApplication   ,     
        . 

    Active 

        True,       
  .  Active    True,   
 Active       True.    
 ,     ,    
    TCanvas. 
    
      

    EXEName 

        ,    
  (    argv [0]).      
   ,      
'  ''. 

     8.                 241 


       EXEName     
ExtractFilePath  Extract- 1   FileDir   SysUtils. 

    Hint  ShowHint 

      _1__? ,      
 OnHint. 
     ShowHint   , ^  " 
".    False      
       .   
    ,    . 
  . 

    procedure TForml.mnuToggleHintsClick(Sender:   TObject); begin 
    (   .} 
    mnuToggleHints.Checked   :=  not mnuToggleHintsChecked; 
    (    ShowHint.} 
    Application.ShowHint   := mnuToggleHints.Checked; end; 
    HintColor, HintPause, HintHidePause  HintShortPause 
    HintColor     ,  
    Application.HintColor   :=  clLime; HintPause  HintHidePause  
      . 

    1.        TControl. 
     OnHint         TControl. 

      
    2.    Delphi  HintPause     . 
    3.      TControl. 
    4.   Delphi  HintHidePause     . 
     HintShowPause     , 
    . 

    Icon 

     Icon   ,    
    .  ,     
   .      
 INACTIVE.ICO: 

    Application.Icon.LoadFromFile('INACTIVE.ICO'); 
    Title 

         . 

     TApplication 
    Minimize  Maximize 

            .  
 ,       WindowState 
 TForm.         ,  
   .        . 

    242             II.   


    ProcessMessages 

          .  
 , ,   ,     
  . ,      

    while  not Application.Terminated do 

          ,      
      .  ,   
  ,      .        
 *       : 

    while  not Application.Terminated do Application.ProcessMessages; 

           
 , -  TThread.    
~!, " ^9."""""" 

    Terminate 

          . Terminate  
  ,       
  .      File1* Exit. 

    procedure  TForml.mnuFileExitClick(Sender:   TObject); begin 
    Application.Terminate; end; 


     TApplication 
      TApplication 

       TApplication ,    
  -     
(Object Inspector). 
      2, "  Delphi",     
,          
,       Object Inspector. , 
  Object Inspector  ,     . 
       .     
 ,     .    
    ,      
. ,     "  OnActivIte 
 TNotifyEvent    . 
        : 

    TNotifyEvent  = procedure   (Sender:   TObject)   of Object; 

        ,       
TObject,   ,       . 
          TForml. 

    type 
    TForml   =  class(TForm) private 
    {  .} 
    procedure  OnActivateHandler(Sender:   TObject); public 
    {  .} end; 

       protected        
.  ,     . 
    6   


     8.         243 

    ,    ,  .    
  implementation  . 

    procedure  TForml.OnActivateHandler(Sender:   TObject); begin 
    {   .} end; 

            
,       .      
    .   
    ,^^^^^ .      
OnCreate  .    OnCreate  TForml 
 . 

    procedure  TForml.FormCreate(Sender:   TObject); begin 
    Application.OnActivate   :=  OnActivateHandler; end; 
    OnActivate  OnDeactivate 

           Active. 

    OnException 

         .   
     5, "  ". 

    OnHint 

             
TControl,    Hint  ,     . 

    Onldle 

     ,        
 .        
      . 
        Done,    True. 
     True.      ,  
      .    -Done 
 False,       . 
            
,           
 ProcessMessages. 
              
 TPanel. 

    procedure  TForml.OnldleHandler(Sender:   TObject;   var  Done:   
Boolean); begin 
    pnlTime.Caption   :=  TimeToStr(Now); end; 


     TScreen 

     TScreen      . Delphi 
       Screen.   
   uses    Forms. 

    244               II.   


     TScreen 
    ActiveControl 

        TWinControl,   .  
     Copy, Cut  Paste   
 .  ,    TMenuItem, 
  . 

    procedure  TForml.mnuEditCopyClick(Sender:   TObject); begin 
    Screen.ActiveControl.Perform(WM_COPY,0,0); end; 

    ,     Windows,   .  
 -        /   ^ 
  .         
  WM_c65y] 

    ActiveForm 

        TForm,   .   
,  ,         
 .        
  ,    .  
Windows API,    ,   ' : 

    FlashWindow(Screen.ActiveForm.Handle,False); 


    Cursor 

            .  
     ,    ,  
    ,  ,  . 

    {      .} Screen.Cursor   :=  crHourglass; 
    try 
    {    - .} for iCount :=1 to 1000000000 do; 
    finally 
    (  .) 
    Screen.Cursor   :=  crDefault; end; 

           TControl ( 
TForm) .  

     

    Forms  FormCount 

           .     
       ,    
"MDIChildren  MDIChildCount". 

    Height  Width 

       ,       
.      ,    
 .       . 

    Left   :=   (Screen.Width  -  Width)   div  2; Top   :=   (Screen.Height  
-  Height)   div 2; 


     TScreen 

    TScreen    ,    
  .    TApplication,  
 TScreen    .     
    ,   
"  TApplication". 

     8.         245 


    OnActiveControlChange 

              
  . CBOHCTBI ActiveControl    
 .    ,     
   . 

    procedure TForml.ActiveControlChangeHandler(Sender:   TObject); begin 
    if   (not  Application.Terminated)   then 
    pnlStatus.Caption   := ActiveControl.Hint; end; 

       ,       
,          
 .'                                                      
                                                                               
    OnActiveFormChange 

               
   .      MDI-  
     -.    
  MDI-. 

    procedure  TMainForm.UpdateMenuItems(Sender:   TObject); begin 
    FileCloseltem.Enabled     :=  MDIChildCount   >   0; 
    FileSaveltem.Enabled        :=  MDIChildCount  >   0; 
    FileSaveAsItem.Enabled   := MDIChildCount   >   0; 

     UpdateMenuItems      
OnActiveFormChange   

    OnCreate. 
    procedure TMainForm.FormCreate(Sender: TObject); begin 
    Application.OnHint := ShowHint; 
    Screen.OnActiveFormChange := UpdateMenuItems; end; 


       

       ,       
.     -_, , , TNotifyEvent  
Onclick  TCloseEvent  OnClose. ɸ    - 
      . 
       TEdit,   OnKeyDown  OnKeyUp. 
     ,       
  .        
 (   ). , ,     
   OnCreate  OnClick. 
              
   ,       
 . 
          TButton  TEdit  OnClick. 
    1.       File^New Application   . 
    2.    TButton       OnClick  . 
    procedure  TForml.ButtonlClick(Sender:   TObject); begin 

    Editl.SetFocus; 
    Editl.SelectAll; end; 

    3.    TEdit  .  Object Inspector     
 OnClick  ButtonlClick. 
            TEdit     
          TEdit  
     . 

    246                II.   


     Sender 

           , 
  ,     .   
  Sender,    ,  
  ,  .     
       ,    . 

       

      Windows      ,  
     .   , ..  
    ,     
 . 

        

        Windows     
 (window class name). Delphi       
 , ,  Delphi   Forml  TForml, 
TForml        Forml.   
  Caption,     (window title).   
       Windows API FindWin-dow, 
   . 
          TForml,       
        ,   .  , 
     . 

    begin 
    Application. Initialize/
    if FindWindow('TForml','Forml'; Application.Terminate; 
    <>   0   then 
    Application.CreateForm(TForml,Forml); Application.Run; end. 

        Windows API, ,   
  Windows. 

      
          Delphi, ,  Form Designer  
        .    
 ,  Delphi. 

      Caption  Name,        
    ,    .  
 ,      ,    
    ,     . 

       

    -,   "    ,    
 !" - ...     
       Windows API  
SetForegroundWindow.    . 

    var 
    hwndPrev : HWND; begin 
    Application.Initialize; 
    hwndPrev := FindWindow('TForml','Forml'); 
    if hwndPrev <> 0 then 
    begin 
    SetForegroundWindow(hwndPrev);   
    Application.Terminate;         ? end,'   ~"  ""   ""     
    end. 
    Application.CreateForm(TForml,Forml); Application.Run; 


     8.          247 


     

              
Delphi   TForm.    ,   ,  
        Object Repository. 
            SDI, MDI  ;  
     MDI-   
Windows API   .  ,  ,   
      Object Repository   . 
     ,       TApplication  
TScreen      Application  Screen. 
    , ,         
      Windows API. 

    248      II.   

