ScOpenAPI.pas 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. unit ScOpenAPI;
  2. interface
  3. uses
  4. Windows, Forms, Classes, ScProject, ScConfig, ScConsts;
  5. type
  6. TScRegisterProc = function(App: TApplication): Boolean;
  7. IScMenu = interface
  8. ['{FF358C40-4275-456B-BB95-D82CC2CC79BF}']
  9. procedure AddMenuItem(const APath: string; AHandle: TNotifyEvent);
  10. end;
  11. TScCreateProjectMode = (cpmOpen, cpmNew, cpmImportWCost, cpmImportZBFile);
  12. IScProjManager = interface
  13. ['{41A65667-0FCB-4B3F-BC98-8F4FD727FD3B}']
  14. function Open(AMode: TScCreateProjectMode; AFileName: string = ''; APType: TScProjType = ptBills): TScProject;
  15. function GetCurProject: TScProject;
  16. function Version: Integer;
  17. function GetConfigInfo: TScConfigInfo;
  18. procedure LockViews;
  19. procedure UnLockViews;
  20. property ConfigInfo: TScConfigInfo read GetConfigInfo;
  21. property CurProject: TScProject read GetCurProject;
  22. end;
  23. procedure ScRegisterMenu(const MenuPath: string; Handle: TNotifyEvent);
  24. function ScLoadPlugInModule(const APath, AProcName: string): Integer;
  25. var
  26. MainApp: TApplication;
  27. implementation
  28. uses SysUtils, Menus, ScUtils;
  29. procedure ScRegisterMenu(const MenuPath: string; Handle: TNotifyEvent);
  30. var
  31. StrList: TStringList;
  32. s: string;
  33. I: Integer;
  34. Item: TMenuItem;
  35. vItem: TMenuItem;
  36. begin
  37. StrList := TStringList.Create;
  38. try
  39. StrList.Delimiter := '\';
  40. StrList.DelimitedText := MenuPath;
  41. Item := MainApp.MainForm.Menu.Items;
  42. for I := 0 to StrList.Count - 1 do
  43. begin
  44. if StrList[I] = '' then Continue;
  45. vItem := Item.Find(StrList[I]);
  46. if vItem = nil then
  47. begin
  48. vItem := TMenuItem.Create(Item.Owner);
  49. vItem.Caption := StrList[I];
  50. Item.Add(vItem);
  51. end;
  52. Item := vItem;
  53. end;
  54. vItem.OnClick := Handle;
  55. finally
  56. StrList.Free;
  57. end;
  58. end;
  59. function ScLoadPlugInModule(const APath, AProcName: string): Integer;
  60. var
  61. slFiles: TStringList;
  62. I: Integer;
  63. sName: string;
  64. hModule: THandle;
  65. Proc: TScRegisterProc;
  66. begin
  67. slFiles := TStringList.Create;
  68. try
  69. ScFindFiles(slFiles, APath);
  70. for I := 0 to slFiles.Count - 1 do
  71. begin
  72. try
  73. sName := slFiles[I];
  74. hModule := LoadLibrary(PChar(sName));
  75. @Proc := GetProcAddress(hModule, PChar(AProcName));
  76. if (@Proc = nil) or (not Proc(Application)) then
  77. FreeLibrary(hModule);
  78. except
  79. Application.HandleException(Application);
  80. end;
  81. end;
  82. finally
  83. slFiles.Free;
  84. end;
  85. end;
  86. var
  87. OrgApp: TApplication;
  88. initialization
  89. OrgApp := Application;
  90. finalization
  91. Application := OrgApp;
  92. end.