           V 

      OLE 

    18.   OLE,      ActiveX 
    19.     
    20.  OLE 
    21.    ActiveX 

                  18 

      OLE,   i    ActiveX 

      


       OLE 

     OLE    . 

         

       OLE  . 

        

      OLE    . 

          OLE 

         Custom Insert. 

         

         OLE. 

      OLE 

      OLE   . 

         

       . 

        

       

      OLE   ,      , 
        .  
   OLE     ActiveX,  Delphi 
    ActiveX      
,    VCL. 
       ActiveX      
 OLE,  OLE   OLE.     
 -    ActiveX   . 
  ActiveX   ,   
     Delphi.  , 1,h;  
 OLE   .  Delphi   
   TOleContainer.      
      ,    
.           
OLE   ActiveX.      OLE. 
     Delphi 2  TOleContainer      Delphi 
I.         Delphi (Delphi 3). 
    TOleContainer   
  Active Document. 

    404 

          ,    
 OLE.         
,     OLE   ActiveX.  
  OLE     ,   
      . 

      OLE 

      ,  ,    , 
    ActiveX,     
    OLE.     
  ,     
    .  OLE   
          
    . 
      OLE  ,   Delphi,  
   (code reusability).  ,  
 OLE-,    ,   Delphi  
         OLE. 
       OLE   
    .  ,  
     ,   
Excel,   ,   Word,    
     . 
    Delphi      ActiveX  
.      ActiveX    21, 
"   ActiveX". 
       ActiveX  .     
    VCL,     .     
    ActiveX   (package)    . 
      Delphi      
 ActiveX.        
 .   Win95    OLE, 
   -.  ,   ActiveX 
   Internet.       VCL,  
   ActiveX     . 
  VCL  ,    OLE,   
   OLE         
 , ..    ,  
   ActiveX. 

      OLE 

        OLE?        
,    ,   .   OLE 
 ,      (Object 
Linking and Embedding)    (Component Object Model).   
    OLE (OLE 1.0)    
,         
    .   OLE 
     ^    . 
    ̗   API,     -. 
       , 
   . ,    ,  
    VCL,       . 
                
.        
  .  Microsoft   
 ,     OLE.    
      OLE,  , 
,    OLE,     
      OLE. 
        OLE  ,    
,    .   OLE 1.0  
   OLE    ,   
    .     
     .     OLE 
  3,  OLE 2.0   . 
        OLE     
       OLE    . 
 ,      OLE,     
    .       
RESUME.   OLEDB. ,      . 

     18.   OLE,      ActiveX   405 

    ActiveX     OLE.     
  ActiveX,     .   
          
 Internet,    ActiveX     
  . ,    " 
  ActiveX",     
    DBMemo. 

        OLE 

     (linking)     OLE  
 OLE.       ,  
 OLE   .   OLE     , 
       . 
    "!  Word     (BMP-)   
  OLE   '   .     
  OLE,  ,   OLE  -     
 . 
          ,   
,  OLE       
 . ,      
        ,    
.    OLE ,  .  
   ,      , 
    . 
    ' '" (emEeddIng)~o6beKTOB"'- ^ ..,  
    OLE.      
       OLE     
 .   OLE       
  ^  , 
     ,   ,    
     .                    
    ",   ,    
  ,       ,  
  OLE      oro 
.  ,    ,     . 
           OLE    
      ,    
SaveToFile  OLE    . .   ^ 
         ?     
 OLE     .    
,    ,       
 . 

      ? 

       . 
     ,      OLE     
  ,   . 
           . 
       ,         
 . 
         . 
       . 
            . 
      . 
    I  ,         
 . 
        ,      
      OLE. 
    !       . 
        . 
         ,  
      OLE. 

    406                                            V.   OLE 


     TOIeContainer 

     TOIeContainer    OLE   
VCL,     .     
 OLE         
 ."* 
        TOIeContainer,  ,    ,  
    ,   TOIeContainer  
     .     : 
TOIeContainer    .      , 
     .     ,  
,        TOIeContainer.   
   TOIeContainer ,     
  . 
     Delphi 3  TOIeContainer   ,   
    .      
      Microsoft Word   
   .    Microsoft Office 97  
    ,    . 
        ,  
 (binders).          
  .       (icons)  
 .         
        . 
     TOIeContainer      OLE  
.         OLE,  
         
InsertObjectDialog (. 18.1).    OLE  
    CreateObj ect, CreateLinkToFile  
-      OLE. 
    

    . 18.1.  ,    
TOIeContainer    


    TOIeContainer     ,      
   . 
         TOIeContainer  .   
    OLE. 
      (cut)   (paste)  OLE    Windows. 
          (iconic) .   
  OLE    . 
       OLE. 
       DoVerb. 
        OleProperty.     
Insert Object. 

     18.   OLE,      ActiveX   407 


      TOIeContainer 

      TOIeContainer     AllowActiveDoc.  
     ActiveDocument.   
AllowActiveDoc   True,      
 . 
     . 18.1-18.3   ,   , 
   TOIeContainer      
   . 

     18.1.   TOIeContainer 

      

    CreateLinkToFile       OLE 
    CreateObj ect      OLE 
    CreateObj ectFromFile    OLE     
,      
    CreateObj ectFromInfo     ,  
   Tcreatelnfo 
    DestroyObject          
    DoVerb   OLE      
    GetIconMetaPic    (Global Handle) 
  OLE. - j      | 
    InsertObjectDialog    Insert Object.   
  ,     OLE 
    ChangeIconDialog      OLE 
    PasteSpecialDialog      
   Windows   I 
    ObjectPropertiesDialog     
   OLE 
    LoadFromFile   OLE    
    LoadFromStreaiti   OLE   
    SaveToFile   OLE    
    SaveToStream   OLE   j 
    Copy        Windows 
    Paste      Windows   
    Run   OLE   osRunning 
    UpdateObj ect   ,  ,   
   | 
    UpdateVerbs   ,   OLE   j 
    SourceDoc       OLE j 
    State   OLE (osEmpty, osLoaded, osRunning, osOpen, osin- ! PlaceActive,osUIActive) 
    Storagelnterface  I storage  OLE | 


    408  V.   OLE 


    1  18.2.   TOIeContainer 

                   

    AllowInPlace	 ,       , 
    False 
    AllowActiveDoc	     True,  TOIeContainer 
    ,      
  
    AutoActivate	    OLE   
(aaManual  - , aaGetFocus   
 , aaDouble-Click     ) 
    Align	         alClient 
    CanPaste	,          
     
    CopyOnSave	     True,     
OLE,         
  
    Iconic	     True,     
  .       
  OLE 
    Linked	       True 
    ObjectVerbs	  ,    , 
     
    OleClassName	   OLE 
    OleObject	   OLE (OLE Automation),  
     OLE 
    01eObjectInter face	  lOleObj ect   OLE. 
 IQleObj ect      API OLE    
    Modified	  True,    ,   
   
    Newlnserted	  True,   OLE    
   Insert Object,      4) 
     
    OldStreamFormat	      
 OLE 1.0.     
    SizeMode	   OLE   (smClip, smCenter, 
smScale, smStretch,smAutoSize) 
    

     18.3.   TOIeContainer                                 

               

    OnObj ectMove     ,     OLE 
    

     OnObj ectMove     TOIeContainer. 
       
    (      
  OLE),     .    
  BoundsRect   ,    Bounds 
 ,         
.       OnObj ectMove. 

    procedure Tformi.OleContainerlObjectMove(OleContainer: TOIeContainer; 
    const Bounds: TRect); 
    begin 


     18.   OLE,      ActiveX   409 


    //  ,     
    //   . 
    with Bounds do begin 
    if Left < 100 then Left := 100 
    if Right < 100 then Right := 100 
    end; // with 
    OleContainerl.BoundsRect := Bounds; 
    end; // Tforml.OleContainerlObjectMove 


       OLE 

     TOle-Container      OLE  
.         OLE,  
        InsertObjectDialog. 
      ,   . 
    1.     Delphi. 
    2.   TOleContainer   System   . 
    3.          .   
   Insert Object (. 18.2). 
    
    , 18.2.   Insert Object 

    4.   Object Type   Bitmap Image     . 
    5.    .  -,  
    Paint   .    
   (. 18.3). (,    , 
  .) 
    6.   .   OLE   
,      Paint.   ,  
,  ,     ,  
   . 

    . 18.3.     Paint 
    

    410                                    V.   OLE 

           Paint  - 
|Ill!'lI!''ff^gli^^ . ,    . 18.4,  
   ^ 1 OLE     
ObjectPropertiesDialog. ; 
               - 
lllAateBitmap image     Object Properties. 

    . 18.4.      Paint 

      ObjectPropertiesDialog        
 , : 

    Procedure TFormI.ButtonlClick(Sender: TObject); 
    begin 
    with OleContainerI do 
    if ObjectPropertiesDialog then 
    ShowMessage('  OLE '); 
    //    ,   . 
    end; //Tforml.ButtonlClick 

       OLE   TOleContainer    
,   CreateObject,     
 OLE   CreateLinkToFile. 
    ,         TOleContainer.  
    ,   .   
  ,   Windows    
    OLE,      
 .        
  .    ,   
 . 

    Procedure TFormI.ButtonlClick(Sender: TObject); 
    begin 
    with OleContainerI do 
    if InsertObjectDialog then 
    DoVerb(ovShow) ; 
    else 
    ShowMessage('An object MUST be specified'); 
    end; // TForml.ButtonlClick 

     OLE     . ,  
  OLE    CreateObject    
  (Progid)    (  )   
.   -    
: Paint. Picture  Pbrush,      
.  ,  ,   Paint    
 ,     OLE. 

    CreateObject  Paint.Picture', False) ; 

      (Progid}        
  OLE (CLSID) .     
   .       
    OLE. 
             
  InsertObjectDialog  ObjectPropertiesDialog.  , 
         . 
       
InsertObjectDialog,         . 

     18.   OLE,      ActiveX   411 

     ,  ,    OleDB  
    Insert Object.    
         
.        
Tdlgln1"! sertableOleObj . GetInsertableObjects,     
 18.1. 

     18.1. \UDELPHl3\CHPl8\OLEDB\lnsertable01eObju.PAS.   
   Insert Object 

    procedure TdiginsertableOleObj.Getln5ertable0bjects(OLENames, Proglds: TStrings); 
    var 
    i: integer; 
    OleType, CLSID: String; 
    KeyNames: TStrings; 
    begin 
    //         , 
    //      OLE. 
    KeyNames:= TStringList.Create; 
    try 
    with TRegistry.Create do 
    try 
    RootKey := HKEY_CLASSES_ROOT; 
    if not OpenKey('\', False) then exit; 
    GetKeyNames(KeyNames) ; 
    with KeyNames do 
    for i := 0 to count - 1 do begin 
    CloseKey; 
    RootKey := HKEY_CLASSES_ROOT; 
    if OpenKey(Strings[i], False) then begin 
    if KeyExists('Insertable') then begin 
    OleType := ReadString(''); 
    OpenKey('CLSID', False); 
    CLSID := ReadString(''); 
    CloseKey; 
    if OpenKey('CLSID\' + CLSID, False) then begin 
    OLENames.Add(OleType) ; 
    if OpenKey('Progid', False) then 
    Progld.Add(ReadString('') ) 
    else 
    Progld.Add(' [NO PROG ID] '); 
    end; // if CLSID 
    end; // if 
    end; // for 
    end; // with KeyNames 
    finally 
    Free ; 
    end; // try 
    finally 
    KeyNames.free; 
    end; // try 
    end; // TdiginsertableOleObj.GetInsertableObjects 

     GetInsertableObjects        
 ,         
    Insertable.    ,    
   ,  ,   ,    
   .       
CLSID,    . 

    412                                            V.   OLE 


          

           ,   
    insertObjectDialog,   .  
  . -, ,      
   -   Windows,    
TRegistry   . 
        createObject ,     
 (Progid).  ,  RootKey   
HKEY_CLASSES_ROOT   ,        
      .      
     ,     
.      ,   
   RootKey. 
        ,      
 InsertObjectDialog,      (CLSID), 
     progid.     
,         
InsertObjectDialog.       ,  
    InsertObjectDialog.  ,     
   insertable, ,    ,  , 
    ,     
InsertObjectDialog,      CLSID  
HKEY_CLASSES_ROOT,     insertable.    
 ,        
InsertObjectDialog.      
,   insertable,     
(Progid)   (CLSID)  . ,    
 insertable   . 

    HKEY_CLASSES_ROOT 
    AVIFile 
    CLSID                                      {00022602-0000-0000-COOO-00000000046) 
    Compressions 
    Defaultlcon 
    Extensions 
    Insertable 

    ,      (CLSID),   
 ,      AVIFile. 
        (, BMP  DOC),  
    ,       
 .         
  .         
  ,      . 
     ,       
.       ,  
  .       
      

    MiDiSequence 

    Netscape Hypertext Document                    : 

       .   ,    
-   5^!1^ image       , 
             
 .     ,  
  .18.5,       
 . 

    WordPad Document 
    Video Clip 
    MIDI Sequence 
    Media Clip 
    Netscape Hypertext Document 
    
    . 18.5.    Insert New Ole Object 

       18.2       
InsertableOleObjeU.     . 

     18.2. \UDELPHl3\CHP18\OLEDB\lnsertable01eObjU.PAS.   
        OLE,   
   

    unit InsertableOleObjU; 
    interface 
    uses 


     18.   OLE,      ActiveX   413 


    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
StdCtrls, ExtCtrls, Buttons, Mask, DBCtrls; 
    type    ! 
    TdlgInsertableOleObj = class(TForm) 
    Paneil: TPanel; 
    ListBoxl: TListBox; 
    Panel2: TPanel; 
    btnCancel: TBitBtn; 
    BitBtn3: TBitBtn; 
    procedure FormCreate(Sender: TObject); 
    procedure ListBoxIDblClick(Sender: TObject); 
    procedure BtnCancelClick(Sender: TObject); 
    procedure FormShow(Sender: TObject); 
    procedure GetInsertableObjects(OLENames, Progid : TStrings); 
    private 
    Proglds: TStrings; 
    public 
    Selected_ProgId : String; 
    end; 
    var 
    dIgInsertableOleObj: TdlgInsertableOleObj ; 
    implementation 
    uses Registry, OLEDBU, OLEu; 
    {$R *.DFM) 
    procedure TdlgInsertableOleObj.GetInsertableObjects(OLENames, Progid : TStrings); 
    var     ; 
    i: integer; 
    OleType, CLSID: String; 
    KeyNames: TStrings; 
    begin 
    KeyNames:= TStringList.Create; 
    try 
    with TRegistry.Create do 
    try 
    RootKey := HKEY_CLASSES_ROOT; 
    if not OpenKey('\', False) then exit; 
    GetKeyNames(KeyNames) ; 
    with KeyNames do 
    for i := 0 to count - 1 do begin 
    CloseKey; 
    RootKey := HKEY_CLASSES_ROOT; 
    if OpenKey(Strings[i], False) then begin 
    if KeyExists('Insertable') then begin 
    OleType := ReadString('') ; 
    OpenKey ('CLS-ID', False); 
    CLSID := ReadString(''); 
    CloseKey; 
    if OpenKey('CLSID\' + CLSID, False) then begin 
    OLENames.Add(OleType) ; 
    if OpenKey('Progid', False) then 
    Progid.Add(ReadString('') ) 
    else 
    Progid.Add(' [NO PROG ID] '); 


    414                                            V.   OLE 


    end; // if CLSID 
    end; // if 
    end; // for 
    end; // with KeyNames 
    finally 
    Free; 
    end; // try 
    finally 
    KeyNames.free; 
    end; // try 
    end; // TdlgInsertableOleObj.GetInsertableObjects 
    procedure TdlgInsertableOleObj.FormCreate(Sender: TObject); 
    begin 
    Proglds := TStringList.Create; 
    end; 
    procedure TdlgInsertableOleObj.ListBoxIDblClick(Sender: TObject); 
    begin 
    Selected_ProgId := Proglds[ListBoxl.Itemlndex]; 
    ModalResult := mrOk; 
    end; 
    procedure TdlgInsertableOleObj.BtnCancelClick(Sender: TObject) ; 
    begin 
    Selected_ProgId := ''; 
    ModalResult := mrCancel; 
    end; 
    procedure TdlgInsertableOleObj.FormShow(Sender: TObject); 
    begin 
    Selected_ProgId := ''; 
    GetInsertableObjects(ListBoxl.Items, Proglds) ; 
    end; 
    end. 

        TOleContainer      
DOC  BMP    CreateObjectFromFile. , 
   18.3,        
  TOpenDialog   CreateObjectFromFile.   
   TfrmMain. LoadEmbeddedlClick    
  . 

    1  18.3. \UDELPHl3\CHPl8\OLEDB\OLEDBU. PAS. ,  
  TOleContainer       ! 

    procedure TfrmMain.LoadEmbeddedlClick(Sender: TObject); 
    var S: String; 
    begin 
    if OpenDialogI.Execute then 
    Form2.OleContainerI.CreateObjectFromFile(OpenDialogI.FileName, 
    IconViewl.Checked); 
    end; 

     TOleContainer      OLE  
 .         
OLE.        
    Insert66jectDialog.    OLE 
     CreateObject, 
CreateLinkToFile  -      OLE. 

     18.   OLE,      ActiveX   415 


      OLE 

             
  ,       .  , ,   
,     ,    
.     ,      
  InsertObjectDialog.       
  (BMP)      Delphi 3. 
    1.     Delphi. 
    2.      System   TOleContainer. 
    3.  TOleContainer        . 
     Insert Object (. 18.6) 
    4.   Create From File    Link (. 18.7). 
    5.            
Browse.   ,       
Windows.    .      . 

    . 18.6.   Insert Object      

    . 18.7.   Insert Object   

     . 18.8       : \WIN\WAVES . BMP. 
             .  
  ,       . 
   TfrmMain. LoadDocument,    18.4, 
     . 

    . 18.8.  ,   WAVES . BMP,   
  

     18.4. \UDELPHI3\CHP18\OLEDB\OLEDBY. PAS.     
                  j 

    Procedure TfrmMain.LoadDocument(FileName: string; Embedded: Boolean); 
    begin 
    with OleContainerI do begin 
    if Embedded then 
    CreateObjectFromFile(FileName, false) 
    else 
    CreateLinkToFile(FileName, false); 
    M" DoVerb(ovShow) ; 
    end; //with 
    end; // TfrmMain.LoadDocument 


    416                                            V.   OLE 


           

               
 OLE. !         
 ?    ,  . 
    1.   TOleContainer        
 Align  alClient.  AutoActivate   aaGetFocus. 
    2.        ,  
    Word. 
    3.      Paint    
  Word.    . 
    4.    .      
  . 
       OLE    . 
     AutoActivate      : aaManual, 
aaGetFocus  aaDoubleClick.      aaDoubleClick. 
   ,       
OLE      . 
     aaGetFocus (      ) 
     OLE   
  . 
       aaManual      
       . 
      ,      ?    
   .   "    
 TM'afnHenu,    Standard  . 
    .     
 Paint.           
 " ". 
      OLE       ,   
 "" (  Microsoft Word)    . 
      OLE,   
        I  6.' OLE, 
  ,     OLE 
   .     , 
    ,    
  OLE.     ,   
 Locked    True. 
        . 
    5.  Align  TOleContainer   aINone. 
    6.      .     
 (alTop)   ,    (alBottom). 
    
    . 18.9.    ,    OLE 

    . 18.10.    ,    OLE 

    7.   True   TPanel. Locked  , 
    . 
    8.   alClient   TOleContainer .Align. 
          ,    . 
18.9.   .    ,   . 18.10. 

     18.   OLE,      ActiveX   417 
    14  Delphi 3   

         Iconic  TOleContainer 
  True,         
.     ,   OLE  
     .  , 
   OLE,       
'   OLE     Iconic. 
  ^  Sound Object,   
    Microsoft Sound Recorder, 
     . 
             
(binders),        ,   
   ( 1 Left). 
             OLE.  
  , ,   ,    
 OLE,        
 OLE.         
  OLE. 

    procedure TFormI.FormShow(Sender: TObject); 
    begin 
    //  . 
    with TPanel.Create(self) do begin 
    Parent :="self; " """- 
    Align := alTop; 
    end; // create TPanel 
    //  . 
    with TMainMenu.Create (self) do begin 
    Parent := self; 
    end; // create TMainMenu 
    //   OLE. 
    with TOleContainer.Create(self) do begin 
    Parent := self; 
    AllowInPlace := True;        //  . 
    AutoActivate := aaGetFocus; //   
    //   . 
    Align := alClient; 
    //    . 
    CreateObject Paint.Picture', false); //  . 
    Iconic := False;                      //   . 
    //     . 
    SetFocus; 
    end; // with TOleContainer create 
    end; //TFormI.FormShow 


      

          ,    OLE 
   TMainMenu,        , 
   TOleContainer.        
OLE.  , ,      File   OLE  
 File,          
File. TOleContainer       
      OLE. 
       Grouplndex      
 .   (       Grouplndex, 
 0, 2  4,  ,  ,    
Grouplndex  1, 3  5,       OLE. 
 ,   MDI-   Grouplndex 
  . 18.4. 

     18.4.      Grouplndex 

                   Grouplndex                 
 Grouplndex 

    File                0                              Window              4 
    Edit                1                              Help                  5 
    Object              2 


    418                                            V.   OLE 


    ,   File, Object  Window  ,  
  Edit  Help      OLE.            
                                                    ; 
    ,. 3   Group.IiidQx.He  (  
   ). 

    . 18.11.        Word 

    . 18.12.        Word 

     . 18.11  18.12       .   
         . 

             OLE 

             Delphi 
  ,        Windows.   
      .    
  Copy, Paste  PasteSpecialDialog. 
     Copy  Paste    TOleContainer  ,    
  Delphi.      OLE  
,   OLE ,   ,    
,   .    CanPaste    
  ,     OLE  . 
      Paste     ,  , 
    ,    .   
   Paste. 

    Procedure Tform.DoPaste; 
    begin 
    with OLEContainerI do 
    if CanPaste then 
    Paste 
    else 
    ShowMessage('Can not paste OLE object from Windows clipboard'); 
    end; // Tform.DoPaste 

     PasteSpecialDialog      
    Windows   (. 18.13).  
 Paste Special     , , 
          OLE   
.  ,       
,   . 

    Procedure TFormI.DoPasteSpecial; 
    begin 
    with OLEContainerI do 
    if PasteSpecialDialog then 
    ShowMessage('Paste Done') ; 
    end; // TFormI.DoPasteSpecial 

     . 18.14      Excel. 


        OLE 

      OLE    .  Delphi    
      ChangeIconDia 
log,InsertObjectDialog,Object Properties Dialog  PasteSpecialDialog. 
      ,      
,   Change Icon.       
,    OLE    . 

     18.   OLE,      ActiveX   419 

        ,   ,  
   ,       . 

    Procedure TFormI.ChangeIconlClick(Sender: TObject); 
    begin 
    with OleContainerI do 
    //     . 
    if State <> osEmpty then 
    if ChangeIconDialog then 
    ShowMessage('Icon was Changed'); 
    end; // TFormI.ChangeIconlClick 
    fdit VBW jreert Fotmat Tools fiate Urip 
    

    . 18.13.   Paste Special,         
     Excel 

    . 18.14.  Excel,    OLE 

          TOleContainer    
   ,      .  
,         
  -   .     
   ,      . 
      (. 18.15).   "   
OLE''       Insert 
Object.          
OLE,    TOleContainer. 

    . 18.15.   Change Icon 

            
 OLE       Windows. 

    // !!!!     ,  !!!! 
function Win32Chk(Win320K: Integer): Integer; 
    var 
    Buffer: String; 
    begin 
    Result := Win320K; 
    if Win320K = 0 then begin 
    SetLength(Buffer, ERRORSIZE) ; 
    if FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, 
    PChar(Buffer), ERRORSIZE, nil) = 0 then 


    420                                            V.   OLE 


    Buffer := 'Internal Error: Error creating Error String'; 
    SetLength (Buffer, StrLeriC'Pchar (Buffer) ) ) ;                           
    raise EWin32Error.Create(Buffer); 
    end; 
    end; // Win32Chk 
    Procedure TFormI.ChangeIconlClick(Sender: TObject); 
    var 
    Hg: HGlobal; 
    Mfp: PMetaFilePict; // HMetaFile; 
    Hmf: HMetaFile;                                                            
    HHH: HMetaFile;                                                            
    const mfile: pchar = 'c:\test.wmf; 
    begin 
    with OleContainerI do 
    //     . 
    if State <> osEmpty then 
    if ChangeIconDialog then begin 
    Hg := OleContainerI.GetIconMetaPict; 
    Hmf := PMetaFilePict(GlobalLock(Hg)".hMF; 
    HHH := CopyMetaFile(hmf, mfile); 
    if HHH = 0 then Win32Chk(boolean(HHH)); 
    GlobalUnLock(Hg) ; 
    end; // if end; //TFormI.ChangeIconlClick 

     ,       
. ,    ,     
 .    -  ,   
     . 

    TOIeContainer   - 

     TOIeContainer    OLE   
.       OLE  . 
    ,      OLE  . 

    procedure TFormI.LoadObject; 
    begin 
    with OleContainerI do 
    LoadFromFile('c:\udelphi3\chpl8\TestFile-bmp') ; 
    end; // TFormI.LoadObject 

    /^k     TESTFILE. BMP     
   \Udelphi\Chpl8\. 
     testfile. bmp    OLE,    . 
      13 ,    
 190 . 
     TFormI. LoadObject   OLE "TESTFILE.BMP".  
          
      .   OleStreamFormat 
  True,     LoadFromFile    
 ,     TOIeContainer  Delphi 1.0. 

    procedure TFormI.SaveObject; 
    begin 
    with OleContainerI do 


     18.   OLE,      ActiveX   421 


    if State <> osEmpty then 
    SaveToFile('c:\udelphi3\chpl8\testfile.bmp') ; 
    end; // TFormI.SaveObject 

     testfile.bmp     \Udelphi3\chpl8\   
 .      , 
    OLE,    OLE.    
  ,       .    
  OldStreamFormat   True,   SaveToFile 
 ,    TOleContainer  Delphi 1.0. 
     True   OldStreamFormat  ,   
       , 
  TOleContainer,   Delphi 1.0.   
       False.  elphi 
2.0        OLE  
 ,  TOleContainer     
 . 
     LoadFromStream  SaveToStream    ,    
  LoadFromFile  SaveToFile.     
   ,    LoadFromStream  SaveToStream 
    -.     
,         OLE   . 

           OLE    

          ,      
OLE   .      OLEDB. .  
         . 
          OLE Obj ect.     
       TBIobStream.   
18.5     TfrmMain.LoadFromStreamOLE.    
    OLEDBU.     . 

    I  18.5. \UDELPHl3\CHPl8\OLEDB\OLEDBU. PAS.   OLE   

    procedure TfrmMain.LoadFromStreamOLE; 
    var 
    BS: TBIobStream; 
    begin 
    BS := TBIobStream.Create (Tablel.FieldByName('OLE_Object') as TBIobField, 
bmRead) ; 
    if BS.Size <> 0 then 
    try with frmOLE, OLEContainerI do begin 
    LoadFromStream(BS) ; 
    AllowInPlace := True; 
    end; // with 
    finally 
    BS.Free; 
    end; // Try 
    end; // TfrmMain.LoadFromStreamOLE 

    ,   Iconic      
  .       . 
      OLEDB  LoadFromStream    
TDataSource.OnDataChanged.  ,   OLE  
  ,       .  
 18.6     TfrmMain. WriteToStreamOLE.  
   OLE  .        
OLEDBU. PAS    . 

    422                                            V.   OLE 

     18.6. \UDELpHi3\CHPl8\OLEDB\OLEDBU.PAS.   OLE   

    procedure TfrmMain.WriteToStreamOLE; 
    var 
    BS:   TBIobStream; 
    begin 
    BS := TBIobStream.Create( 
    Tablel.FieldByName('OLE_Object') as TBIobField, bmWrite); 
    try 
    with frmOLE.OLEContainer! do 
    if State <> osEmpty then 
    SaveToStream(BS) ; 
    finally 
    BS.Free; 
    end; // try 
    end; // TfrmMain.WriteToStreamOLE 

            
OnBeforePost  TTable.     
,    OLE,        
TOleContainer. Modified.      True, , 
 OLE . 

    TOIeContainer   

    TOleContainer       
,    SizeMode,   . 18.5. 

    |  18.5.   SizeMode 

               

    smClip	 OLE    ;  ,  
  ,  .     
SizeMode   
    smCenter	 OLE        
    smScale	 OLE      . 
      
    smStretch	 OLE       
    OLE 
    smAutoSize	   ,   smClip.   
     OLE 

          .   OLE ( 
  Active Document)    
   (,  Paint     Word). 
   ,   TOleContainer   (TPanel) 
      ( BorderWidth),  10  
,          OLE. 
   ,      
,     . ,    
 OLE  Active Document      . 

         
            , 
         (alClient). 

       ,     ,    . 
 . 18.16     Word  .     
     .  . 18.17  ,  
     . 

     18.   OLE,      ActiveX   423 


    . 18.16.  Word  ,        

    . 18.17.  Word  ,        


      OLE 

     OLE     (verbs),  
     ,    
  ,   ,,   
.  ,   OLE,    
 ,     .   , 
   ,    Do Verb,  
 . 

    DoVerb(ovShow) ; 

      (ovShow)       OLE, 
  . TOleContainer    
,   ,    OLE.  . 
18.6   ,       
 DoVerb. 

     18.6.   OLE 

                      

    ovPrimary	  ,   
   (in-place User Interface) 
    ovOpen	  OLE    
    ovShow	   ovPrimary.     , 
  OLE   ovOpen 
    ovHide	    ,    
.       OLE 
    ovUIActivate	      
 OLE 
    ovInPlaceActivate	  OLE  .    
   
    ovDiscardUndoState	       
 (undo information) 
    
        Microsoft,    OLE  
 ,        
 -.  ovShow  ovHide     
 ovShow  ' ,  ovHide  . 
     Delphi    ovShow  ovOpen.   
 ovPrimary,         0 ().  
  OLE  0 ()   Open.   
 ,    OLE    ,   
    OLE,      . 

    Procedure TFormI.LoadDocumentEmbedded; 
    begin 
    //    . 
    .CreateObjectFromFile('test.doc', false); 


    424       V.   OLE 


    if TOC.State <> osInPlaceActive then 
    TOC.DoVerb(ovOpen); //  Word  Delphi. 
    end; // TFormI.LoadDocumentEmbedded 

    Delphi   ,      
 .  . 18.7    Microsoft 
   . 

         

    osEmpty              g    
    os Loaded                 ,   
  (in-process),    .   
,    .  
    TOleContainer   
    05Running              OLE    . 
  ,     .  
OLE    .     OLE    
  RUN 
    osOpen                   
    osInPlaceActive           
TOleContainer.         
  
    osUIActive               , 
,  TOleContainer        OLE 

     (verbs)   ,     OLE.  
       . , Word 
  : Open  Edit. ,   Open 
    Word  .  , 
 ,      REGEDIT.EXE.  
,    Paint, ""    
HKEY_CLASSES_ROOT\Paint.Picture\Protocol\StdFileEditing\verb.  
,    Paint,   Edit. 
       OLE       .  
       Verb    
 . 

    // .    
    // TOleContainer  TMainMenu   Formi. 
    function TFormI.AddVerbs; 
    var 
    I: integer; 
    Temp: TMenuItem; 
    begin 
    //    Verb. 
    //     Verb. 
    With MainMenul do begin 
    For I := 0 to Items.Count -1 do 
    if MainMenul.Items[I].Caption = 'Verb' then begin 
    while Items[I].Count > 0 do begin 
    Temp := Items[I].Items[0]; 
    Items[I].Delete (0); 
    Temp.Free; 
    end; // while 
    end; // if 
    // if no verbs then exit 
    if OleContainerI.ObjectVerbs.Count = 0 then exit; 
    //   Verb  . 
    Temp := Tmenultem.Create(self); 


     18.   OLE,      ActiveX   425 


    Temp.Caption := 'Verb'; 
    Items.Add(Temp) ; 
    end; // with 
    //   Verbs  . 
    With OleContainerI do 
    For I := 0 to ObjectVerbs.Count - 1 do begin 
    Temp := TMenuItem.Create(self); 
    Temp.Caption := ObjectVerbs[I]; 
    MainMenul.Items.Items[MainMenul.Items.Count -1].Add(Temp) ; 
    end; // For 
    end; //  Form.Add Verb 5 

      OleObject       
  OLE 
     OLE        , 
         
 . ,   Word   
       . 
     Delphi       (Automation 
Server) ,   .     
,       . 

    procedure TFormI.ButtonlClick(Sender: TObject); 
    Var V: Variant; 
    begin 
    OleContainerI.DoVerb(OLEIVERB_UIACTIVATE) ; 
    V := OleContainerI.OleObject; //    OLE. 
    V := V.Application.WordBasic; //    . 
    V.Insert('Delphi becomes greater everyday') 
    end; 

     Delphi becomes greater everyday      
OLE    . 
             
  ,   .   
Word    wordbasic. hip. -    
   MSDN (Microsoft Software Developer's Network),  
       wordbasic. 
              
 Word.   ,   . 

    procedure TFormI.ButtonlClick(Sender:TObject) ; 
    var V: Variant; 
    begin 
    V := OleContainerI.OleObject.Application.WordBasic; 
    V.FileNew; 
    V.Insert ('Delphi is a temple from ' + #13); 
    V.Insert('Greek mythology'); 
    V.SaveFileAs('DelphiHistory') ; 
    end; // TFormI.ButtonlClick 


        

            
 .       
FormatFont.          wordbasic. hip. 

    FormatFont [.Points = number] [, .Underline = number] [, .Color = number] 
    [, .Strikethrough = number] [, .Superscript = number] 
    [, .Subscript = number] [, .Shadow = number] [, .Hidden = number] 
    [, .SmallCaps = number] [, .AllCaps = number] [, .Outline = number) 
    [, .Spacing = number] [, .Position = number or text] [, .Kerning = number] 
    [, .KerningMin = number or text] [, .Default] 
    [, .Tab = number] [, .Font = text] [, .Bold = number] [, .Italic = number] 


    426                                            V.   OLE 

     FormatFont  20  .    
         
.  ,       . 
      12 ,  
   . 

    V.Format Font(12); 
             , 
   ,  . 
    V.Format Font(40, 1)  Bold  Underline,  ,   boolean. 
      OFF 
     1 ON 

            Bold 
  . 

    V.FormatFont(12, Bold := 1); 

          12,   Bold 
  1 (  Bold).     
     ,    
.     ,    
    . 

    V.FormatFont(Bold := 1, Points := 12); 

          ,   ,   
   .    
   ,        
,    .    ,  Bold := 1. 
          , 
    "-" ( ,    
    Visual Basic,     
 ).    ,      
  . ^ . 
    Delphi     Word   .    
   ,  Delphi,    
.  Word   ,   ,   
  (exception). 
    ,  ,      .  
       ,  
  .      
  13     Underline  Bold. 

    V.FormatFont(13,1,,,,,,,,,,,,,,,,, 1) ; 

    '_              
  ,     
 .  ,  ^   
 ,  ,  

    IB., 
    V.FormatFont(13,!,,!); 

      18.7     .  
    . 
       Title     MAINU.PAS  
  .      Resume. 

    j  18.7. \UDELPHl3\CHPl8\RESUME\MAlNU. PAS.   

    procedure Title(V: variant); 
    begin 
    //    . 
    //     12 . 


     18.   OLE,      ActiveX   427 


    V.FormatFont(Bold := 1, Points := 12); 
    V.CenterPara; 
    V.FormatParagraph(0); //   . 
    end/ // Title 


     /Storage 

             
IStorage.     :    
   .  ,    
  ,      
.        .    
   ,       
OLE,  Delphi 2 Unleashed (Second Edition, Borland Press, 1996). 

       

              
.     Resume,     
TOleContainer   OLE Word   Word.   
     Word   
  ( Word),     . 

     1.  -          ^ 

       ,    ,   
     .    RESUME 
     Word,     
  .  . 18.18   Resume   
.      . 
    
    . 18.18.  Resume,    oleobject 

             
 . 
       Word. 
          . 


    428                                            V.   OLE 


       FilePrint, Save  SaveAs  Word. 
         . 
      -   ,    
Edit  Memo. 
         Word. 
           . 

     2.   OLE 

        OLEDB.    
    OLE      .  
   , ,   . ,   
  ,   ,    ,   
        .  . 18.19  
  OLEDB.       
  . 
    
    . 18.19.  OLEDB,    
 OLE    
    
    /  OLE   . 
        Insert Object  Paste Special   TOleContainer. 
        Iconic  AutoActivate   
  .     OLE    Paradox. 
         OLE  . 
        Insert Dialog. 
       Windows  ,     
 OLE. 

       ActiveX 

     ActiveX    ,     
   ,    ActiveX. 
  ,  ActiveX     . 
,     Delphi. 

      ActiveX    Delphi 

       ,   ActiveX   
 Delphi    .     
    .      
ActiveX    ,   VCL. 

     18.   OLE,      ActiveX   429 

       ActiveX  Delphi 3     
  .       ActiveX. 
       ActiveX   Windows. 
      -. 
      -  . 
         . 
            ,   
 15, "  ". 

      
         ActiveX  Delphi.  
   ActiveX,    
\WinNT\System32.         
-   ActiveX. 

         ActiveX ,  
    .      
 . 4-10  13.     -    , 
     . 
       ActiveX      . 
    1.  ,  ,      
ActiveX.   File^New,      , 
  . 18.20.     Package    
 .      New Package.   File Name 
  "test",    Description     (. 
18.21).           . 
    
    . 18,20.   New Items.     ,  
      

    . 18.21.   New Package,      

    2.      ,   . 18.22.  
  .       ActiveX. 
   Add (    "+"). 
    3.    Add (. 18.23).   
 ActiveX,    Import ActiveX. 
    4.     Add     ,  
 . 18.24.      .      
    Windows   ActiveX.   
          .  
        (wrapper) 
Delphi    ActiveX. 

    430                                            V.   OLE 


    . 18.22.                        

    . 18.23.   Add,      
ActiveX  Delphi 

    5.   ,     Delphi,   
    ,     . 6.    
    .     
 Add,       Register OLE Control (. 
18.25).    ActiveX,   ,   
  Open.       , 
   Register OLE Control   .  
  Hours . ,       
  . 

    . 18.24.  Import ActiveX   Add             

    . 18.25.   Register OLE Control 

    6.         
Import ActiveX     ActiveX (. 18.26).  
       .    
      ActiveX   
.   Class Name      
OLE,      OLE.   OLE  
  , ,     
 .        ,   
          
   . 

     18.   OLE,      ActiveX   431 

    7.  Page Palette     ,  
     ActiveX.     
ActiveX    ActiveX,       
,  ,  . 
    8.   Unit file name     ,  Delphi 
      -. tiveX.    
    ,      ActiveX. 
,       ,    ActiveX,  
   . 
    9.   Search Path    ,   Delphi   
  . 
    10.         
    Import ActiveX. 
      -         Import 
ActiveX,    . (      
 ActiveX,    Cancel    .) 
    Delphi     AclivcX,      
  Delphi. 

    . 18.26.  Import ActiveX    ActiveX 

    . 18.27.   Package    ActiveX 

    11.       Package,    . 
18.27.      .    
Build.  Delphi  ,    .  
    Install.     ,    
 ,    . 18.28. 

    . 18.28. ,     Test.dpI 

    12.      ActiveX    Package 
(, . 18.27),    ,     
   ActiveX.      
    ActiveX. 
            . 

    432                                            V.   OLE 


     OLE 

      ActiveX    ,  
    .      
  Delphi. 
           ActiveX (  
    axHours).        
    ActiveX. 
          ,   
 (conversion log).    -  
- ,         
.         
ActiveX   .    Delphi  
    ActiveX        . 
           .  
  ActiveX   TOleControl.  Telecontrol 
 ""  .     TwinControl. 
Telecontrol   Delphi      ActiveX. 

     

      -  InitControlData, 
     Telecontrol.  
InitControlData       
  .  ,    
   .    ,    
     . 
         Hours .     
AboutBox,    ActiveX   .  
AboutBox      About     
 ActiveX.    ,   AboutBox, 
   InvokeMethod  TOleControl.  InvokeMethod  
     ActiveX,    InvokeMethod 
  OLE    . 

     

          .    
,  read  write   .   , 
   TWinControl  TComponent. 
     ,    ActiveX,  , , 
           get  set.  
   get  set  Delphi    
  ActiveX     Delphi. 
         .     
 InitControlData. Delphi   ,    
 (wrapper)   ,    ActiveX,  
    . 

      

        ,    HOURS . . 
          . 

    unit axhours; 
    interface 
    uses 01e21, Classes, Graphics, OleCtrls; 
    type 
    THours = class(TOleControl) 
    private 
    protected 
    procedure InitControlData; override; 
    public 
    published 
    property TabStop; 
    property DragCursor; 
    property DragMode; 
    property ParentShowHint; 
    property PopupMenu; 


     18.   OLE,      ActiveX   433 


    property ShowHint; 
    property TabOrder; 
    property Visible; 
    property OnDragDrop; 
    property OnDragOver; 
    property OnEndDrag; 
    property OnEnter; 
    property OnExit; 
    property OnStartDrag; 
    property crPermitColor: TColor index 1 
    read GetColorProp 
    write SetColorProp stored Falser
    property crDenyColor: TColor index 2 
    read GetColorProp 
    write SetColorProp stored Falser
    property DateData; Variant index 3 
    read GetVariantProp 
    write SetVariantProp stored False; 
    end; 
    procedure Registers
    implementation 
    <$J+) 
    procedure THours.InitControlData; 
    const 
    CControlData: TControlData = ( 
    Class ID: (D1:$A44EA7AD;D2:$9D58;D3:$11CF;D4:($A3,$5F,$00,$AA,$00,$B6,$74,$3B)); 
    EventIID: (D1:$A44EA7AC;D2:$9D58;D3:$11CF;D4:($A3,$5F,$00,$AA,$00,$B6,$74,$3B)); 
    EventCount: 0; 
    EventDispIDs: nil; 
    LicenseKey: nil; 
    Flags: $00000000); 
    begin 
    ControlData := @CControlData; 
    end; 
    procedure Register; 
    begin 
    RegisterComponents('OCX', [THours]) ; 
    end; 
    end. 


       ActiveX   

        ActiveX      
Delphi.    ActiveX      
  Delphi.  ActiveX    
  Delphi    . 

      

       ActiveX  .    
   ActiveX     
 ,    ,      
 OLE.          
IDispatch,    IDispatch     . 
    '      ActiveX FTP,  
   Delphi,    ,   
 Delphi. 
    ,  Internet Control Pack,    Connect  
  ,  . 
    FTP1.Connect(RemoteHost, RemotePort) ; 


    434                                            V.   OLE 


       ,   ,   
 ActivcX,  .      
 ActiveX   Delphi.      
   .  ,       Spell 
Checking   .    QA   
        \UDELPHI\CHP18\QA. 
           
SpellCheckDBMemo.            
 .   4>   text. 
      .    
CheckText  ,   ,    
 . 
       Text     
,        Memo ( 18.8). 

     18.8. \UDELPHI3\CHP18\QA\QAEditU. PAS.  SpellCheckDBMemo 
procedure TDataChangeForm.SpellBtnClick(Sender: TObject); 

    procedure SpellCheckDBMemo(var TheDBMemo: TDBMemo); 
    var 
    buf: PChar; 
    SizeOfBuf: word; 
    begin 
    SizeOfBuf := succ(TheDBMemo.GetTextLen);  (add 1 for the null terminator} 
    buf := AllocMem(SizeOfBuf); 
    TheDBMemo.GetTextBuf(buf, SizeOfBuf) ; 
    VCSpellerl.Text:= Buf; 
    VCSpellerl.CheckText:= Buf; 
    TheDBMemo.SetTextBuf(PChar(VCSpellerl.Text)) ; 
    FreeMemfbuf, SizeOfBuf); 
    end; 
    ( MAIN SpellBtnClick } 
    begin 
    Forml.Tablel.Edit; 
    SpellCheckDBMemo(DBQues) ; 
    SpellCheckDBMemo(DBAns) ; 
    ShowMessage('Spell Check Complete.'); 
    end; // TDataChangeForm.SpellBtnClick 


       

      ActiveX    .  
   ActiveX Delphi     Pascal,  
   ,    ; 
          Unassigned  
 VT_EMPTY  Variant.     . 

    var V: Variant; 
    begin 
    V = Unassigned; 
    OCX1.Method('Imagel.bmp', V, V, V, Read); 
    end; 

      Variant    VT_EMPTY    
 ActiveX,   . 

    var V: Variant; 
    begin 


     18.   OLE,      ActiveX   435 


    V = VT_EMPTY; 
    OCX1.Method('Image 1.bmp', V, V, V, Read); 
    end; 

      OLE   VT_EMPTY  Unassigned  
   Variant,  VT_ERROR.     
  . 

    33MG"Ky 
    var V: Variant; 
    begin TVarRec(V).VType := VT_ERROR; 
    OCX1.Method(21, V, V) ; 


      OleObject 

      OleObject      
,      Variant.   
   OleObject     " 
 OleObject         OLE" 
 "   ". 

    procedure TFormI.ChartlClick; 
    var 
    V: Variant; 
    begin 
    V := SimpleActiveX.OleObject; 
    V. Method ('A' , , 'C' ) ; 
    end; // TForml.ChartlClick 

     OleObject   IDispatch  . 
         ActiveX, 
       Delphi. 

        ActiveX 

        ,    
    ActiveX.   ActiveX  
          . 

       ActiveX 

     Installshield  WISE    
   ActiveX.    
 ,    Installshield    
Delphi.     . 
      ,        
  ActiveX,      . 
     ,        
   ,     
  (DLL)    (REG). ,   
         
 ActiveX (   LIC).     
  .      
 ActiveX     IClassFactory2.  , 
     ActiveX     
REGSVR32 . . 

     

      ,       
\UDELPHI\CHP18\QA      QA.   
  ActiveX,  . 

    436                                            V.   OLE 


    . 18.29.  QA,    ActiveX 

     QA       .   
   ,   (   )   (. 
18.29).      ,     
     .  Edit  Add  Data 
     ,      
     .     
Spell Check      .    
  ActiveX   . 

     18.   OLE,      ActiveX   437 
