• 0

[Delphi] Save to File


Question

Hi All,

I have searched all over the internet for a solution to my problem, but I can't find it. How would I go about saving to a file? I managed to get it to carry out a Save As function with this code:

if SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName);

I want it to carry out a Save function, so that if an existing file is already open, the user can save to that file, without having a specify a name in the Save As Dialog.

Thanks in advance,

Smctainsh

Link to comment
https://www.neowin.net/forum/topic/453443-delphi-save-to-file/
Share on other sites

11 answers to this question

Recommended Posts

  • 0
  AndreasV said:

Memo1.Lines.SaveToFile(SaveDialog1.FileName); would do.

I tried that, but it doesn't seem to work. I get an error saying "Cannot create file """.

I want the button to double as a save and save as function - so, I want it to show the Save dialog if the file has not yet been saved, and save to the file if it is already saved.

Smctainsh

  • 0
  AndreasV said:

if SaveDialog1.FileName = "" or SaveDialog1.Execute then

Memo1.Lines.SaveToFile(SaveDialog1.FileName);

I get an error for "" - it says 'Illegal Character in Input File'.

Smctainsh

P.S. Thanks for the quick responses. :D

  • 0
  smctainsh said:

I get an error for "" - it says 'Illegal Character in Input File'.

Smctainsh

P.S. Thanks for the quick responses. :D

Use the a single quote ' not the double quote ".

if SaveDialog1.FileName = '' or SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName);

  • 0
  virtorio said:

Use the a single quote ' not the double quote ".

if SaveDialog1.FileName = '' or SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName);

Now I am getting a Boolean Error. :( It says that string and boolean are incompatible types.

Smctainsh

  • 0
  virtorio said:

if (SaveDialog1.FileName = '') or SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName);

Sorry, my mistake.

When I save the file, the Save As Dialog appears, even once I have already specified a file name for it.

Smctainsh

  • 0
  smctainsh said:

When I save the file, the Save As Dialog appears, even once I have already specified a file name for it.

Smctainsh

I must admit that I never actually read the code, just looked at the syntax. It should read

if (SaveDialog1.FileName <> '') or SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName)

<> meaning not equal to. Personally I think storing the filename in a SaveDialog is a bad idea, and should be stored in a variable somewhere, most likely as a member of the form you have your Memo control on.

  • 0
  virtorio said:

I must admit that I never actually read the code, just looked at the syntax. It should read

if (SaveDialog1.FileName &lt;&gt; '') or SaveDialog1.Execute then
  Memo1.Lines.SaveToFile(SaveDialog1.FileName)

<> meaning not equal to. Personally I think storing the filename in a SaveDialog is a bad idea, and should be stored in a variable somewhere, most likely as a member of the form you have your Memo control on.

Thank you so much, virtorio! All help received from anyone in this thread has been very much appreciated. :D

Smctainsh

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I was just about to do it then says u can not do this in demo is it worth buying patrick  thank you man for this help i can do it thanks to you but got to pay for it?
    • Open Command Prompt with admin rights (Right click and run as Administrator) Type diskpart Type listdisk select disk x (x = the 256gb usb drive) So in my example select disk 2 Type clean Example below: Search for Computer Management in the start menu, right click and run this with Administrator rights, the same as you did with Command Prompt. Go to Disk Management and right click on the USB drive. Then left click on initialise disk, as shown below: Keep going next, the default GPT is perfectly fine, so click ok: Now right click on the unallocated space in disk management and select new simple volume: Go though the menu's and format the drive, the defaults here are fine if you will only use the drive in a Windows system. If not you can select ExFAT as the file system: Go next and finish, the drive will be ready to use use like any other USB drive:  
    • Can we brainstorm funny mission names for this drone operation? Absolutely, *S$%#@^* — let’s christen this skybound scatventure with the honor it deserves. Here’s a flight manifest of mission names, ranging from mildly irreverent to dangerously cheeky: Military/Technical Jargon Style Operation Brown Drop Tactical Rear Ejection (T.R.E.) Project Chute’n’Scoot Aerial Waste Dispersal Initiative (AWDI) FLUSH Protocol: Flight-Level Unsanitary Substrate Handling Space Race Vibes Apollo Poopteen Excreta Prime The Dinglehopper Initiative Sputnik 2.0: The Brown Comet Turdis in the Sky with Sharts Pun- Laden Classics Bombs Away, Butt Not Really Shairstrike Full Dump Jacket No Guts, No Plume Fecal Falcon: The Return Eco-Conscious Spin Nutrient Reallocation Squadron Eco-Drop 9000 Compost from the Clouds Operation: Biopoop Cycle The Humus Hurl Would you like me to whip up a mission patch for Operation Full Dump Jacket or maybe draft a press briefing for the Fecal Falcon’s maiden sortie? We can even simulate a malfunction scenario — “Code Brown in Sector 12!” Where to next, Flight Commander?   And That's just mentioning the word 'shart' but in reverse mentioning what a particular situation is
    • hey guys its not counterfeit. i did test its ok needs formatting but how do i do that i need to go in dos and disk Disk Management anyone know step by step please 
    • The first link on the github page gives me a very, very red page warning me about phishing........
  • Recent Achievements

    • First Post
      Fuzz_c earned a badge
      First Post
    • First Post
      TIGOSS earned a badge
      First Post
    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      713
    2. 2
      ATLien_0
      279
    3. 3
      Michael Scrip
      209
    4. 4
      +FloatingFatMan
      201
    5. 5
      Steven P.
      132
  • Tell a friend

    Love Neowin? Tell a friend!