I was wondering if you could use a picture dialog to select an image, then copy the selected image to the folder of the program(that ran the picture dialog)'s exe.
Thanks in advance.
I was wondering if you could use a picture dialog to select an image, then copy the selected image to the folder of the program(that ran the picture dialog)'s exe.
Thanks in advance.
something like this?
[code=pascal]
procedure TForm1.Button1Click(Sender: TObject);
var filepath, pictureFileName, fileToCopy : string;
begin
filepath := ExtractFilePath(application.ExeName);
if (openPictureDialog1.Execute) then
begin
fileToCopy := openPictureDialog1.Filename;
pictureFileName := ExtractFileName(openPictureDialog1.Filename);
if copyFile(pchar(fileToCopy), pchar(filepath+pictureFileName),true) then
messagedlg('file succesfully copied', mtinformation, [mbok],0)
else
messagedlg('file was not copied!', mterror, [mbok],0)
end;
end;
[/code]
Thanks!! Works wonderfully.
Just a small question, to rename the copied file, should I just change the PictureFileName variable?
Yes, that is correct. You do need to extract the original file extension though, if you want to change the filename.
Thank you. Is there some specific code required to extract the extension?
If you want to change the file extension of a filename just do something like so:Originally Posted by Cer3brus
[pascal]FileName := ChangeFileExt(FileName,'.bmp');[/pascal]
This will change the file extension to '.bmp' for example...
If you want to extract a file extension:
[pascal]Ext := ExtractFileExt(FileName);[/pascal]
cheers,
Paul
Games:
Seafox
Pages:
Syntax Error Software itch.io page
Online Chess
http://gameknot.com/#paul_nicholls
Bookmarks