Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2022-01

Now sure why this raises Runtime Error 216

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ozz Nixon

Without SetLength(var,0) at the end I get Runtime Error 216 once, adding those - assuming FPC now required me to zero out those fields, I now get the error twice.

Code:
Program MakePrompts;
Type
   Language_File = Record
      Description:Array of Char; {null terminated string}
      Enabled:Boolean;
      SecurityLevel:Byte;        {zero to 255, 255 is reserved for SYSOP}
      Flags:Longint;             {32 Flags - A..Z,1..6}
      MenuPath:Array of Char;
      TextPath:Array of Char;
      QuestPath:Array of Char;
   End;
Var
   L:Language_File;
Procedure Make_Language_File(
   Description,MenuPath,TextPath,QuestPath:String;
   Enabled:Boolean;SecurityLevel:Byte;Flags:Longint);
Var
   FileSize:Longint;
Begin
   Writeln('Language_File empty size is ',SizeOf(L));
   FileSize:=0;
   Description:=Description+#0;
   Inc(FileSize,Length(Description));
   MenuPath:=MenuPath+#0;
   Inc(FileSize,Length(MenuPath));
   TextPath:=TextPath+#0;
   Inc(FileSize,Length(TextPath));
   QuestPath:=QuestPath+#0;
   Inc(FileSize,Length(QuestPath));
   SetLength(L.Description,Length(Description));
   SetLength(L.MenuPath,Length(MenuPath));
   SetLength(L.TextPath,Length(TextPath));
   SetLength(L.QuestPath,Length(QuestPath));
   Move(Description[1],L.Description,Length(Description));
   Move(MenuPath[1],L.MenuPath,Length(MenuPath));
   Move(TextPath[1],L.TextPath,Length(TextPath));
   Move(QuestPath[1],L.QuestPath,Length(QuestPath));
   L.Enabled:=Enabled;
   L.SecurityLevel:=SecurityLevel;
   L.Flags:=Flags;
   Inc(FileSize,6);
   Writeln('Language_File size is ',FileSize);
   SetLength(L.Description,0);
   SetLength(L.MenuPath,0);
   SetLength(L.TextPath,0);
   SetLength(L.QuestPath,0);
End;
Begin
   Make_Language_File('English (c) 2022 by Ozz
Nixon','%ROOTPATH%\MENUS\','%ROOTPATH%\TXTFILES\','%ROOTPATH%\QUESTION\',True,0,0);
End.

Reply by email

Ozz Nixon
to Ozz Nixon

Just incase someone needs to know: (public release, not a custom build). 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]

PM Ozz Nixon wrote 62 lines
Without SetLength(var,0) at the end I get Runtime Error 216 once, adding those - assuming FPC now required me to zero out those fields, I now get the error twice. Code: Program MakePrompts; Type Language_File = Record Description:Array of Char; {null terminated string} Enabled:Boolean; SecurityLevel:Byte; {zero to 255, 255 is reserved for SYSOP} Flags:Longint; {32 Flags - A..Z,1..6} MenuPath:Array of Char; TextPath:Array of Char; QuestPath:Array of Char; End; Var L:Language_File; Procedure Make_Language_File( Description,MenuPath,TextPath,QuestPath:String; Enabled:Boolean;SecurityLevel:Byte;Flags:Longint); Var FileSize:Longint; Begin Writeln('Language_File empty size is ',SizeOf(L)); FileSize:=0; Description:=Description+#0; Inc(FileSize,Length(Description)); MenuPath:=MenuPath+#0; Inc(FileSize,Length(MenuPath)); TextPath:=TextPath+#0; Inc(FileSize,Length(TextPath)); QuestPath:=QuestPath+#0; Inc(FileSize,Length(QuestPath)); SetLength(L.Description,Length(Description)); SetLength(L.MenuPath,Length(MenuPath)); SetLength(L.TextPath,Length(TextPath)); SetLength(L.QuestPath,Length(QuestPath)); Move(Description[1],L.Description,Length(Description)); Move(MenuPath[1],L.MenuPath,Length(MenuPath)); Move(TextPath[1],L.TextPath,Length(TextPath)); Move(QuestPath[1],L.QuestPath,Length(QuestPath)); L.Enabled:=Enabled; L.SecurityLevel:=SecurityLevel; L.Flags:=Flags; Inc(FileSize,6); Writeln('Language_File size is ',FileSize); SetLength(L.Description,0); SetLength(L.MenuPath,0); SetLength(L.TextPath,0); SetLength(L.QuestPath,0); End; Begin Make_Language_File('English (c) 2022 by Ozz Nixon','%ROOTPATH%\MENUS\','%ROOTPATH%\TXTFILES\','%ROOTPATH%\QUESTION\',True,0,0); End.

Reply by email

Michael Van Canneyt
to Ozz Nixon: Without SetLength(var,0) at the end I get Runtime Error 216 once, adding those - assuming…
Ozz Nixon wrote 22 lines
Procedure Make_Language_File( Description,MenuPath,TextPath,QuestPath:String; Enabled:Boolean;SecurityLevel:Byte;Flags:Longint); Var FileSize:Longint; Begin Writeln('Language_File empty size is ',SizeOf(L)); FileSize:=0; Description:=Description+#0; Inc(FileSize,Length(Description)); MenuPath:=MenuPath+#0; Inc(FileSize,Length(MenuPath)); TextPath:=TextPath+#0; Inc(FileSize,Length(TextPath)); QuestPath:=QuestPath+#0; Inc(FileSize,Length(QuestPath)); SetLength(L.Description,Length(Description)); SetLength(L.MenuPath,Length(MenuPath)); SetLength(L.TextPath,Length(TextPath)); SetLength(L.QuestPath,Length(QuestPath)); Move(Description[1],L.Description,Length(Description));

This code is wrong. That must be

Move(Description[1],L.Description[0],Length(Description));
Move(MenuPath[1],L.MenuPath,Length(MenuPath));
Same here.
Move(MenuPath[1],L.MenuPath[0],Length(MenuPath));
Move(TextPath[1],L.TextPath,Length(TextPath));
Same here
Move(TextPath[1],L.TextPath[0],Length(TextPath));
Move(QuestPath[1],L.QuestPath,Length(QuestPath));
Same here.
Move(QuestPath[1],L.QuestPath[0],Length(QuestPath));

These fields are dynamic arrays, in essence pointers to a memory block.

Your code writes to the memory area for pointer, not to the memory area the pointer points to.

Michael.

Reply by email

Ozz Nixon
to Michael Van Canneyt

Ok, I'll check it out. Thanks guys, did not realize it was a pointer, too many years writing scripts instead of code. Thanks!!

PM Michael Van Canneyt wrote 53 lines
On Thu, 6 Jan 2022, Ozz Nixon via fpc-devel wrote: > Procedure Make_Language_File( > Description,MenuPath,TextPath,QuestPath:String; > Enabled:Boolean;SecurityLevel:Byte;Flags:Longint); > Var > FileSize:Longint; > > Begin > Writeln('Language_File empty size is ',SizeOf(L)); > FileSize:=0; > Description:=Description+#0; > Inc(FileSize,Length(Description)); > MenuPath:=MenuPath+#0; > Inc(FileSize,Length(MenuPath)); > TextPath:=TextPath+#0; > Inc(FileSize,Length(TextPath)); > QuestPath:=QuestPath+#0; > Inc(FileSize,Length(QuestPath)); > SetLength(L.Description,Length(Description)); > SetLength(L.MenuPath,Length(MenuPath)); > SetLength(L.TextPath,Length(TextPath)); > SetLength(L.QuestPath,Length(QuestPath)); > Move(Description[1],L.Description,Length(Description)); This code is wrong. That must be Move(Description[1],L.Description[0],Length(Description)); > Move(MenuPath[1],L.MenuPath,Length(MenuPath)); Same here. Move(MenuPath[1],L.MenuPath[0],Length(MenuPath)); > Move(TextPath[1],L.TextPath,Length(TextPath)); Same here Move(TextPath[1],L.TextPath[0],Length(TextPath)); > Move(QuestPath[1],L.QuestPath,Length(QuestPath)); Same here. Move(QuestPath[1],L.QuestPath[0],Length(QuestPath)); These fields are dynamic arrays, in essence pointers to a memory block. Your code writes to the memory area for pointer, not to the memory area the pointer points to. Michael.

Reply by email