Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:howto:develop_com_components_and_automation [2009/10/06 11:21]
smayr
swdev:howto:develop_com_components_and_automation [2009/11/05 11:12] (current)
smayr
Line 78: Line 78:
 procedure TfrmClientMain.btnLaunchSvrClick(Sender: TObject); procedure TfrmClientMain.btnLaunchSvrClick(Sender: TObject);
 begin begin
-  svr    := CoMySvr.Create();+  if not Assigned(svr) then begin 
 +    svr := CoMySvr.Create()
 +  end;
   if Assigned(svr) then begin   if Assigned(svr) then begin
     btnGetSvrVersion.Enabled := True;     btnGetSvrVersion.Enabled := True;
Line 91: Line 93:
  
 == Wrapping an Existing Application Functionality in an Automation Object == == Wrapping an Existing Application Functionality in an Automation Object ==
 +Especially use this method for Out-of-process automation servers:
  * Open an existing Delphi application project.   * Open an existing Delphi application project. 
     * Select New > ActiveX > Automation Object.     * Select New > ActiveX > Automation Object.
Line 98: Line 101:
       * Select ''IMySvr'', then add Method or Property.       * Select ''IMySvr'', then add Method or Property.
  * Register the COM Server.  Perform one of these:  * Register the COM Server.  Perform one of these:
-    * Select Run > Register ActiveX Server. +    * In-process (DLL) automation server: 
-    * Setup project to auto register server, to avoid littering the Windows Registry while developing.  +      * Select Run > Register ActiveX Server. 
-      * Select Project > Options > Linker > Auto register type library.+      * Setup project to auto register server, to avoid littering the Windows Registry while developing.  
 +        * Select Project > Options > Linker > Auto register type library. 
 +      * Register from command line: <code>C:\> regsvr32 myServer.dll </code> or <code>C:\> tregsvr myServer.dll</code> 
 +    * Out-of-process (EXE) automation server: 
 +      * To register, run this from command line: <code>C:\> myapp.exe /regserver </code> 
 +      * To unregister, run this from command line: <code>C:\> myapp.exe /unregserver </code>
  
 == Linking Multiple Clients to a Single Instance of a COM Object == == Linking Multiple Clients to a Single Instance of a COM Object ==
Line 204: Line 212:
     for i := LBound to UBound do begin     for i := LBound to UBound do begin
         ElemData := TIntegerArray(sfArrData)[i];              // get data from safearray         ElemData := TIntegerArray(sfArrData)[i];              // get data from safearray
-        str := str + format('sfArr[%d] = %d', [i, ElemData]); // save it for later+        str := str + format('sfArr[%d] = %d'+#13#10, [i, ElemData]); // save it for later
     end;     end;
   end;   end;
Line 232: Line 240:
   for i := LBound to UBound do begin   for i := LBound to UBound do begin
     SafearrayGetElement(sfArr, i, ElemData);     SafearrayGetElement(sfArr, i, ElemData);
-    str := str + format('sfArr[%d] = %d', [i, ElemData]); // get data from safearray and print it+    str := str + format('sfArr[%d] = %d'+#13#10, [i, ElemData]); // get data from safearray and print it
   end;   end;
   ShowMessage(str);   ShowMessage(str);
Line 247: Line 255:
 function SafeArrayToIntArr(sfArr: PSafeArray): TIntegerArray; function SafeArrayToIntArr(sfArr: PSafeArray): TIntegerArray;
 var var
-  sfArrBoundsTSafeArrayBound;+  LBound, UBoundinteger;
   sfArrData: pointer;   sfArrData: pointer;
   i: integer;   i: integer;
-  LBound, UBound: integer; 
   Arr: TIntegerArray;   Arr: TIntegerArray;
 begin begin
Line 356: Line 363:
  * [[http://msdn2.microsoft.com/en-us/library/ms221145.aspx|MSDN Safearray Manipulation Functions]] - Microsoft MSDN  * [[http://msdn2.microsoft.com/en-us/library/ms221145.aspx|MSDN Safearray Manipulation Functions]] - Microsoft MSDN
  * [[http://www.gekko-software.nl/Delphi/art08.htm|Automation Arrays (Safearray, Variant arrays)]] - Gekko Software  * [[http://www.gekko-software.nl/Delphi/art08.htm|Automation Arrays (Safearray, Variant arrays)]] - Gekko Software
 + * [[http://www.gekko-software.nl/Delphi/art10.htm|Server Events for Two-way Communication]] - Gekko Software
 + * [[http://www.techvanguards.com/com/|COM Tutorials and Concepts]] - TechVanguards
 + * [[http://podgeretsky.com/ftp/docs/Delphi/D5/dg/autosrvr.html#3201|Delphi 5 Dev Guide: Creating an Automation Server]]