Recent

Author Topic: Error - type identified not allowed here  (Read 8794 times)

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #15 on: January 20, 2018, 09:52:00 pm »
Nope. That's the part of part of his problems... He is using the wrong string type in a record and then tries to load/save: then you get pointers, not strings.

First look here: https://www.tutorialspoint.com/pascal/pascal_files_handling.htm

Then try this and complete it:
This should help him a  little, because this record can be load/saved from disk....(w/o jumping through hoops, of course it is possible):
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode delphi}{$H+}{$I-}{$endif}
  2.  
  3. //BBS Wide User Record Info
  4. type
  5.   TuserRecord = packed record
  6.     firstname, lastname, handle, password, datejoined, email, affils, fromwhere, status, bbssysop, bbsname, lastcall, notes: string[255];// fixed length string...Now find out how much you actually use per individual string
  7.     seclevel: integer;
  8.   end;
  9.  
  10. Var
  11.  logged_in_user_record : TuserRecord;
  12.  
  13. procedure load_user_record(var sHandleGiven);
  14. Begin
  15.  //
  16. end;
  17.  
  18.  
  19. //Main Program Code
  20. Begin
  21. end.  
   

That's lesson 1: don't store things in strings, store in native types. Or in a real database. Strings are for representation, not always for storage... Fixed length strings are OK, but take up more space and are limited to 255 chars.

Code: Pascal  [Select][+][-]
  1.   TuserRecord = packed record
  2.     firstname:string[20];
  3.      lastname:string[50]
  4.      handle:dword;
  5.      password:array[0..39] of byte;
  6.      datejoined:TDateTime;
  7.     .....
  8.   end;

Actually he should use something like SQlite for this task..... But that is far fetched at the moment.
Note the wiki is really, is really bad on file of record. I almost deleted everything, but instead I will bring more sense to it.


changed to your code and it gave same error:

Code: Pascal  [Select][+][-]
  1. /BBS Wide User Record Info
  2. type
  3.   userRecord = packed record
  4.     firstname, lastname, handle, password, datejoined, email, affils, fromwhere, status, bbssysop, bbsname, lastcall, notes: string[255];
  5.     seclevel: integer;
  6.   end;
  7.  
  8. Var
  9.  logged_in_user_record : userRecord;          
-Nugax

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: Error - type identified not allowed here
« Reply #16 on: January 20, 2018, 09:55:27 pm »
You should first focus on the difference between a string and a fixed length string,  After that we will move to records.
Specialize a type, not a var.

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #17 on: January 20, 2018, 10:30:17 pm »
You should first focus on the difference between a string and a fixed length string,  After that we will move to records.

I understand the difference in strings.

-Nugax

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: Error - type identified not allowed here
« Reply #18 on: January 20, 2018, 11:07:30 pm »
You should first focus on the difference between a string and a fixed length string,  After that we will move to records.

I understand the difference in strings.
Do you understand why you have to use fixed length strings in records that you want to store and read from disk?
Specialize a type, not a var.

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #19 on: January 21, 2018, 03:03:25 am »
Yes, so you can control the variable and size of the variable.
-Nugax

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Error - type identified not allowed here
« Reply #20 on: January 21, 2018, 04:42:14 am »
Non fixed strings are those you can control the size of  and its done for you in the background, those are called
managed strings and they are pointers to a chuck of memory which you don't need to deal with directly..

 However there is an issue of using those inside a record. when you move a record to another location like disk
for example, all you have done is moved the pointer to the string, not the actual contents and the next time
you load it it'll be pointing to garbage. Those strings are huge strings {$H+} etc.
 
 Short strings or Array of char's are directly bound to the record, there are no memory pointers in the record
pointing to background managed strings.

  You can use dynamic strings in a record but care must be taken to make sure they get released and you
can't directly transpose them to file and such.

 So using a string with  Name:String[?] to indicate the number of characters you want it hold will create a
fixed chunk of space within that Record that will live and stay there, not be somewhere in memory management
heap elsewhere.
 
  STrings with Size indicators are called short strings and are limited to their range. 255..
 
 if you need more than that, you can use an Array[0....500] of char for example..
it'll just make the record larger, even if you don't use all of the array,.

hope that helped some..
The only true wisdom is knowing you know nothing

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #21 on: January 22, 2018, 02:49:54 am »
That makes sense. I didn't know that pascal auto sized the strings or ansi strings. I believe you can use length to set the size as well.

But a fixed string size of 255 is fine for this. I just know have to figure out how to reference that record from the other unit.
-Nugax

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #22 on: January 22, 2018, 04:59:15 pm »
You should first focus on the difference between a string and a fixed length string,  After that we will move to records.

I understand the difference in strings.
Do you understand why you have to use fixed length strings in records that you want to store and read from disk?


I figured out what the issue was. I was creating a pointer to a record type i created. It wasnt actually creating memory for the object.

I altered the function to pass the record as a result (return) value and then load it from the function. It now works properly.

Thank you
-Nugax

 

TinyPortal © 2005-2018