2
0

importtl.pas 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. program importtl;
  2. {$mode objfpc}{$H+}
  3. {$apptype console}
  4. uses
  5. classes,typelib,sysutils;
  6. var
  7. unitname:string;
  8. sTL,sOutDir:string;
  9. F:text;
  10. slDep:TStringList;
  11. i:integer;
  12. bNoRecurse,bHelp, bActivex:boolean;
  13. begin
  14. slDep:=TStringList.Create;
  15. bNoRecurse:=false;
  16. bHelp:=false;
  17. bActiveX:=false;
  18. i:=1;
  19. while i<=Paramcount do
  20. begin
  21. if pos('-n',ParamStr(i))>0 then bNoRecurse:=true
  22. else if pos('-a',ParamStr(i))>0 then bActiveX:=true
  23. else if pos('-h',ParamStr(i))>0 then bHelp:=true
  24. else if pos('-d',ParamStr(i))>0 then
  25. begin
  26. sOutDir:=trim(copy(ParamStr(i), pos('-d',ParamStr(i))+2, 260)); // windows MAX_PATH
  27. if sOutDir='' then
  28. if i<Paramcount-1 then
  29. begin
  30. i:=i+1;
  31. sOutDir:=trim(ParamStr(i));
  32. end
  33. else
  34. begin
  35. bHelp:=true;
  36. sOutDir:='\';
  37. end;
  38. if not (sOutDir[length(sOutDir)] in [':','\']) then
  39. sOutDir:=sOutDir+'\';
  40. end;
  41. i:=i+1;
  42. end;
  43. if bHelp or (Paramcount=0) or (pos('-',paramstr(Paramcount))=1) then
  44. begin
  45. writeln('Usage: importtl [options] file');
  46. writeln('Reads type information from "file" and converts it into a freepascal binding');
  47. writeln('units.');
  48. writeln('Options.');
  49. writeln(' -h : displays this text.');
  50. writeln(' -a : create ActiveXContainer descendants');
  51. writeln(' -d dir: set output directory. Default: current directory.');
  52. writeln(' -n : do not recurse typelibs. Default: create bindingss for all');
  53. writeln(' dependencies.');
  54. exit;
  55. end;
  56. slDep.Add(paramstr(Paramcount));
  57. i:=0;
  58. repeat
  59. writeln('Reading typelib from '+slDep[i]+ ' ...');
  60. sTL:=ImportTypelib(slDep[i],unitname,slDep,bActiveX);
  61. bActiveX:=false; //don't create ActiveXContainer descendants in descendants
  62. unitname:=sOutDir+unitname;
  63. writeln('Writing to '+unitname);
  64. AssignFile(F,unitname);
  65. Rewrite(F);
  66. Write(F,sTL);
  67. CloseFile(F);
  68. i:=i+1;
  69. until bNoRecurse or (i=slDep.Count);
  70. slDep.Destroy;
  71. end.