Saving a bitmap image to new file

In Reply to question "Saving bitmap image from clipboard to file"

: I managed to save an image from clipboard to file using:
: if Clipboard.HasFormat(CF_BITMAP) then begin
: Image1.Picture.Assign(Clipboard);
: Image1.Picture.SaveToFile('c:\test\abc.bmp');
: end;

: How do I get it to save to a different file name and not overwrite the existing one (say abc,abc1,abc2etc.)

Here's a Delphi Source code example for storing up to 10000 images under the same "base name". Just increase the MaxFiles number if that is not enough ;)

const
  BaseName = 'c:\test\abc';
  MaxFiles = 10000;
var
  i: integer;
  FileName: string;
begin
  ...
  for i := 1 to MaxFiles do begin
    FileName := BaseName + IntToStr(i) + '.bmp';
    if not FileExists(FileName) then break;
  end;
  Image1.Picture.SaveToFile(FileName);
  ...



Members of the DelphiLand Club can access the full version of our tutorials, including all fully commented source code files.

Click here to become a DelphiLand Club member.