Recent

Author Topic: [SOLVED] object pascal handbook and generic  (Read 1631 times)

superc

  • Full Member
  • ***
  • Posts: 242
[SOLVED] object pascal handbook and generic
« on: February 18, 2022, 10:58:20 am »
Hello,

I'm downloaded a Marco Cantù book : 'Object Pascal Handbook': I'm trying code like:

Code: Pascal  [Select][+][-]
  1. type
  2. TKeyValue<T> = class
  3.   private
  4.     FKey: string;  
  5.     FValue: T;
  6.     procedure SetKey(const Value: string);
  7.     procedure SetValue(const Value: T);
  8.   public
  9.     property Key: string read FKey write SetKey;
  10.     property Value: T read FValue write SetValue;
  11. end;
  12.  


In lazarus this code doesn't work, ok but.... Why book is named Object Pascal Handbook??

Thanks in advance.


« Last Edit: February 18, 2022, 11:56:03 am by superc »

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: object pascal handbook and generic
« Reply #1 on: February 18, 2022, 11:15:38 am »
If you're in {$mode objfpc} then add generic before TKeyValue<T>, or set {$mode delphi} and it'll work ....
https://wiki.freepascal.org/Generics

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: object pascal handbook and generic
« Reply #2 on: February 18, 2022, 11:35:23 am »
IOW use {$mode delphi}
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: object pascal handbook and generic
« Reply #3 on: February 18, 2022, 11:37:54 am »
This is a bit confusing, but there is no one Object Pascal language. There are different dialects under the broad term Object Pascal.
I don't know the Object Pascal landscape fully, but Turbo Pascal, Delphi and FreePascal are three different dialects of Object Pascal, and do things differently. Generics is just one of the examples. Another one is Management Operators, Operator Overloading, or simply that in FreePascal you take function pointer with @ while in Delphi no Operator is needed.

These are just things one has to learn.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: object pascal handbook and generic
« Reply #4 on: February 18, 2022, 11:43:31 am »
but Turbo Pascal, Delphi and FreePascal are three different dialects of Object Pascal, and do things differently.
Well, at the minimum, FPC tries to achieve all reasonable modes..... FPC has many dialects..
And that code simply compiles in {$mode delphi}
Some code - in fpc -does not compile until anonymous methods do work, but Marco's book is otherwise excellent.
« Last Edit: February 18, 2022, 11:47:18 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

superc

  • Full Member
  • ***
  • Posts: 242
Re: object pascal handbook and generic
« Reply #5 on: February 18, 2022, 11:53:59 am »
I read from from https://wiki.freepascal.org/Generics

Quote
It is possible to use units written in {$mode ObjFPC} syntax in other units that use {$mode Delphi}, and vice versa.

so I deduce that I can use one mode in some units and the other in others, not as bad as i thought.....


Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: [SOLVED] object pascal handbook and generic
« Reply #6 on: February 18, 2022, 05:00:38 pm »
Correct.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018