Recent

Author Topic: xgraph.pas "failure 235/35 can't read Variables of this type"  (Read 410 times)

coradi

  • Full Member
  • ***
  • Posts: 121
xgraph.pas "failure 235/35 can't read Variables of this type"
« on: November 23, 2022, 10:25:02 am »
It's from the Book, Turbo Pascal for Kids

xgraph.pas

Got the failure  235/35 can't read Variables of this type

Code: [Select]
{-----------------------------------------------------------------------
This unit declares a unit containing procedures etc. that are normally
(i.e., in Turbo Pascal) provided by the units 'graph' and 'crt'. The actual
implementation of most of these is not contained in this unit, but in
puff_c.c, which is written in C, and uses the X11 window system (hence
this unit's name).
The implementations here and in puff_c.c are not complete: they are limited
to what is needed for compiling and using the PUFF software. As such, they
may or may not be useful for compiling other graphical Turbo Pascal
applications under Linux, depending on the requirements of such applications.
This unit and puff_c.c also contain a few other routines that were used in
the Linux port of PUFF but do not exist in Turbo Pascal: these were needed
because some things must (for efficiency or other reasons) be implemented
differently on Linux than on MS-DOS.
Parts (support for readln and writeln) are copyright (c) 1999-2000 by Michael
Van Canneyt and Peter Vreman, members of the Free Pascal development team.
Rest is copyright (c) 2000, by Pieter-Tjerk de Boer, pa3fwm@amsat.org.
This software is distributed under the conditions of version 3 of the GNU
General Public License from the Free Software Foundation.
-----------------------------------------------------------------------}

{$T-}    {No output sections}

Unit xgraph;


Interface


TYPE
  ViewPortType = Record
    X1,Y1,X2,Y2 : Integer;
    Clip : Boolean
  end;


Procedure InitGraph (var GraphDriver,GraphModus : integer; const PathToDriver : string); cdecl; external;
Procedure CloseGraph ; cdecl; external;

Procedure SetColor (Color : Longint); cdecl; external;
Procedure SetFillStyle (Pattern,Color : Longint); cdecl; external;
Procedure SetLineStyle (LineStyle,Pattern,Width : Longint); cdecl; external;

Procedure Line (X1,Y1,X2,Y2 : Longint); cdecl; external;
Procedure PutPixel (X,Y : Longint; Color : Longint); cdecl; external;
Procedure Bar (X1,Y1,X2,Y2 : Longint); cdecl; external;
Procedure Rectangle (X1,Y1,X2,Y2 : Longint); cdecl; external;
Procedure Arc (X,Y : Longint; start,stop, radius : Longint); cdecl; external;
Procedure FillEllipse (X,Y : Longint; Xradius,YRadius: Longint); cdecl; external;
Procedure Circle (X,Y : Longint; Radius : Longint); cdecl; external;
Procedure FloodFill (X,Y : Longint; BorderColor : Longint); cdecl; external;

Procedure SetTextJustify (Horizontal,Vertical : Longint); cdecl; external;
Procedure OutTextXY (X,Y : Integer; Const TextString : String);

Procedure SetViewPort (X1,Y1,X2,Y2 : Longint; Clip : Boolean); cdecl; external;

Function GetBkColor : Longint; cdecl; external;
Procedure SetBkColor (Color : Longint); cdecl; external;

Function GraphErrorMsg (ErrorCode : Longint) : String; cdecl; external;
Function GraphResult : Longint; cdecl; external;


Procedure GetBox(bn, x, y, width, height: Longint); cdecl; external;
Procedure PutBox(bn, x, y, width, height: Longint); cdecl; external;


VAR
  ScreenHeight:integer; external name 'ScreenHeight';
  ScreenWidth:integer; external name 'ScreenWidth';


CONST
  SOLIDFILL=0;
  lefttext=0;
  centertext=1;
  righttext=2;
  userbitln=4;
  normwidth=1;
  solidln=0;
  VGA=0;
  EGA=1;
  GROK=0;





CONST
  Black = 0;
  Blue = 1;
  Green = 2;
  Cyan = 3;
  Red = 4;
  Magenta = 5;
  Brown = 6;
  LightGray = 7;
  DarkGray = 8;
  LightBlue = 9;
  LightGreen = 10;
  LightCyan = 11;
  LightRed = 12;
  LightMagenta = 13;
  Yellow = 14;
  White = 15;
  co80 = 3;
  WindMax: Word = $184f;
  LastMode: Word = 3;
  DirectVideo: Boolean = False;




Procedure Window (X1, Y1, X2, Y2: Longint); cdecl; external name 'crtWindow';
Procedure GotoXY (X: Longint; Y: Longint); cdecl; external;
Procedure Sound (hz : Longint); cdecl; external;
Procedure Delay (DTime: Longint); cdecl; external;
Procedure NoSound ; cdecl; external;
Function KeyPressed : Boolean; cdecl; external;
Function ReadKey : Char; cdecl; external;
procedure TextMode(Mode: Longint); cdecl; external;
Procedure TextColor (CL: Longint); cdecl; external;
Procedure TextBackground (CL: Longint); cdecl; external;
Procedure ClrScr ; cdecl; external;


Function GetTimerTicks : Integer; cdecl; external;




Implementation


uses dos,linux;




Procedure C_OutTextXY (X,Y : Longint; Var TextString : String); cdecl; external;

Procedure OutTextXY (X,Y : Integer; Const TextString : String);
var s: string;
begin
   s:=TextString;
   C_OutTextXY(X,Y,s);
end;




{ write(ln) and readln support code based on rtl/linux/crt.pp from the fpc source tree }

procedure DoWrite(var s: string); cdecl; external;
procedure DoWriteEnd; cdecl; external;


Function xgraphWrite(Var F: TextRec): Integer;
Var
  Temp : String;
  idx,i : Longint;
Begin
  idx:=0;
  while (F.BufPos>0) do
   begin
     i:=F.BufPos;
     if i>255 then
      i:=255;
     Move(F.BufPTR^[idx],Temp[1],i);
     SetLength(Temp,i);
     DoWrite(Temp);
     dec(F.BufPos,i);
     inc(idx,i);
   end;

  DoWriteEnd;
  xgraphWrite:=0;
End;



Function xgraphRead(Var F: TextRec): Integer;
{
  Read from CRT associated file.
}
var
  c : char;
  i : longint;
Begin
      F.BufPos := 0;
      i := 0;
      repeat
        c := readkey;
        case c of
          { ignore special keys }
          #0:
            c:= readkey;
          { Backspace }
          #8:
            if i > 0 then
              begin
                write(#8#32#8);
                dec(i);
              end;
          { Unhandled extended key }
          #27:;
          { CR }
          #13:
            begin
              F.BufPtr^[i] := #10;
              write(#10);
              inc(i);
            end;
          else
            begin
              write(c);
              F.BufPtr^[i] := c;
              inc(i);
            end;
        end;
      until (c in [#10,#13]) or (i >= F.BufSize);
      F.BufEnd := i;
      xgraphRead := 0;
      exit;
End;


Function xgraphReturn(Var F:TextRec):Integer;
Begin
  xgraphReturn:=0;
end;




Function xgraphOpen(Var F: TextRec): Integer;
Begin
  If F.Mode=fmOutput Then
   begin
     TextRec(F).InOutFunc:=@xgraphWrite;
     TextRec(F).FlushFunc:=@xgraphWrite;
   end;
  If F.Mode=fmInput Then
   begin
     TextRec(F).InOutFunc:=@xgraphRead;
     TextRec(F).FlushFunc:=@xgraphReturn;
   end;
  xgraphOpen:=0;
End;



procedure init_x; cdecl; external;


Initialization

  Assign(Output,'');
  TextRec(Output).OpenFunc:=@xgraphOpen;
  Rewrite(Output);
  TextRec(Output).Handle:=StdOutputHandle;
  Assign(Input,'');
  TextRec(Input).OpenFunc:=@xgraphOpen;
  Reset(Input);
  TextRec(Input).Handle:=StdInputHandle;

  init_x();
{
  ScreenHeight:=500;
  ScreenWidth:=1000;
}

end.
Amstrad Schneider CPC 6128
Wind XP / 7 / 10

Thaddy

  • Hero Member
  • *****
  • Posts: 12212
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #1 on: November 23, 2022, 11:13:38 am »
Turbo Pascal did not support initialization sections. It also did not support for in do and some more places where you mixed up the syntax with modern Pascal. You screwed up, I am afraid. Modes are important for features to be supported.
Also note that to test such code you should use {$mode tp}

btw: I got a completely unrelated error while compiling your code in mode tp -: unexpected end of file.
« Last Edit: November 23, 2022, 11:17:54 am by Thaddy »
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

Bart

  • Hero Member
  • *****
  • Posts: 4831
    • Bart en Mariska's Webstek
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #2 on: November 23, 2022, 12:17:28 pm »
Are you using this unit with TP or with fpc?
I don't get compilation errors with fpc (well it won't link, since I don't have the external libraries it needs).

Bart

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10407
  • FPC developer.
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #3 on: November 23, 2022, 12:28:55 pm »
Maybe he is in an IDE that forces some objfpc/delphi mode on the cmdline, and strings become ansistrings or so ?

coradi

  • Full Member
  • ***
  • Posts: 121
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #4 on: November 23, 2022, 03:46:35 pm »
I use it on Freepascal in DOS Mode, and copied the Units

It's Turbo pascal / from the BOOK Torbo PAscal and Delphi for kids.
Is copy paste from CD
https://www.amazon.de/Turbo-Pascal-Delphi-für-Kids/dp/3826606426/ref=sr_1_1?__mk_de_DE=ÅMÅŽÕÑ&crid=12Z7V8RCP57QE&keywords=turbo+pascal+kids&qid=1669214774&sprefix=turbo+pascal+kids%2Caps%2C215&sr=8-1
« Last Edit: November 23, 2022, 03:48:06 pm by coradi »
Amstrad Schneider CPC 6128
Wind XP / 7 / 10

Thaddy

  • Hero Member
  • *****
  • Posts: 12212
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #5 on: November 23, 2022, 03:54:36 pm »
Code: Pascal  [Select][+][-]
  1. {-----------------------------------------------------------------------
  2. This unit declares a unit containing procedures etc. that are normally
  3. (i.e., in Turbo Pascal) provided by the units 'graph' and 'crt'. The actual
  4. implementation of most of these is not contained in this unit, but in
  5. puff_c.c, which is written in C, and uses the X11 window system (hence
  6. this unit's name).
  7. The implementations here and in puff_c.c are not complete: they are limited
  8. to what is needed for compiling and using the PUFF software. As such, they
  9. may or may not be useful for compiling other graphical Turbo Pascal
  10. applications under Linux, depending on the requirements of such applications.
  11. This unit and puff_c.c also contain a few other routines that were used in
  12. the Linux port of PUFF but do not exist in Turbo Pascal: these were needed
  13. because some things must (for efficiency or other reasons) be implemented
  14. differently on Linux than on MS-DOS.
  15. Parts (support for readln and writeln) are copyright (c) 1999-2000 by Michael
  16. Van Canneyt and Peter Vreman, members of the Free Pascal development team.
  17. Rest is copyright (c) 2000, by Pieter-Tjerk de Boer, pa3fwm@amsat.org.
  18. This software is distributed under the conditions of version 3 of the GNU
  19. General Public License from the Free Software Foundation.
  20. Editted version by Thaddy de Koning 2022. Should be cleaned up further because this is NOT the original version.
  21. Some fool screwed it up and I just did damage control.
  22. -----------------------------------------------------------------------}
  23.  
  24. {.$T-}    {No output sections} //bollocks
  25. {$mode fpc}
  26. Unit xgraph;
  27. {.$mode tp} // this code is a mess and won't compile under its target TP mode. This is FPC mode
  28.  
  29. Interface
  30.  
  31.  
  32. TYPE
  33.   ViewPortType = Record
  34.     X1,Y1,X2,Y2 : Integer;
  35.     Clip : Boolean
  36.   end;
  37.  
  38.  
  39. Procedure InitGraph (var GraphDriver,GraphModus : integer; const PathToDriver : string); cdecl; external;
  40. Procedure CloseGraph ; cdecl; external;
  41.  
  42. Procedure SetColor (Color : Longint); cdecl; external;
  43. Procedure SetFillStyle (Pattern,Color : Longint); cdecl; external;
  44. Procedure SetLineStyle (LineStyle,Pattern,Width : Longint); cdecl; external;
  45.  
  46. Procedure Line (X1,Y1,X2,Y2 : Longint); cdecl; external;
  47. Procedure PutPixel (X,Y : Longint; Color : Longint); cdecl; external;
  48. Procedure Bar (X1,Y1,X2,Y2 : Longint); cdecl; external;
  49. Procedure Rectangle (X1,Y1,X2,Y2 : Longint); cdecl; external;
  50. Procedure Arc (X,Y : Longint; start,stop, radius : Longint); cdecl; external;
  51. Procedure FillEllipse (X,Y : Longint; Xradius,YRadius: Longint); cdecl; external;
  52. Procedure Circle (X,Y : Longint; Radius : Longint); cdecl; external;
  53. Procedure FloodFill (X,Y : Longint; BorderColor : Longint); cdecl; external;
  54.  
  55. Procedure SetTextJustify (Horizontal,Vertical : Longint); cdecl; external;
  56. Procedure OutTextXY (X,Y : Integer; Const TextString : String);
  57.  
  58. Procedure SetViewPort (X1,Y1,X2,Y2 : Longint; Clip : Boolean); cdecl; external;
  59.  
  60. Function GetBkColor : Longint; cdecl; external;
  61. Procedure SetBkColor (Color : Longint); cdecl; external;
  62.  
  63. Function GraphErrorMsg (ErrorCode : Longint) : String; cdecl; external;
  64. Function GraphResult : Longint; cdecl; external;
  65.  
  66.  
  67. Procedure GetBox(bn, x, y, width, height: Longint); cdecl; external;
  68. Procedure PutBox(bn, x, y, width, height: Longint); cdecl; external;
  69.  
  70.  
  71. VAR
  72.   ScreenHeight:integer; external name 'ScreenHeight'; // unsuported by TP
  73.   ScreenWidth:integer; external name 'ScreenWidth';   // unsupported by tp
  74.  
  75.  
  76. CONST
  77.   SOLIDFILL=0;
  78.   lefttext=0;
  79.   centertext=1;
  80.   righttext=2;
  81.   userbitln=4;
  82.   normwidth=1;
  83.   solidln=0;
  84.   VGA=0;
  85.   EGA=1;
  86.   GROK=0;
  87.  
  88.  
  89.  
  90.  
  91.  
  92. CONST
  93.   Black = 0;
  94.   Blue = 1;
  95.   Green = 2;
  96.   Cyan = 3;
  97.   Red = 4;
  98.   Magenta = 5;
  99.   Brown = 6;
  100.   LightGray = 7;
  101.   DarkGray = 8;
  102.   LightBlue = 9;
  103.   LightGreen = 10;
  104.   LightCyan = 11;
  105.   LightRed = 12;
  106.   LightMagenta = 13;
  107.   Yellow = 14;
  108.   White = 15;
  109.   co80 = 3;
  110.   WindMax: Word = $184f;
  111.   LastMode: Word = 3;
  112.   DirectVideo: Boolean = False;
  113.  
  114.  
  115.  
  116.  
  117. Procedure Window (X1, Y1, X2, Y2: Longint); cdecl; external name 'crtWindow';
  118. Procedure GotoXY (X: Longint; Y: Longint); cdecl; external;
  119. Procedure Sound (hz : Longint); cdecl; external;
  120. Procedure Delay (DTime: Longint); cdecl; external;
  121. Procedure NoSound ; cdecl; external;
  122. Function KeyPressed : Boolean; cdecl; external;
  123. Function ReadKey : Char; cdecl; external;
  124. procedure TextMode(Mode: Longint); cdecl; external;
  125. Procedure TextColor (CL: Longint); cdecl; external;
  126. Procedure TextBackground (CL: Longint); cdecl; external;
  127. Procedure ClrScr ; cdecl; external;
  128.  
  129.  
  130. Function GetTimerTicks : Integer; cdecl; external;
  131.  
  132.  
  133.  
  134.  
  135. Implementation
  136.  
  137.  
  138. uses dos;
  139.  
  140.  
  141.  
  142.  
  143. Procedure C_OutTextXY (X,Y : Longint; Var TextString : String); cdecl; external;
  144.  
  145. Procedure OutTextXY (X,Y : Integer; Const TextString : String);
  146. var s: string;
  147. begin
  148.    s:=TextString;
  149.    C_OutTextXY(X,Y,s);
  150. end;
  151.  
  152.  
  153.  
  154.  
  155. { write(ln) and readln support code based on rtl/linux/crt.pp from the fpc source tree }
  156.  
  157. procedure DoWrite(var s: string); cdecl; external;
  158. procedure DoWriteEnd; cdecl; external;
  159.  
  160.  
  161. Function xgraphWrite(Var F: TextRec): Integer;
  162. Var
  163.   Temp : String;
  164.   idx,i : Longint;
  165. Begin
  166.   idx:=0;
  167.   while (F.BufPos>0) do
  168.    begin
  169.      i:=F.BufPos;
  170.      if i>255 then
  171.       i:=255;
  172.      Move(F.BufPTR^[idx],Temp[1],i);
  173.      SetLength(Temp,i);
  174.      DoWrite(Temp);
  175.      dec(F.BufPos,i);
  176.      inc(idx,i);
  177.    end;
  178.  
  179.   DoWriteEnd;
  180.   xgraphWrite:=0;
  181. End;
  182.  
  183.  
  184.  
  185. Function xgraphRead(Var F: TextRec): Integer;
  186. {
  187.   Read from CRT associated file.
  188. }
  189. var
  190.   c : char;
  191.   i : longint;
  192. Begin
  193.       F.BufPos := 0;
  194.       i := 0;
  195.       repeat
  196.         c := readkey;
  197.         case c of
  198.           { ignore special keys }
  199.           #0:
  200.             c:= readkey;
  201.           { Backspace }
  202.           #8:
  203.             if i > 0 then
  204.               begin
  205.                 write(#8#32#8);
  206.                 dec(i);
  207.               end;
  208.           { Unhandled extended key }
  209.           #27:;
  210.           { CR }
  211.           #13:
  212.             begin
  213.               F.BufPtr^[i] := #10;
  214.               write(#10);
  215.               inc(i);
  216.             end;
  217.           else
  218.             begin
  219.               write(c);
  220.               F.BufPtr^[i] := c;
  221.               inc(i);
  222.             end;
  223.         end;
  224.       until (c in [#10,#13]) or (i >= F.BufSize);
  225.       F.BufEnd := i;
  226.       xgraphRead := 0;
  227.       exit;
  228. End;
  229.  
  230.  
  231. Function xgraphReturn(Var F:TextRec):Integer;
  232. Begin
  233.   xgraphReturn:=0;
  234. end;
  235.  
  236.  
  237.  
  238.  
  239. Function xgraphOpen(Var F: TextRec): Integer;
  240. Begin
  241.   If F.Mode=fmOutput Then
  242.    begin
  243.      TextRec(F).InOutFunc:=@xgraphWrite;
  244.      TextRec(F).FlushFunc:=@xgraphWrite;
  245.    end;
  246.   If F.Mode=fmInput Then
  247.    begin
  248.      TextRec(F).InOutFunc:=@xgraphRead;
  249.      TextRec(F).FlushFunc:=@xgraphReturn;
  250.    end;
  251.   xgraphOpen:=0;
  252. End;
  253.  
  254.  
  255.  
  256. procedure init_x; cdecl; external;
  257.  
  258.  
  259. Initialization
  260.  
  261.   Assign(Output,'');
  262.   TextRec(Output).OpenFunc:=@xgraphOpen;
  263.   Rewrite(Output);
  264.   TextRec(Output).Handle:=StdOutputHandle;
  265.   Assign(Input,'');
  266.   TextRec(Input).OpenFunc:=@xgraphOpen;
  267.   Reset(Input);
  268.   TextRec(Input).Handle:=StdInputHandle;
  269.  
  270.   init_x();
  271. {
  272.   ScreenHeight:=500;
  273.   ScreenWidth:=1000;
  274. }
  275.  
  276. end.
Works. But it still is a gigantic mess and bad coding. And the bad coding is NOT!! from that book.....
Well, I  am a pensionado with little else to do, but please be honest if you mess up things yourself. (and help my 14 year old daughter with maths... which is worse than fixing this)

This is for mode fpc. I am not inclined to fix it for mode tp. I could have watched Japan beating Germany in the mean time - forever :P ;D
Why did you not write you have made modifications? That is wrong, very wrong. Especially if these mods are very wrong.
« Last Edit: November 23, 2022, 04:35:44 pm by Thaddy »
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

Bart

  • Hero Member
  • *****
  • Posts: 4831
    • Bart en Mariska's Webstek
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #6 on: November 23, 2022, 05:13:47 pm »
Can't you just use graph or ptgraph unit that come with fpc?

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 12212
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #7 on: November 23, 2022, 05:18:46 pm »
He could have.
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

coradi

  • Full Member
  • ***
  • Posts: 121
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #8 on: November 23, 2022, 05:28:17 pm »
yes, it in on the CD from the book...I mean

That's the complete Program
Amstrad Schneider CPC 6128
Wind XP / 7 / 10

Thaddy

  • Hero Member
  • *****
  • Posts: 12212
Re: xgraph.pas "failure 235/35 can't read Variables of this type"
« Reply #9 on: November 23, 2022, 05:30:34 pm »
Liar.
There is no for in do in TP, nor initialization sections.
I am not prepared to help you any further.
 YOU messed up.
Either it is a wrong book or you are wrong.

(note that I myself have made bold and wrong statements too (dismissed by mainly Sarah) but never lied.)

As I suspect that the author of this "book" is a forum member I would suggest he/she would answer.
But if you changed the code you should apologize. Wasting time only pensionado's can afford...barely!
(My first band was 51 years ago, my best band is 40 years ago: resp. Tombstone and The Duvel. I do not imagine to beat that time span)
« Last Edit: November 23, 2022, 06:03:39 pm by Thaddy »
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

 

TinyPortal © 2005-2018