Recent

Author Topic: Error: Pointer to object expected  (Read 2842 times)

creaothceann

  • Full Member
  • ***
  • Posts: 117
Error: Pointer to object expected
« on: February 07, 2016, 02:29:31 am »
Compiling the following code (reduced from a much larger project) results in the error indicated in the comment below:

Code: Pascal  [Select][+][-]
  1. {$MODESWITCH AdvancedRecords}
  2. program Prg;
  3.  
  4.  
  5. type t = record
  6.         class var      v : Boolean;
  7.         class function f : Boolean;  static;
  8.         class property p : Boolean  read v;
  9.         end;
  10.  
  11.  
  12. class function t.f : Boolean;
  13. begin
  14. Result := p;    // "Error: Pointer to object expected"
  15. end;
  16.  
  17.  
  18. begin
  19. end.

Searching for that error message brings up "You specified an illegal type in a new statement. The extended syntax of new needs an object as a parameter". I'm not using new though...

Btw. the error disappears when I replace "record" with "class". I might have/want to stream the (bitpacked) record data to/from a memory stream later, and a class might not be useful for that (using the address of the class and SizeOf)?
« Last Edit: February 07, 2016, 02:31:40 am by creaothceann »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Error: Pointer to object expected
« Reply #1 on: February 07, 2016, 03:32:32 am »
I tried with FPC 3.0.0 and I can only say that if you replace the code with:
Code: Pascal  [Select][+][-]
  1. Result := v;
it compiles well.
You can try to ask on FPC mailing list.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: Error: Pointer to object expected
« Reply #2 on: February 07, 2016, 04:10:59 am »
Quote
class function f : Boolean;  static;

Static methods have not Self inside.
So, t.f should not have access to v and p.

I tried with FPC 3.0.0 and I can only say that if you replace the code with:
Code: Pascal  [Select][+][-]
  1. Result := v;
it compiles well.

This is a good reason for writing bugreport.

Right way:

Code: Pascal  [Select][+][-]
  1. class function t.f : Boolean;
  2. begin
  3.   Result := t.v;
  4.   // or
  5.   Result := t.p;
  6. end;
  7.  

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: Error: Pointer to object expected
« Reply #3 on: February 07, 2016, 04:18:27 am »
Btw. the error disappears when I replace "record" with "class".

This is a good reason for writing bugreport too.

creaothceann

  • Full Member
  • ***
  • Posts: 117
Re: Error: Pointer to object expected
« Reply #4 on: February 07, 2016, 04:42:22 am »
Quote
class function f : Boolean;  static;

Static methods have not Self inside.
So, t.f should not have access to v and p.

v and p are class variables/properties, so they're essentially global variables/properties except that they're in the record's namespace (which is exactly what I want).


Right way:

Code: Pascal  [Select][+][-]
  1. class function t.f : Boolean;
  2. begin
  3.   Result := t.v;
  4.   // or
  5.   Result := t.p;
  6. end;
  7.  
I'll probably use that, thanks. (It's just a bit silly having to write the record's name in its own method.)
« Last Edit: February 07, 2016, 04:46:11 am by creaothceann »

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: Error: Pointer to object expected
« Reply #5 on: February 07, 2016, 04:49:35 am »
I think, I was a little rushed.
From here:
http://www.freepascal.org/docs-html/ref/refsu31.html

Quote
Note that they do have access to all class variables, types etc

 

TinyPortal © 2005-2018