Recent

Author Topic: Same Source - different OS - different results. (FileOpen Access Violation WinXP  (Read 7619 times)

ozznixon

  • Full Member
  • ***
  • Posts: 119
    • http://www.modernpascal.com/
Code: Pascal  [Select][+][-]
  1. Begin
  2.    S:='Hello World!';
  3.    Handle:=FileCreate('testing.123',2,438);
  4.    FileWrite(Handle,@S[1],Length(S));
  5.    FileClose(Handle);
  6. End.

Run on Mac OSX - Success
Run on Linux - Success
Run on Windows - "Access Violation" (File Create).

* I have tried different 2nd Parameters, I changed to simply FileCreate('testing.123') - same error, same line.

If I change code to use Assign(File,'testing.123'); Rewrite(File,1); etc. works on Windows.

Quote
Free Pascal Compiler version 3.0.4 [2017/10/06] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
C:\FPC\3.0.4\bin\i386-Win32\fpc.exe [options] <inputfile> [options]
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Try:
Code: Pascal  [Select][+][-]
  1.   S:='Hello World!';
  2.   Handle:=FileCreate('testing.123',fmOpenReadWrite or fmShareDenyNone,438);
  3.   FileWrite(Handle,S[1],Length(S));
  4.   FileClose(Handle);

ozznixon

  • Full Member
  • ***
  • Posts: 119
    • http://www.modernpascal.com/
Thanks, tried that too. It is very odd, may be a 3.0.4 issue. I have had very odd problems with I port my working code to Windows. (rarely code for Windows for the past decade, but, this is simple file I/O 102.

Ozz
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Just tested this on WinXp:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, sysutils
  10.   { you can add units after this };
  11.  
  12. var
  13.   S: string;
  14.   Handle:THandle;
  15. begin
  16.   S:='Hello World!';
  17.   Handle:=FileCreate('testing.123',fmOpenReadWrite or fmShareDenyNone,438);
  18.   FileWrite(Handle,S[1],Length(S));
  19.   FileClose(Handle);
  20. end.

I guess your problem is outside this code.

ozznixon

  • Full Member
  • ***
  • Posts: 119
    • http://www.modernpascal.com/
@engkin - thanks, I will synchronize to a newer build than 3.0.4 and see what happens. The code works fine on my Win10 64bit environment.

Thank you for your time!
Ozz
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

engkin

  • Hero Member
  • *****
  • Posts: 3112
My test is on FPC 3.0.4. Just make sure your file 'testing.123' is not open with another application, or something similar.

ozznixon

  • Full Member
  • ***
  • Posts: 119
    • http://www.modernpascal.com/
@engkin ... it is something with "create file" even this raises the same error:

(typed off the top of my head, but using old Pascal syntax same error):
Assign(BFH,'testing.456');
Rewrite(BFH,1); <--- Access Violation
Close(BFH);

Again the code works on Linux and Mac, hmmm.
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

lucamar

  • Hero Member
  • *****
  • Posts: 4219
There must be something else wrong in either your program or your system. I've just tested both alternatives in two different machines, with 32 bits Windows XP Home and Professional, with Lazarus/FPC 1.8.4/3.0.4 and they worked as they should.

Also tested in Linux and it also works without more ado.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

sash

  • Sr. Member
  • ****
  • Posts: 366
Code: Pascal  [Select][+][-]
  1. Begin
  2.    S:='Hello World!';
  3.    Handle:=FileCreate('testing.123',2,438);
  4.    FileWrite(Handle,@S[1],Length(S));
  5.    FileClose(Handle);
  6. End.

Try not to use relaxing defaults:

  - Check Handle validity
  - Use full path (or explicitly change current directory).
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

engkin

  • Hero Member
  • *****
  • Posts: 3112
@engkin ... it is something with "create file" even this raises the same error:

(typed off the top of my head, but using old Pascal syntax same error):
Assign(BFH,'testing.456');
Rewrite(BFH,1); <--- Access Violation
Close(BFH);

Again the code works on Linux and Mac, hmmm.

This post contradicts your first post:
Quote
If I change code to use Assign(File,'testing.123'); Rewrite(File,1); etc. works on Windows.

My guess: it works, you open the file 'testing.123' or 'testing.456' with some application to check the contents and it blocks access to it, maybe?

Cyrax

  • Hero Member
  • *****
  • Posts: 836
@engkin ... it is something with "create file" even this raises the same error:

(typed off the top of my head, but using old Pascal syntax same error):
Assign(BFH,'testing.456');
Rewrite(BFH,1); <--- Access Violation
Close(BFH);

Again the code works on Linux and Mac, hmmm.

In under what directory structure you are saving your project files? Please check security permission settings of your directories.

 

TinyPortal © 2005-2018