I’m making a program that takes a snapshot of the screen, and saves it to a folder as a Bitmap picture. I seem to be running into a problem though, the picture just overwrites itself.
Can anyone tell me how I can make it so when it saves, the number will be one higher than the last? For example: Save 1: Screenshot0001.bmp Save 2: Screenshot0002.bmp Save 3: Screenshot0003.bmp
And so on.
There are many ways to accomplish something like this.
Do it like your digital camera does; Have a counter and save it in a file or in the registry. You’ll probably run into multi-user problems and you’ll still have to handle situations where an image already exists.
Don’t use a incrementing number, but write a datetime in the filename. FileName := ‘Screenshot_’+FormatDateTime(‘yyyymmdd-hhnnss-zzz.bmp’,now());
Do something like the code below to find the latest number. I think this does what you’re describing, but remember that this code will get slower as you write more images. With thousands of pictures and a slow drive or network it could ‘hang’ your program.
..