Recent

Author Topic: data2pas 0.8.0 released  (Read 2313 times)

yamer

  • Jr. Member
  • **
  • Posts: 87
data2pas 0.8.0 released
« on: July 29, 2015, 01:30:27 pm »
data2pas is a tool that converts text or binary data into pascal include files.

Changes:
  • Improved: command line check
  • Fixed: indent value is now limited in range [1..40]
  • Fixed: width value is now limited in range [40..1024]

http://yann.merignac.free.fr/data2pas.html

Thaddy

  • Hero Member
  • *****
  • Posts: 9399
Re: data2pas 0.8.0 released
« Reply #1 on: July 29, 2015, 04:12:27 pm »
Like data2inc? Which is included with FPC under tools.
also related to equus asinus.

yamer

  • Jr. Member
  • **
  • Posts: 87
Re: data2pas 0.8.0 released
« Reply #2 on: July 29, 2015, 05:08:17 pm »
Yes, the two tools are used to the same thing. However data2pas syntax is, in my opinion, much more readable.

An example of data2pas file that creates an include file (`data.inc') containing three constants:
Code: [Select]
FILE 'data.inc';
BEGIN
  Font8x8Data : array of byte = DATA('data/fnt8x8.png');
 
  Font8x16Data : array of byte = DATA('data/fnt8x16.png');

  VGAPalImgData : array of byte = DATA('data/vga_pal.pal');
END;

VTwin

  • Hero Member
  • *****
  • Posts: 837
  • Former Turbo Pascal 3 user
Re: data2pas 0.8.0 released
« Reply #3 on: February 19, 2016, 10:36:33 pm »
Thanks yammer!

This works great, now I do not have to include a "Resources" folder with my distros. Yay! I looked at data2inc, but found it confusing. data2pas is easy. :)

For anyone interested, I did this for an about dialog png:

Code: Pascal  [Select]
  1. file 'data.inc';
  2. begin
  3.   AboutPng : array of byte = Data('about.png');
  4.   BeepWav  : array of byte = Data('Beep.wav');
  5. end;

Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   s: TMemoryStream;
  4. begin
  5.   s := nil;
  6.   fBmp := nil;
  7.   try
  8.     s := TMemoryStream.Create;
  9.     s.SetSize(SizeOf(AboutPng));
  10.     s.WriteBuffer(AboutPng, SizeOf(AboutPng));
  11.     s.Seek(0, soFromBeginning);
  12.     fBmp := TBGRABitmap.Create(s);
  13.   finally
  14.     s.Free;
  15.   end;
  16. end;
  17.  
  18. procedure TForm1.FormPaint(Sender: TObject);
  19. begin
  20.   if fBmp <> nil then
  21.     fBmp.Draw(Canvas, 0, 0, false);
  22. end;  
  23.  

and this for a simple sound:

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   p, t: string;
  4.   fs: TFileStream;
  5. begin
  6.   t := GetTempDir(true);
  7.   p := t + 'Beep.wav';
  8.   try
  9.     fs := TFileStream.Create(p, fmCreate);
  10.     fs.WriteBuffer(BeepWav, SizeOf(BeepWav));
  11.     PlaySound(p);
  12.   finally
  13.     fs.Free;
  14.   end;
  15. end;

There is probably a better way to do the sound, but I used a temporary file. No problem to compile for OS X.

Cheers,
VTwin
« Last Edit: February 19, 2016, 10:47:19 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.7 fixes svn r62562 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4