Lazarus

Programming => Operating Systems => Topic started by: ozznixon on January 30, 2019, 01:45:27 am

Title: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: ozznixon on January 30, 2019, 01:45:27 am
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]
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: engkin on January 30, 2019, 02:26:06 am
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);
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: ozznixon on January 30, 2019, 03:27:56 am
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
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: engkin on January 30, 2019, 04:17:05 am
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.
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: ozznixon on January 30, 2019, 06:53:13 pm
@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
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: engkin on January 30, 2019, 08:26:58 pm
My test is on FPC 3.0.4. Just make sure your file 'testing.123' is not open with another application, or something similar.
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: ozznixon on January 30, 2019, 10:21:04 pm
@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.
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: lucamar on January 30, 2019, 10:32:19 pm
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.
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: sash on January 30, 2019, 10:52:35 pm
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).
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: engkin on January 30, 2019, 11:02:05 pm
@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?
Title: Re: Same Source - different OS - different results. (FileOpen Access Violation WinXP
Post by: Cyrax on January 31, 2019, 12:43:33 am
@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