Recent

Author Topic: How to make a String Type with 8 characters ?[SOLVED]  (Read 683 times)

DaveP

  • New Member
  • *
  • Posts: 13
How to make a String Type with 8 characters ?[SOLVED]
« on: November 26, 2022, 10:28:31 pm »
Hi,
  I am converting some DOS Modula-2 programmes and libraries to FPC Paccal,  I have only just started this and have run in a problem with a Library procedure that makes a Frame on the screen. It uses pre-defined strings of characters for the Frame, of a Type "FrameType".
So firstly a FrameType is declared,
Then the variables of FrameType are declared,
Then the variables are allocated the characters.

A programme Imports ( uses ) the FrameType  and a suitable FrameType variable.
which are then used by any procedures that write the Frame to the screen.

[ NOT TRUE CODE ]
TYPE
  FrameType = ARRAY [ 0..8 ] OF CHAR;    (* originally defined in the Def Module *)

Then the various Frames are declared as a FrameType       (* Also defined in the Def Module *)
VAR  DoubleFrame, SingleFrame : FrameType;

(* This was in the Implementation Module Main Code.  *)
Then the variables are allocated the characters.    (* Originally as CHR(201) + CHR(205)  etc etc *)
  DoubleFrm :  #201 + #205 + #187 + #200 + #205 + #188 + #186 + #186 ;
  SingleFrm :  #218 + #196 + #191 + #192 + #196 + #217 + #179 + #179 ;   
[ / NOT TRUE CODE ]   

However I have failed to find Information as to how I can implement this in FPC  and the Save/Compile sequence  is hammering my ssd. Any help as best practice to achieve this in Pascal will be most welcome.
Dave P..
« Last Edit: November 27, 2022, 03:16:32 pm by DaveP »

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: How to make a String Type with 8 characters ?
« Reply #1 on: November 26, 2022, 11:00:14 pm »
before you go too far with that you should know that you will be dealing with UTF8 encoding
 issues.
 Any character value above #128 is going to hit a wall.

 But in any case, you can use a RawByteString to help reduce the chance of that happening at least in that case.
 
 But if you want to continue then the single and double characters need to be different types.

 So instead of FrameType, you need to use for example TDFrameType and TSFrameType and each define can be statically defined.

Type
  TDFrameType = TFrameType =(#20,204,....);

 S0o y0ou can still use the original FrameType as a type for the next frame types.

I think you get it.

If you still have a problem understanding this, I can create the actual type for you.



The only true wisdom is knowing you know nothing

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: How to make a String Type with 8 characters ?
« Reply #2 on: November 26, 2022, 11:08:17 pm »
Everything you posted is valid FPC/Pascal code. It is just not very handy, and you might get into problems defining literals.

I was a Topspeed Modula-2er before I migrated to Free Pascal in about 1998.. I'd advise you to not try to retain the old M2 types, but to fully rewrite using ansistrings.

Encoding issues might ensue, but in my case that was hopeless anyway (it only supported default locale, whatever it was)

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: How to make a String Type with 8 characters ?
« Reply #3 on: November 26, 2022, 11:08:28 pm »
I made the types and constants you can look at,...
Code: Pascal  [Select][+][-]
  1. type
  2.   TFrameType = String[8];
  3.   TDFrameType = TFrameType;
  4.   TSFrameType = TFrameType;  
  5. ...
  6. Const
  7.  DFrameString:TDFrameType= #201 + #205 + #187 + #200 + #205 + #188 + #186 + #186;
  8.  SFrameString:TDFrameType= #218 + #196 + #191 + #192 + #196 + #217 + #179 + #179 ;
  9.  
  10.  

Those are now fixed length strings which you can index if the code is that way.
The only true wisdom is knowing you know nothing

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: How to make a String Type with 8 characters ?
« Reply #4 on: November 26, 2022, 11:10:38 pm »
Jamie that is wrong. The M2 type can harbor 9 characters (0..8), not 8.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: How to make a String Type with 8 characters ?
« Reply #5 on: November 27, 2022, 12:09:36 am »
Ok, I was trying to push him towards using strings since there needs to be a conversion in any case.
Code: Pascal  [Select][+][-]
  1. type
  2.   TFrameType = array[0..8] of char;    
  3. .....
  4. Const
  5.  DFrameString:TFrameType= #201 + #205 + #187 + #200 + #205 + #188 + #186 + #186;
  6.  SFrameString:TFrameType= #218 + #196 + #191 + #192 + #196 + #217 + #179 + #179 ;    
  7.  

I find it strange that the compiler accepts this since I didn't define the last character in the string. So, I assume the compiler may have left that undefined?
The only true wisdom is knowing you know nothing

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: How to make a String Type with 8 characters ?
« Reply #6 on: November 27, 2022, 12:34:37 am »
I find it strange that the compiler accepts this since I didn't define the last character in the string. So, I assume the compiler may have left that undefined?
since it's a typed constant, the "undefined" character will be a #0
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

DaveP

  • New Member
  • *
  • Posts: 13
Re: How to make a String Type with 8 characters ?[SOLVED]
« Reply #7 on: November 27, 2022, 03:17:48 pm »
Many thanks for the replies, One problem put to bed, 2 foreseeable problems to go. ( will post )

MarkMLl

  • Hero Member
  • *****
  • Posts: 6647
Re: How to make a String Type with 8 characters ?
« Reply #8 on: November 27, 2022, 03:30:46 pm »
Everything you posted is valid FPC/Pascal code. It is just not very handy, and you might get into problems defining literals.

I was a Topspeed Modula-2er before I migrated to Free Pascal in about 1998.. I'd advise you to not try to retain the old M2 types, but to fully rewrite using ansistrings.

Encoding issues might ensue, but in my case that was hopeless anyway (it only supported default locale, whatever it was)

I used (and sold/supported) multiple M2 implementations on multiple platforms. I agree: move to AnsiString wherver possible, or the old-fashioned String[xxx] if it's necessary to define a field in a record.

I can't remember whether the language According to Wirth had a mandatory CHAR(0) string terminator, or the extent to which early implementations stuck rigidly to that. TopSpeed was, of course, an offshoot of Borland, and like all Borland products was notorious for doing its own thing (even though it might appear like a good idea at the time... I'm not necessarily criticising them).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018