Recent

Author Topic: Display Multiple Image In TScrollBox  (Read 3384 times)

heejit

  • Full Member
  • ***
  • Posts: 245
Display Multiple Image In TScrollBox
« on: February 20, 2018, 04:44:27 pm »
I am trying to display multiple images from database into TScrollBox

I am creating TImage control in loop and adding into using TScrollBox.InsertControl
but only one image is displaying.

How do I display multiple image what control to use?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Display Multiple Image In TScrollBox
« Reply #1 on: February 20, 2018, 04:51:10 pm »
set the timage.align to altop for the images does that show them all?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

heejit

  • Full Member
  • ***
  • Posts: 245
Re: Display Multiple Image In TScrollBox
« Reply #2 on: February 20, 2018, 06:14:49 pm »
Not working

heejit

  • Full Member
  • ***
  • Posts: 245
Re: Display Multiple Image In TScrollBox
« Reply #3 on: February 20, 2018, 06:16:09 pm »
This is the code I am running
Code: Pascal  [Select][+][-]
  1.     for i := 0 to tqry.RecordCount-1 do begin
  2.         astream := tqry.CreateBlobStream(tqry.FieldByName('file_data'), bmRead);
  3.         Image1 := TImage.Create(self);
  4.         Image1.Picture.LoadFromStream(astream);
  5.         Image1.Top := y;
  6.         y := y + Image1.Height;
  7.         ScrollBox1.InsertControl(Image1);
  8.         tqry.Next;
  9.     end;
  10.  
  11.  

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Display Multiple Image In TScrollBox
« Reply #4 on: February 20, 2018, 08:46:53 pm »
This is the code I am running
the code looks ok, here is a small crucial addition and a small loop correction.
Code: Pascal  [Select][+][-]
  1.     while not tqry.EOF do begin
  2.         astream := tqry.CreateBlobStream(tqry.FieldByName('file_data'), bmRead);
  3.         Image1 := TImage.Create(self);
  4.         Image1.Picture.LoadFromStream(astream);
  5.         Image1.Top := y;
  6. ///////////////////////////////////////////////////////////////////////////////
  7.         Image1.Width :=Image1.Picture.Graphic.Width;
  8.         Image1.Height:=Image1.Picture.Graphic.Height;
  9. ///////////////////////////////////////////////////////////////////////////////
  10.         y := y + Image1.Height;
  11.         ScrollBox1.InsertControl(Image1);
  12.         tqry.Next;
  13.     end;
  14.  
  15.  
« Last Edit: February 20, 2018, 09:02:11 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

heejit

  • Full Member
  • ***
  • Posts: 245
[SOLVED] Re: Display Multiple Image In TScrollBox
« Reply #5 on: February 20, 2018, 09:12:30 pm »
Thanks it is working fine

heejit

  • Full Member
  • ***
  • Posts: 245
Re: Display Multiple Image In TScrollBox
« Reply #6 on: February 20, 2018, 09:31:57 pm »
But Adding 50 images overlapping

heejit

  • Full Member
  • ***
  • Posts: 245
Re: Display Multiple Image In TScrollBox
« Reply #7 on: February 20, 2018, 09:37:27 pm »
I am adding 43 Images

After 23 no image showing blank area

heejit

  • Full Member
  • ***
  • Posts: 245
Re: Display Multiple Image In TScrollBox
« Reply #8 on: February 21, 2018, 12:47:40 am »
Look like it is Integer Data Type max value issue

Image.Top ignoring if values is more than 32767



taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Display Multiple Image In TScrollBox
« Reply #9 on: February 21, 2018, 12:59:31 am »
Look like it is Integer Data Type max value issue

Image.Top ignoring if values is more than 32767

try doing it in reverse eg.

Code: Pascal  [Select][+][-]
  1.     tqry.Last;
  2.     while not tqry.BOF do begin
  3.         astream := tqry.CreateBlobStream(tqry.FieldByName('file_data'), bmRead);
  4.         Image1 := TImage.Create(self);
  5.         Image1.Picture.LoadFromStream(astream);
  6.         Image1.Top := -1;
  7. ///////////////////////////////////////////////////////////////////////////////
  8.         Image1.Width :=Image1.Picture.Graphic.Width;
  9.         Image1.Height:=Image1.Picture.Graphic.Height;
  10. ///////////////////////////////////////////////////////////////////////////////
  11.         Image1.Align := altop;
  12.         ScrollBox1.InsertControl(Image1);
  13.         tqry.Previous;
  14.     end;
  15.  
Not sure if this will helps at all, something to test until an lcl developer answers about the 32K upper limit.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: Display Multiple Image In TScrollBox
« Reply #10 on: February 21, 2018, 06:30:12 am »
Look like it is Integer Data Type max value issue
Image.Top ignoring if values is more than 32767
It's about TScrollBox, not TImage. I do not see any limitations. Here is the code, the result is attached.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Image: TImage;
  4.   i: Integer;
  5.   Lbl: TLabel;
  6. begin
  7.   for i := 1 to 600 do
  8.   begin
  9.     Image := TImage.Create(Self);
  10.     Image.Picture.LoadFromFile('c:\lazarus64\components\images\examples\lazarus.jpg');
  11.     Image.Width := Image.Picture.Graphic.Width;
  12.     Image.Height := Image.Picture.Graphic.Height;
  13.     Image.Align := alTop;
  14.     ScrollBox1.InsertControl(Image);
  15.     Lbl := TLabel.Create(Self);
  16.     Lbl.Caption := IntToStr(ScrollBox1.VertScrollBar.Range);
  17.     Lbl.Align := alTop;
  18.     ScrollBox1.InsertControl(Lbl);
  19.   end;
  20. end;

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Display Multiple Image In TScrollBox
« Reply #11 on: February 21, 2018, 07:41:59 am »
Hi

This thread is very similar to one from a couple of weeks a go.

https://forum.lazarus.freepascal.org/index.php/topic,39977.msg275446.html#msg275446
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018