PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/KOLAPPEXPERT200/KolAppExpert203.pas

http://github.com/rofl0r/KOL
Pascal | 350 lines | 275 code | 44 blank | 31 comment | 3 complexity | 35a7f01e7630156a5b2640e98ad983db MD5 | raw file
  1. {***************************************************************
  2. *
  3. * Unit Name: KolAppExpert
  4. * Purpose : Creates default empty KOL project
  5. * and unit for working with KOL without MCK
  6. * Author : Thaddy de Koning
  7. * History : First released D4 © 2000,Thaddy de Koning.
  8. * This version D4, D5, D6, D7 © 2004, Thaddy de Koning
  9. * Status : Freeware
  10. * Remarks :
  11. * Simply install it in a Package of choice(f.e.users)
  12. * Depending on the Delphi version it shows up under:
  13. * File|new|Kol Application
  14. * or
  15. * File|New|Other|Kol Application
  16. *
  17. * It creates a project file and a unit file with
  18. * an empty form with a basic messagehandler
  19. * The code is equivalent to that of an MCK project,
  20. * but without confusing conditional defines and inc
  21. * files.
  22. * Remarks2 :
  23. * I wrote this, because I rarely use the MCK,
  24. * I think this gives more readable code.
  25. * The MCK is recommended, though!
  26. * Note:
  27. * The OpenTools Api I used is deprecated, but so is
  28. * Tobject 0_-)
  29. *
  30. ****************************************************************}
  31. unit KolAppExpert203;
  32. interface
  33. uses
  34. ExptIntf, EditIntf, Windows,SysUtils;
  35. const crlf = #13#10 ;
  36. type
  37. TSimpleKolAppExpert = class(TIExpert)
  38. public
  39. function GetName: string; override; stdcall;
  40. function GetAuthor: string; override; stdcall;
  41. function GetComment: string; override; stdcall;
  42. function GetPage: string; override; stdcall;
  43. function GetGlyph: HICON; override; stdcall;
  44. function GetStyle: TExpertStyle; override; stdcall;
  45. function GetState: TExpertState; override; stdcall;
  46. function GetIDString: string; override; stdcall;
  47. function GetMenuText: string; override; stdcall;
  48. procedure Execute; override; stdcall;
  49. end;
  50. TSimpleKolAppCreator = class(TIProjectCreator)
  51. public
  52. function Existing: Boolean; override; stdcall;
  53. function GetFileName: string; override; stdcall;
  54. function GetFileSystem: string; override; stdcall;
  55. function NewProjectSource(
  56. const ProjectName: string): string; override; stdcall;
  57. procedure NewDefaultModule; override; stdcall;
  58. procedure NewProjectResource(Module: TIModuleInterface); override; stdcall;
  59. end;
  60. TSimpleKolUnitCreator = class(TiModuleCreator)
  61. public
  62. function Existing: Boolean; override; stdcall;
  63. function GetAncestorName: string; override; stdcall;
  64. function GetFileName: string; override; stdcall;
  65. function GetFileSystem: string; override; stdcall;
  66. function GetFormName: string; override; stdcall;
  67. function NewModuleSource(const UnitIdent, FormIdent,
  68. AncestorIdent: string): string; override; stdcall;
  69. procedure FormCreated(Form: TIFormInterface); override; stdcall;
  70. end;
  71. procedure Register;
  72. implementation
  73. uses
  74. ToolIntf, Dialogs;
  75. procedure Register;
  76. begin
  77. RegisterLibraryExpert(TSimpleKolAppExpert.Create);
  78. end;
  79. procedure TSimpleKolAppCreator.NewDefaultModule;
  80. var
  81. UnitCreator:TSimpleKolUnitCreator;
  82. Test:TiModuleInterface;
  83. begin
  84. if not assigned(Toolservices) then
  85. begin
  86. Showmessage('Can''t access Toolservices');
  87. Exit;
  88. end;
  89. UnitCreator:=TSimpleKolUnitCreator.create;
  90. try
  91. Test:=Toolservices.ModuleCreate(UnitCreator,[cmMarkModified, cmNewUnit, cmUnNamed,cmAddtoProject,cmShowSource]);
  92. Try
  93. ;
  94. finally
  95. Test.free;
  96. end;
  97. finally
  98. UnitCreator.free;
  99. end;
  100. end;
  101. procedure TSimpleKolAppExpert.Execute;
  102. var
  103. PrjCreator: TSimpleKolAppCreator;
  104. PrjModule: TIModuleInterface;
  105. begin
  106. if not Assigned(ToolServices) then
  107. begin
  108. ShowMessage('Can''t access ToolServices');
  109. Exit;
  110. end;
  111. if not ToolServices.CloseProject then
  112. Exit;
  113. PrjCreator := TSimpleKolAppCreator.Create;
  114. try
  115. PrjModule := ToolServices.ProjectCreate(PrjCreator, []);
  116. try
  117. ;
  118. finally
  119. PrjModule.Free;
  120. end;
  121. finally
  122. PrjCreator.Free;
  123. end;
  124. end;
  125. function TSimpleKolAppExpert.GetAuthor: string;
  126. begin
  127. Result := 'Thaddy de Koning';
  128. end;
  129. function TSimpleKolAppExpert.GetComment: string;
  130. begin
  131. Result := 'Creates a new KOL based application project';
  132. end;
  133. function TSimpleKolAppExpert.GetGlyph: HICON;
  134. begin
  135. Result := LoadIcon(0, IDI_WINLOGO);
  136. end;
  137. function TSimpleKolAppExpert.GetIDString: string;
  138. begin
  139. Result := 'KOL Simple Expert';
  140. end;
  141. function TSimpleKolAppExpert.GetMenuText: string;
  142. begin
  143. Result := 'New Simple Kol Project';
  144. end;
  145. function TSimpleKolAppExpert.GetName: string;
  146. begin
  147. Result := 'Simple KOL application';
  148. end;
  149. function TSimpleKolAppExpert.GetPage: string;
  150. begin
  151. Result := 'New';
  152. end;
  153. function TSimpleKolAppExpert.GetState: TExpertState;
  154. begin
  155. Result := [esEnabled];
  156. end;
  157. function TSimpleKolAppExpert.GetStyle: TExpertStyle;
  158. begin
  159. Result := esProject;
  160. end;
  161. function TSimpleKolAppCreator.Existing: Boolean;
  162. begin
  163. Result := False;
  164. end;
  165. function TSimpleKolAppCreator.GetFileName: string;
  166. begin
  167. Result := '';
  168. end;
  169. function TSimpleKolAppCreator.GetFileSystem: string;
  170. begin
  171. Result := '';
  172. end;
  173. procedure TSimpleKolAppCreator.NewProjectResource(
  174. Module: TIModuleInterface);
  175. begin
  176. Module.Free;
  177. end;
  178. function TSimpleKolAppCreator.NewProjectSource(
  179. const ProjectName: string): string;
  180. begin
  181. Result :=
  182. 'program Project1;'+
  183. CrLf +
  184. '//********************************************************************'+
  185. CrLf +
  186. '// Created by KOL project Expert Version 2.01 on:'+DateTimeToStr(Now)+
  187. CrLf +
  188. '//********************************************************************'+
  189. CrLf +
  190. CrLf +
  191. 'uses'+
  192. CrLf +
  193. ' Kol;'+
  194. CrLf +
  195. 'begin'+
  196. CrLf +
  197. ' NewForm1( Form1, nil);'+
  198. CrLf+
  199. ' Run(Form1.form);'+
  200. CrLf +
  201. 'end.';
  202. end;
  203. { TSimpleKolUnitCreator }
  204. function TSimpleKolUnitCreator.Existing: Boolean;
  205. begin
  206. Result:=False;
  207. end;
  208. procedure TSimpleKolUnitCreator.FormCreated(Form: TIFormInterface);
  209. begin
  210. Form.free;
  211. end;
  212. function TSimpleKolUnitCreator.GetAncestorName: string;
  213. begin
  214. Result:='';
  215. end;
  216. function TSimpleKolUnitCreator.GetFileName: string;
  217. begin
  218. Result:='';
  219. end;
  220. function TSimpleKolUnitCreator.GetFileSystem: string;
  221. begin
  222. Result:='';
  223. end;
  224. function TSimpleKolUnitCreator.GetFormName: string;
  225. begin
  226. Result:='';
  227. end;
  228. function TSimpleKolUnitCreator.NewModuleSource(const UnitIdent, FormIdent,
  229. AncestorIdent: string): string;
  230. begin
  231. Result :=
  232. 'unit unit1;'+
  233. CrLf +
  234. '//********************************************************************'+
  235. CrLf +
  236. '// Created by KOL project Expert Version 2.03 on:'+DateTimeToStr(Now)+
  237. CrLf +
  238. '//********************************************************************'+
  239. CrLf +
  240. CrLf+CrLf+
  241. 'interface'+
  242. CrLf+
  243. 'uses'+
  244. CrLf +
  245. ' Windows, Messages, Kol;'+
  246. CrLf +
  247. CrLf +
  248. 'type' +
  249. CrLf +
  250. CrLf +
  251. 'PForm1=^TForm1;' +
  252. CrLf +
  253. 'TForm1=object(Tobj)'+
  254. CrLf +
  255. ' Form:pControl;'+
  256. CrLf+
  257. 'public'+
  258. CrLf +
  259. ' // Add your eventhandlers here, example:'+
  260. CrLf +
  261. ' function DoMessage(var Msg:Tmsg;var Rslt:integer):boolean;'+
  262. CrLf +
  263. 'end;'+
  264. CrLf +
  265. CrLf+CrLf+
  266. 'procedure NewForm1( var Result: PForm1; AParent: PControl );'+
  267. CrLf+
  268. CrLf+
  269. 'var'+
  270. CrLf+
  271. ' Form1:pForm1;'+
  272. CrLf+CrLf+
  273. 'implementation' +
  274. CrLf+CrLf+
  275. 'procedure NewForm1( var Result: PForm1; AParent: PControl );'+
  276. CrLf+
  277. 'begin'+
  278. CrLf+
  279. ' New(Result,Create);' +
  280. CrLf+
  281. ' with Result^ do'+CrLf +
  282. ' begin'+CrLf +
  283. ' Form:= NewForm(AParent,''KOLForm'').SetSize(600,400).centeronparent.Tabulate;'+
  284. CrLf+
  285. ' Applet:=Form;'+
  286. CrLf+
  287. ' Form.OnMessage:=DoMessage;'+
  288. CrLf+
  289. ' Form.Add2AutoFree(Result);'+
  290. CrLf+
  291. ' end;'+CrLf+
  292. 'end;'+
  293. CrLf+
  294. CrLf+CrLf+
  295. 'function TForm1.DoMessage(var Msg:TMsg;var Rslt:integer):Boolean;'+
  296. CrLf +
  297. 'begin'+
  298. CrLf +
  299. ' Result:=false;'+
  300. CrLf +
  301. 'end;'+
  302. CrLf +
  303. CrLf +
  304. 'end.';
  305. end;
  306. end.