Topic: Random Image in Panel

Hello Mvd!

I need a sample on random image in panel when when form is shown.... anybody from the wizards of MVD family.

Thanks!

2 (edited by derek 2019-05-21 17:49:33)

Re: Random Image in Panel

Hi Manixs,
I suppose the 'correct' way would be to read through the images in a directory and load the file names into some sort of stringlist etc.
But if the number of images is fixed, I'd probably do it very simply as per the attached example (if you have a large number of images, use a batch utility to rename them 1.jpg, 2.jpg, 3.jpg ,4.jpg etc and then alter the script to however many images you have).
Derek

Post's attachments

Attachment icon randomimages.zip 922.14 kb, 301 downloads since 2019-05-21 

3 (edited by manixs2013 2019-05-22 02:48:07)

Re: Random Image in Panel

Hello Derek

There was an error with me... please..

thanks!

Post's attachments

Attachment icon Capture.PNG 11.62 kb, 131 downloads since 2019-05-22 

Re: Random Image in Panel

manixs2013,
The Random function has recently changed.  Try the following:

vrandompicture := 'images\' + inttostr(random(6)) + '.jpg';

Re: Random Image in Panel

YESSSSS


Thanks to ehwagner.. and derek!

Re: Random Image in Panel

manixs2013,
Derek mentioned about another option which would be to extract the file list from the image directory into a stringlist. I went ahead and put together such a project. See attached.

Doing it this way, you do not need to rename all images and you do not need to know the number of files in the folder for the random number.

Post's attachments

Attachment icon randomimages another option.zip 1.14 mb, 306 downloads since 2019-05-22 

Re: Random Image in Panel

Thank 5x very much ehwagner!