Here is a code snippet that I use to display a set of numImages variables of the number of webcams.
const MaxImages = 24; type TForm1 = class(TForm) ... images: array[1..MaxImages] of TWebcamImage; numImages: integer; .... end;
TWebCamImage is a descendant of TImage with some additional attributes, such as the source url of the webcam, file name for the saved image, and a double-click handler to open the image in an additional panel.
Here is the code used to place the images on the panel.
procedure TForm1.ArrangeImages; var i, numh, numv : integer; const margin=2; begin case numImages of 1: begin numh:=1; numv:=1; end; 2: begin numh:=2; numv:=1; end; 3: begin numh:=3; numv:=1; end; 4: begin numh:=2; numv:=2; end; 5,6: begin numh:=3; numv:=2; end; 7,8: begin numh:=4; numv:=2; end; 9: begin numh:=3; numv:=3; end; 10: begin numh:=5; numv:=2; end; 11,12: begin numh:=4; numv:=3; end; 13,14,15: begin numh:=5; numv:=3; end; 16: begin numh:=4; numv:=4; end; 17,18,19,20: begin numh:=5; numv:=4; end; else begin numh:=6; numv:=4; end; end; for i:=1 to numImages do begin images[i].Width := (panel2.Width div numh) - margin * 2; images[i].Height := (panel2.Height div numv) - margin * 2; images[i].Top := (((i-1) div numh) * (panel2.Height div numv)) + margin; images[i].Left := (((i-1) mod numh) * (panel2.Width div numh)) + margin; end; end;
this method is called when the form connected to the oncreate event and the onresize event is onresize .
procedure TForm1.FormCreate(Sender: TObject); begin ... numImages:=0; for i:=1 to maxImages do begin imageURL:=ini.ReadString('images','imageURL'+intToStr(i),imageURLDefault); if imageURL<>'' then begin inc(numimages); images[numImages]:=TWebCamImage.create(self,panel2,imageURL); end; .... end; .... ArrangeImages; .... end; procedure TForm1.FormResize(Sender: TObject); begin ArrangeImages; end;
source share