Recent

Author Topic: The weird Rewrite bug  (Read 4769 times)

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: The weird Rewrite bug
« Reply #15 on: May 08, 2024, 01:36:55 am »
What OS and filesystem is that?
Did you try some other location or USB flash drive?
Do you have some special file/directory permissions?
Do you run some AV software, cloud synchronisation, backup software or something similar which could interfere with filesystem?
Did you try to test it on different computer?

It's just Windows 11.
Location is the same, I showed you that it makes the file in the beginning, and then it doesn't want to rewrite() for overwriting.
Location is nothing special, a folder on my data partition on the big SSD drive that replaced the older HDD.
There is nothing that can possibly interfere with that.
Ok, I'll get it to run on a Windows VM...

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: The weird Rewrite bug
« Reply #16 on: May 08, 2024, 01:39:06 am »
There is no weird rewrite bug. he needs to keep the handle open and use append.
that was already mentioned? Or if the handle is closed open it and do append(handle).

The proper way to handle this is - of course again - in the manuals:
https://www.freepascal.org/docs-html/rtl/system/seek.html
https://www.freepascal.org/docs-html/rtl/system/append.html#:~:text=Append%20opens%20an%20existing%20file%20in%20append%20mode.,is%20not%20taken%20into%20account%20when%20calling%20Append.
Full example. note:  Filemode=2 meaning r/w. and then reset, not rewrite and then append.
More docs:
https://www.freepascal.org/docs-html/rtl/system/filemode.html

So, now, what? is weird? It has always been that way.
Code: Pascal  [Select][+][-]
  1. program filehandling;
  2. var
  3.   Handle:Text;
  4.   Fn:string = 'test.txt';
  5. begin
  6.   Assign(Handle,Fn);
  7.   Rewrite(Handle);
  8.   writeln(Handle, 'First part');
  9.   Close(Handle);
  10.  
  11.   FileMode := 2; // open read/write
  12.  
  13.   Assign(Handle, Fn);
  14.   Reset(Handle);// NOT rewrite
  15.   Append(Handle);//Goto eof
  16.   Writeln(Handle,'Second part');
  17.   Close(Handle);
  18.   // You may want to restore filemode hereafter.
  19. end.
Code: Bash  [Select][+][-]
  1. cat test.txt
  2. First part
  3. Second part
Please read the manuals first, ask later.

But I don't want to append, I want to write over. It's the save button, it has to replace the file with whatever is new.

ASBzone

  • Hero Member
  • *****
  • Posts: 717
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: The weird Rewrite bug
« Reply #17 on: May 08, 2024, 03:35:16 am »
What are the permissions on the file you are creating?


Also, can you try to save the files somewhere else, on a different drive?  (Maybe an external one?)
-ASB: https://www.BrainWaveCC.com/

Lazarus v3.5.0.0 (2216170cde) / FPC v3.2.3-1387-g3795cadbc8
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

dseligo

  • Hero Member
  • *****
  • Posts: 1455
Re: The weird Rewrite bug
« Reply #18 on: May 08, 2024, 10:24:55 am »
What OS and filesystem is that?
Did you try some other location or USB flash drive?
Do you have some special file/directory permissions?
Do you run some AV software, cloud synchronisation, backup software or something similar which could interfere with filesystem?
Did you try to test it on different computer?

It's just Windows 11.
Location is the same, I showed you that it makes the file in the beginning, and then it doesn't want to rewrite() for overwriting.
Location is nothing special, a folder on my data partition on the big SSD drive that replaced the older HDD.
There is nothing that can possibly interfere with that.
Ok, I'll get it to run on a Windows VM...

There *is* something that interfere with your file, that is the reason I wrote possibilities that I could think of.
It could be something in your program, it could be open in external program, it could be something with OS, with AV, ...

Maybe you could try at the same time (at the beginning of your SaveToFile method) to create/rewrite some other file (try in the same location and also somewhere else), just for test. See if that works or fails.

dseligo

  • Hero Member
  • *****
  • Posts: 1455
Re: The weird Rewrite bug
« Reply #19 on: May 08, 2024, 10:35:27 am »
Oh, and I just tried your code and it doesn't compile:
Error: Wrong number of parameters specified for call to "Assign"

So what is your Lazarus version and mode in which you compile this?
It would be best if you could make small compileable project that shows your problem and post it here.

Also, in one of your posts you wrote this:
Quote
This code is from SmartPascal.

What did you mean by this?

Thaddy

  • Hero Member
  • *****
  • Posts: 16411
  • Censorship about opinions does not belong here.
Re: The weird Rewrite bug
« Reply #20 on: May 08, 2024, 10:43:59 am »
Smart pascal is basically a scripting language.
If he wants to overwrite, btw, he can leave out append. or use seek() if he wants to overwrite something specific.
There is nothing wrong with being blunt. At a minimum it is also honest.

 

TinyPortal © 2005-2018