Recent

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

nugax

  • Full Member
  • ***
  • Posts: 232
Error - type identified not allowed here
« on: January 20, 2018, 06:05:29 pm »
I have a record, in which this below record member is a string type.
 I am trying to jsut display that record (which is held in another unit and referenced in uses.

Why cant I reference the string?

Code: Pascal  [Select][+][-]
  1.  sFirstName := user_handler.userRecord.firstname;  
-Nugax

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #1 on: January 20, 2018, 06:06:04 pm »
userRecord is a global record also.
-Nugax

Thaddy

  • Hero Member
  • *****
  • Posts: 19253
  • Glad to be alive.
Re: Error - type identified not allowed here
« Reply #2 on: January 20, 2018, 06:10:45 pm »
Can you show the record declaration? This information is not enough. If I see the record structure I know the answer probably immediately.
A record on its own can not be a string. A member of a record can be a string.
« Last Edit: January 20, 2018, 06:12:19 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Handoko

  • Hero Member
  • *****
  • Posts: 5544
  • My goal: build my own game engine using Lazarus
Re: Error - type identified not allowed here
« Reply #3 on: January 20, 2018, 06:15:48 pm »
The OP said the error was "type identified not allowed here", then I can write code that show the same error:

Code: Pascal  [Select][+][-]
  1. type
  2.   TTest = record
  3.     Name: string;
  4.     Age: Integer;
  5.   end;
  6.  
  7. var
  8.   AString: string;
  9.  
  10. begin
  11.   AString := TTest.Name;
  12. end.

The code above will generate the same error as OP said. Looking at the code, then we know why. :D :-X
« Last Edit: January 20, 2018, 06:18:57 pm by Handoko »

Thaddy

  • Hero Member
  • *****
  • Posts: 19253
  • Glad to be alive.
Re: Error - type identified not allowed here
« Reply #4 on: January 20, 2018, 06:20:35 pm »
The OP said the error was "type identified not allowed here", then I can write code that show the same error:
The code above will generate the same error as OP said. Looking at the code, then we know why. :D :-X

Yes. But judging from the rest of his questions better to let him give the structure and then explain: this is only part of his problems... 8-)
objects are fine constructs. You can even initialize them with constructors.

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #5 on: January 20, 2018, 06:23:34 pm »
Can you show the record declaration? This information is not enough. If I see the record structure I know the answer probably immediately.
A record on its own can not be a string. A member of a record can be a string.

Here you go -> the user handler unit

Code: Pascal  [Select][+][-]
  1. unit user_handler;
  2.  
  3. {$I direct.inc}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, crt;
  9.  
  10.  
  11. //BBS Wide User Record Info
  12. type
  13.   userRecord = record
  14.     firstname, lastname, handle, password, datejoined, email, affils, fromwhere, status, bbssysop, bbsname, lastcall, notes: string;
  15.     seclevel: integer;
  16.   end;
  17.  
  18. Var
  19.  logged_in_user_record : userRecord;
  20.  
  21.  
  22. procedure load_user_record(var sHandleGiven);
  23.  
  24.  
  25. implementation
  26.  
  27. procedure load_user_record(var sHandleGiven);
  28.  Begin
  29.  
  30.  
  31.  end;
  32.  
  33.  
  34. //Main Program Code
  35. Begin
  36.  
  37.  
  38. end.      

-Nugax

Handoko

  • Hero Member
  • *****
  • Posts: 5544
  • My goal: build my own game engine using Lazarus
Re: Error - type identified not allowed here
« Reply #6 on: January 20, 2018, 06:31:01 pm »
You can't give a type to a variable. You haven't provided enough information, so let's see my example.

Code: Pascal  [Select][+][-]
  1. type
  2.   TTest = record
  3.     Name: string;
  4.     Age: Integer;
  5.   end;
  6.  
  7. var
  8.   UserData: TTest;
  9.   AString: string;
  10.  
  11. begin
  12.   ...
  13.   ...
  14.  
  15.   // This is wrong
  16.   AString := TTest.Name;
  17.  
  18.   // This is correct
  19.   AString := UserData.Name;
  20.  
  21. end.

TTest is a type, UserData is a variable.
« Last Edit: January 20, 2018, 06:36:06 pm by Handoko »

Thaddy

  • Hero Member
  • *****
  • Posts: 19253
  • Glad to be alive.
Re: Error - type identified not allowed here
« Reply #7 on: January 20, 2018, 06:41:42 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.
« Last Edit: January 20, 2018, 06:56:58 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #8 on: January 20, 2018, 07:14:56 pm »
funny you say that, it is saved in sqlite, this is pulling the sqlite data and loading into variables to be used throughout the program.
-Nugax

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #9 on: January 20, 2018, 07:17:02 pm »
You can't give a type to a variable. You haven't provided enough information, so let's see my example.

Code: Pascal  [Select][+][-]
  1. type
  2.   TTest = record
  3.     Name: string;
  4.     Age: Integer;
  5.   end;
  6.  
  7. var
  8.   UserData: TTest;
  9.   AString: string;
  10.  
  11. begin
  12.   ...
  13.   ...
  14.  
  15.   // This is wrong
  16.   AString := TTest.Name;
  17.  
  18.   // This is correct
  19.   AString := UserData.Name;
  20.  
  21. end.

TTest is a type, UserData is a variable.



Isnt this exactly what I did, except i did it from another unit?
I pulled the data from sqlite and tried to place it into the record.
-Nugax

Handoko

  • Hero Member
  • *****
  • Posts: 5544
  • My goal: build my own game engine using Lazarus
Re: Error - type identified not allowed here
« Reply #10 on: January 20, 2018, 07:35:37 pm »
Sorry, I didn't know you're talking about database. Database programming is not my expertise.
« Last Edit: January 20, 2018, 07:53:49 pm by Handoko »

jamie

  • Hero Member
  • *****
  • Posts: 7762
Re: Error - type identified not allowed here
« Reply #11 on: January 20, 2018, 07:39:15 pm »
You can not assign a type to an Instant!

 you need to create a instant of that Record type and then get that from the instant..

Var
 MyInstant:TSomeRecord =........End;

Begin

 MyString := MyInstant.SomeInnerName;
etc

The only true wisdom is knowing you know nothing

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #12 on: January 20, 2018, 09:09:30 pm »
You can not assign a type to an Instant!

 you need to create a instant of that Record type and then get that from the instant..

Var
 MyInstant:TSomeRecord =........End;

Begin

 MyString := MyInstant.SomeInnerName;
etc



Didnt I do that? In this part of the above code?

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

Thaddy

  • Hero Member
  • *****
  • Posts: 19253
  • Glad to be alive.
Re: Error - type identified not allowed here
« Reply #13 on: January 20, 2018, 09:34:15 pm »
No... You are using the wrong kind of string.... A LONG string instead of a fixed length string.... I wrote string[255], which makes it work in a crude way... And gave you a pointer for some lessons...
objects are fine constructs. You can even initialize them with constructors.

nugax

  • Full Member
  • ***
  • Posts: 232
Re: Error - type identified not allowed here
« Reply #14 on: January 20, 2018, 09:49:27 pm »
No... You are using the wrong kind of string.... A LONG string instead of a fixed length string.... I wrote string[255], which makes it work in a crude way... And gave you a pointer for some lessons...

Whats the difference in a record and a packed record?
-Nugax

 

TinyPortal © 2005-2018