home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Install / DATA.Z / MYAUTO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-11  |  1.5 KB  |  72 lines

  1. unit MyAuto;
  2.  
  3. { This object has one method and one property that are available via OLE
  4.   automation. The property allows you to set the value of a string, and
  5.   the method shows the string in a dialog.
  6.  
  7.   For this example to work, you need to run the TestAp program, stored in this
  8.   same directory. Before running TestAp, you should run this program once,
  9.   passing in /regserver as the program's sole parameter.
  10.  
  11.   Open up the DPR file to see the call to Automation.ServerRegistration. }
  12.  
  13. interface
  14.  
  15. uses OleAuto;
  16.  
  17. type
  18.   TMyAuto = class(TAutoObject)
  19.   private
  20.     FMyProp: string;
  21.     function GetMyProp: string;
  22.     procedure SetMyProp(S: string);
  23.   public
  24.     constructor Create; override;
  25.   automated
  26.     procedure ShowDialog;
  27.     property MyProp: string read GetMyProp write SetMyProp;
  28.   end;
  29.  
  30. implementation
  31.  
  32. uses
  33.   Dialogs;
  34.  
  35. constructor TMyAuto.Create;
  36. begin
  37.   inherited Create;
  38. end;
  39.  
  40. procedure TMyAuto.ShowDialog;
  41. begin
  42.   if FMyProp = '' then
  43.     FMyProp := 'This object has a property called MyProp';
  44.   ShowMessage(FMyProp);
  45. end;
  46.  
  47. procedure TMyAuto.SetMyProp(S: string);
  48. begin
  49.   FMyProp := S;
  50. end;
  51.  
  52. function TMyAuto.GetMyProp: string;
  53. begin
  54.   Result := FMyProp;
  55. end;
  56.  
  57. procedure RegisterMyAuto;
  58. const
  59.   AutoClassInfo: TAutoClassInfo = (
  60.     AutoClass: TMyAuto;
  61.     ProgID: 'AUTOPROJ.MyAuto';
  62.     ClassID: '{FE67CF61-2EDD-11CF-B536-0080C72EFD43}';
  63.     Description: 'Sam';
  64.     Instancing: acMultiInstance);
  65. begin
  66.   Automation.RegisterClass(AutoClassInfo);
  67. end;
  68.  
  69. initialization
  70.   RegisterMyAuto;
  71. end.
  72.