Recent

Author Topic: How to insert data from a text file on lazarus?  (Read 7418 times)

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: How to insert data from a text file on lazarus?
« Reply #15 on: August 23, 2017, 12:08:55 pm »
what should I write in order to change the form's background with a jpg picture?
Simplistic example (there are other ways):

Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     ...
  4.   public
  5.     Image: TPicture;
  6.   end;
  7.  
  8. ...
  9.  
  10. procedure TForm1.FormCreate(Sender: TObject);
  11. begin
  12.   Image := TPicture.Create;
  13.   Image.LoadFromFile('c:\temp\test.jpg');
  14. end;
  15.  
  16. procedure TForm1.FormDestroy(Sender: TObject);
  17. begin
  18.   Image.Free;
  19. end;
  20.  
  21. procedure TForm1.FormPaint(Sender: TObject);
  22. var
  23.   aLeft, aTop: integer;
  24. begin
  25.   aLeft := 0;
  26.   while aLeft < Width do
  27.   begin
  28.     aTop := 0;
  29.     while aTop < Height do
  30.     begin
  31.       Canvas.Draw(aLeft, aTop, Image.Bitmap);
  32.       Inc(aTop, Image.Bitmap.Height);
  33.     end;
  34.     Inc(aLeft, Image.Bitmap.Width);
  35.   end;
  36. end;

This will paint the jpg on your form. It will tile (duplicate) it when the form is bigger than the jpg.

Otherwise use:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. begin
  3.   Canvas.StretchDraw(ClientRect, Image.Bitmap);
  4. end;
« Last Edit: August 23, 2017, 12:11:57 pm by rvk »

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: How to insert data from a text file on lazarus?
« Reply #16 on: August 23, 2017, 04:10:49 pm »
Quote
what should I write in order to change the form's background with a jpg picture?
Use a TImage...  :P :P :P
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: How to insert data from a text file on lazarus?
« Reply #17 on: August 23, 2017, 04:24:13 pm »
Or you can download glSlideshow and study how it change the form's background by repeating a tileable image:
http://forum.lazarus.freepascal.org/index.php/topic,35313.msg256719.html#msg256719

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: How to insert data from a text file on lazarus?
« Reply #18 on: August 23, 2017, 05:41:09 pm »
I don't know what this means :Instance := TSomeClass.Create;
and in this line [//Code with Instance]
:'(
This is a generalized construction. TSomeClass is a some class, and Instance is an instance of this class.
what should I write in order to change the form's background with a jpg picture?
Place the TImage component. Set alClient for the Align property. Expand the Picture property and load the file.

 

TinyPortal © 2005-2018