Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save File With Program Generated File Name 1

Status
Not open for further replies.

MerryMadDad

Programmer
Dec 11, 2001
47
GB
Hello,

I am trying to save a file with its name generated from a combobox and and edit box, the contents of both change according to what the program is doing.

I use if savedialog.execute then ...

The problem is that when the file is saved its name is not displayed in the save dialog file name box but, the next time a file is saved the previous file name is displayed in the save dialog file name box but the current file is saved with the new program generated file name.
How can I rectify this to display the curent file name in the save dialog file name box ?

I also need to change the file name manually if necessary.

Thanks in advance

 
I think that you need to use the code 'SaveDialog.FileName = Required-File-Name-Here' before showing the Dialog box. This should then allow the file to be saved accordingly.
Hope this helps.
Steve
 
Thanks for your answer - I did try that format too but it still does not show the file name the first time you save a file. It is a simple text file I am saving from a memo.
 
Suppose the file you want to save is called 'TestFile.txt' you would use code like :

tpFileToSave := 'TestFile.txt'
with SaveDialog1 do
begin
InitialDir := ExtractFilePath(Application.ExeName);
Filter := 'Text files (*.txt)|*.TXT';
FileName := tpFileToSave;
DefaultExt := '.txt';
if (Execute = True) then
begin
RichEdit1.Lines.SaveToFile(FileName);
end;
end;

This is code I use for saving from a RichEdit component but the logic is the same. Might also be worth putting a check in to see if the file already exists in case the user overwrites an existing file - better safe than sorry :)
Hope that this helps ...
Steve
 
Hi Steven,

Thank you for your answer above - it solved the problem completely - I tried it over the week-end and now the program works like I want it to.

Best Regards

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top