pgtk.pp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. program PGtk;
  2. Uses sysutils, ObjectDef, classes;
  3. type
  4. PGtkexception = class (Exception);
  5. procedure DataRead (Filename:string; var Descr:TObjectDefs);
  6. var StrStream : TFileStream;
  7. BinStream : TMemoryStream;
  8. begin
  9. if fileExists (filename) then
  10. begin
  11. StrStream := TFileStream.Create(filename, fmOpenRead);
  12. try
  13. BinStream := TMemoryStream.Create;
  14. try
  15. writeln ('Reading...');
  16. ObjectTextToBinary(StrStream, BinStream);
  17. BinStream.Seek(0, soFromBeginning);
  18. BinStream.ReadComponent(Descr);
  19. finally
  20. BinStream.Free;
  21. end;
  22. finally
  23. StrStream.Free;
  24. end;
  25. end
  26. else
  27. raise PGtkException.Create ('Error: Can''t find file "'+filename+'"');
  28. end;
  29. procedure Convert (DescrFilename, UnitFilename : string);
  30. var GTK : TObjectDefs;
  31. l : TStrings;
  32. begin
  33. l := TStringlist.Create;
  34. GTK := TObjectdefs.create (nil);
  35. try
  36. DataRead (DescrFilename, GTK);
  37. writeln ('Filling Stringlist');
  38. GTK.Write (l, nil, nil);
  39. writeln ('Writing to file');
  40. L.SaveToFile (UnitFilename);
  41. finally
  42. GTK.Free;
  43. l.Free;
  44. end;
  45. end;
  46. begin
  47. if paramcount = 2 then
  48. Convert (Paramstr(1), Paramstr(2))
  49. else
  50. writeln ('Give 2 filenames :'#10#13' First the object description file'#10#13' Second the Pascal unit filename');
  51. end.