Hello,

I have just started using Delphi and ran into a small problem. It's a simple app, as I am only practicing. It has a Button and 2 Edit boxes. I want the user to enter some text to be saved (in a .txt file) in Edit1 and choose a filename by typing it into Edit2.

Heres my code:

var
  F: TextFile;
begin
  AssignFile(F, 'C:\XXXXX.txt');
  Rewrite(F);
  WriteLn(F, Edit1.Text);
  CloseFile(F);
end;

How would I tell the app to save the name as the content of Edit2?

Just as you've shown how to write the contents of edit1, change the string you have in your assign file to be the edit 2..

Like so?

var
  F: TextFile;
begin
  AssignFile(F, 'C:\Edit2.text.txt');
  Rewrite(F);
  WriteLn(F, Edit1.Text);
  CloseFile(F);
end;

Then it makes the filename "Edit2.text" :S

Or am I being stupid?

Id go with a bit of stupid but not a lot..

You still kept it as a string with ' marks, and the c:\ bit and so on..

if you want filename in the box, just use the edit2.text..

If you want to force other things.. that you need to think of, such as what if someone put

NUL in there
or
CON:
or just \

both of which are reserved
and the file wont be written the way you think.

I got it :D

'C:/'+Edit2.text+'.txt'

Thank you for youre help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.