Recent

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

ozznixon

  • Jr. Member
  • **
  • Posts: 85
    • 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: 2513
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

  • Jr. Member
  • **
  • Posts: 85
    • 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: 2513
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

  • Jr. Member
  • **
  • Posts: 85
    • 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: 2513
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

  • Jr. Member
  • **
  • Posts: 85
    • 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: 1982
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 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

sash

  • Sr. Member
  • ****
  • Posts: 265
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.2 FPC 3.0.4 x86_64-linux-gtk2 -- Ubuntu 19.04 XFCE

engkin

  • Hero Member
  • *****
  • Posts: 2513
@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: 741
@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.