home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / eXpertDevelopmentKit / SOURCE / XDKMAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-26  |  2.0 KB  |  76 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       eXpert Development Kit                          }
  4. {                                                       }
  5. {       Copyright (c) 1996,97 Sergey Orlik              }
  6. {       - product manager of Borland Russia             }
  7. {                                                       }
  8. {*******************************************************}
  9. unit XDKMain;
  10.  
  11. interface
  12. uses
  13.   SysUtils, Classes, Forms,
  14.   LibIntf, ExptIntf;
  15.  
  16. type
  17.   ExdkInitError = class(Exception);
  18.  
  19. procedure xdkInitModule(ModuleClass:TComponentClass; var Reference);
  20. procedure xdkDoneModule(Module:TComponent);
  21.  
  22. //====================================================================
  23. implementation
  24. //====================================================================
  25.  
  26. const
  27.   sToolServicesError = 'XDK initialization error!';
  28.   sInitModuleError = 'Module of %s-class is not initialized!';
  29.  
  30. procedure ToolServicesError;
  31. begin
  32.   raise ExdkInitError.Create(sToolServicesError);
  33. end;
  34.  
  35. procedure InitModuleError(const ModuleClassName:string);
  36. begin
  37.   raise ExdkInitError.Create(Format(sInitModuleError,[ModuleClassName]));
  38. end;
  39.  
  40. //=====================================================================
  41.  
  42. procedure xdkInitModule(ModuleClass:TComponentClass; var Reference);
  43. var
  44.   Instance: TComponent;
  45. begin
  46.   Instance := TComponent(ModuleClass.NewInstance);
  47.   TComponent(Reference) := Instance;
  48.   try
  49.     Instance.Create(nil);
  50.   except
  51.     TComponent(Reference):=nil;
  52.     Instance.Free;
  53.     InitModuleError(ModuleClass.ClassName);
  54.   end;
  55.   if (Instance is TForm) then
  56.     TForm(Instance).HandleNeeded;
  57. end;
  58.  
  59. procedure xdkDoneModule(Module:TComponent);
  60. begin
  61.   if Module<>nil then
  62.   begin
  63.     Module.Free;
  64.     Module:=nil;
  65.   end;
  66. end;
  67.  
  68. //=====================================================================
  69. initialization
  70.   try
  71.     ToolServices:=DelphiIDE.GetToolServices;
  72.   except
  73.     ToolServicesError;
  74.   end;
  75. end.
  76.