Recent

Author Topic: Disk Write Error  (Read 1010 times)

PeterHu

  • Newbie
  • Posts: 6
Disk Write Error
« on: August 12, 2022, 04:30:46 am »
Greetings!

Just a console test program to see whether can display asian font---Reading from a txt file which contains Chinese.But got error:
1. Compiler error:disk write error;
2.when directly run the program in windows10 console,
a. it said disk full;
b. it does not display Chinese properly.

What did I do wrong?Please help!

Thanks in advance.

PS:Below code is from online tutorials.

Code: Pascal  [Select][+][-]
  1. program filereadex1;
  2.  {H+ $CODEPAGE=UTF8}
  3. uses
  4.  Sysutils;
  5.  
  6.  
  7. const
  8.   C_FNAME = 'textfile.txt';
  9.  
  10. var
  11.   tfIn: TextFile;
  12.   s: string;
  13.  
  14. begin
  15.   // Give some feedback
  16.   writeln('Reading the contents of file: ', C_FNAME);
  17.   writeln('=========================================');
  18.  
  19.   // Set the name of the file that will be read
  20.   AssignFile(tfIn, C_FNAME);
  21.  
  22.   // Embed the file handling in a try/except block to handle errors gracefully
  23.   try
  24.     // Open the file for reading
  25.     reset(tfIn);
  26.  
  27.     // Keep reading lines until the end of the file is reached
  28.     while not eof(tfIn) do
  29.     begin
  30.       readln(tfIn, s);
  31.       writeln(s);
  32.     end;
  33.  
  34.     // Done so close the file
  35.     CloseFile(tfIn);
  36.  
  37.   except
  38.     on E: EInOutError do
  39.      writeln('File handling error occurred. Details: ', E.Message);
  40.   end;
  41.  
  42.   // Wait for the user to end the program
  43.   writeln('=========================================');
  44.   writeln('File ', C_FNAME, ' was probably read. Press enter to stop.');
  45.   readln;
  46. end.                                    
  47.  

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Disk Write Error
« Reply #1 on: August 12, 2022, 05:17:34 am »
I tested your code using Lazarus 2.2.2 on Ubuntu Mate 22.04 64-bit, it worked without problem.

Download and try the source code I provided. If you still get the error, maybe there is something wrong with your Lazarus installation or your system.

PeterHu

  • Newbie
  • Posts: 6
Re: Disk Write Error
« Reply #2 on: August 12, 2022, 05:36:06 am »
Thanks for the reply.

Sorry,still the same ,failed to pass.Disk write error.

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Disk Write Error
« Reply #3 on: August 12, 2022, 07:54:32 am »
There are many file handling demos you can download and test in the link below:
https://wiki.freepascal.org/Portal:HowTo_Demos#File_handling

If the error still happen on those demos, I think you should reinstall your Lazarus/FPC.

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: Disk Write Error
« Reply #4 on: August 12, 2022, 10:21:40 am »
I had to add
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
to your code to be able to compile it in fp.
Can you read your file in command prompt (type textfile.txt)?
Try this text file without Chinese characters, i.e. only 'abcd'.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Disk Write Error
« Reply #5 on: August 12, 2022, 11:56:34 am »
1. Compiler error:disk write error;
How did you compile?
From commandline, from within the FP IDE (text based)?
What version of the compiler?
(I suppose your disk is not full, otherwise the error would be self-explanatory).

2.when directly run the program in windows10 console,

How can you run the program if you cannot compile it?

To be able to display Chinese text on the console, your console muste be able to display them.
Unless you have a "Chinese" locale, this by default is not the case.
Also you need to know what codepage the text file in question uses: a Windows ANSI codepage, UTF8, UTF16, something else?
Otherwise it's just a guessing game.

Bart

PeterHu

  • Newbie
  • Posts: 6
Re: Disk Write Error
« Reply #6 on: August 12, 2022, 02:11:55 pm »
I had to add
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
to your code to be able to compile it in fp.
Can you read your file in command prompt (type textfile.txt)?
Try this text file without Chinese characters, i.e. only 'abcd'.

Yes,I can read either with or without Chinese characters by 'type textfile.txt' cmd prompt,but Chinese characters won't display properly.
In Lazarus,even I have given a {$CODEPAGE UTF8},the program still can not display Chinese characters properly.

PeterHu

  • Newbie
  • Posts: 6
Re: Disk Write Error
« Reply #7 on: August 12, 2022, 02:34:17 pm »
1. Compiler error:disk write error;
How did you compile?
From commandline, from within the FP IDE (text based)?
What version of the compiler?
(I suppose your disk is not full, otherwise the error would be self-explanatory).

Peter:the lastest Lazarus,ver2.2.2,compile & run by hit F9.


2.when directly run the program in windows10 console,

How can you run the program if you cannot compile it?

Peter:It seems that it compiled but failed to run.*.exe has been created there.

To be able to display Chinese text on the console, your console muste be able to display them.
Unless you have a "Chinese" locale, this by default is not the case.
Also you need to know what codepage the text file in question uses: a Windows ANSI codepage, UTF8, UTF16, something else?

Peter:The default codepage is 936.

Otherwise it's just a guessing game.

Bart

I tried to run the program from cmd prompt,got the screenshot as the second one shown.

Under Win10 console input & output with Chinese characters,we local people care this issue whenever we try to use a new programming language or IDE.The day before yesterday,we tried in Lazarus and it turns out it can display Chinese characters properly as long as we set {$CODEPAGE UTF8} and that's enough,no need to setConsoleCP/setConsoleOutputCP or,using UTF8toansi funciton.
Code: Pascal  [Select][+][-]
  1.  
  2. program cnlocale;
  3. {$CODEPAGE UTF8}
  4. uses
  5.   Windows;
  6.   var msg:string;
  7. begin
  8.  
  9.   msg:='早上好!';
  10.   writeln('first try');
  11.   writeln(msg);
  12.  
  13.  
  14.   //SetTextCodePage(Output, CP_UTF8);
  15.   //SetConsoleCP(CP_UTF8);//try to set console codepage
  16.   //SetConsoleOutputCP(CP_UTF8);  //try to set console output codepage
  17.  
  18.   writeln('second try');
  19.   //writeln(utf8toansi(msg));
  20.   //writeln(utf8toansi('早上好!'));
  21.   writeln('你好Freepascal!');
  22.   writeln('Freepascal & Lazarus好极了!我喜欢!');
  23.  
  24.  
  25.   readln;
  26. end.
  27.        
  28.  

But this time when play with text file,we failed.

Going back to the readfile program,if I delete those Chinese characters in the textfile,the program compiled and the debug windows does not show any more,and no "disk is full "error appear.


Here attached the textfile been read in the program.
« Last Edit: August 12, 2022, 03:01:26 pm by PeterHu »

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: Disk Write Error
« Reply #8 on: August 12, 2022, 03:00:09 pm »
This is crash inside FPC, so tell us FPC version.
Run FPC in Win10 console to show its version.

PeterHu

  • Newbie
  • Posts: 6
Re: Disk Write Error
« Reply #9 on: August 12, 2022, 03:07:02 pm »
This is crash inside FPC, so tell us FPC version.
Run FPC in Win10 console to show its version.

D:\lazarus\fpc\3.2.2\bin\x86_64-win64>fpc
Free Pascal Compiler version 3.2.2 [2022/05/15] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
D:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe [options] <inputfile> [options]
 Only options valid for the default or selected platform are listed.
 Put + after a boolean switch option to enable it, - to disable it.
  @<x>   Read compiler options from <x> in addition to the default fpc.cfg
  -a     The compiler does not delete the generated assembler file
      -a5        Don't generate Big Obj COFF files for GNU Binutils older than 2.25 (Windows, NativeNT)
      -al        List sourcecode lines in assembler file
      -an        List node info in assembler file (-dEXTDEBUG compiler)
      -ao        Add an extra option to external assembler call (ignored for internal)
      -ar        List register allocation/release info in assembler file
      -at        List temp allocation/release info in assembler file
  -A<x>  Output format:
      -Adefault  Use default assembler
      -Aas       Assemble using GNU AS
      -Agas      Assemble using GNU GAS
      -Agas-darwin Assemble darwin Mach-O64 using GNU GAS
      -Amasm     Win64 object file using ml64 (Microsoft)

Thanks for you all for the help!

 

TinyPortal © 2005-2018