Recent

Author Topic: Problem statement structures  (Read 8178 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Problem statement structures
« on: June 06, 2011, 02:26:17 pm »
Hello I have created two structures contained in the other. Can anyone tell me how to not have error at compile time? Thank you very much. The bold line is the offending

{ci salvo i collegamenti neurali - singolo neurone}
Type ListaCollegamentiNeurali=^Rete;
     Rete = Record
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;

{ci salvo la rete neurale - singolo neurone}
Type ListaAtleti=^Atleta;
     Atleta = Record
        Cognome: string;
        Nome: string;
        Provenienza: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;

Error:

reteneurale.pas(13,34) Error: Identifier not found "ListaAtleti"
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Problem statement structures
« Reply #1 on: June 06, 2011, 02:44:05 pm »
Code: [Select]
   ListaCollegamentiNeurali=^Rete;
   ListaAtleti=^Atleta;

   Atleta = Record
        Cognome: string;
        Nome: string;
        Provenienza: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;

   Rete = Record
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;     
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/

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Problem statement structures
« Reply #2 on: June 06, 2011, 02:48:48 pm »
Modified code, but not correct. Why


unit reteneurale;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

{ci salvo i collegamenti neurali - singolo neurone}
{Type ListaCollegamentiNeurali=^Rete;
     Rete = Record
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;}



{ci salvo la rete neurale - singolo neurone}
{type ListaAtleti=^Atleta;
     Atleta = Record
        Cognome: string;
        Nome: string;
        Provenienza: string;
        Grado: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;}

   ListaCollegamentiNeurali=^Rete;
   ListaAtleti=^Atleta;

   Atleta = Record
        Cognome: string;
        Nome: string;
        Provenienza: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;

   Rete = Record
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;
type
        ReteNeuraleAtleti = Object
        private
            MiaReteNeurale: ListaAtleti; {variabile che mi contiene il puntatore a tutti i neuroni}
            function InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaAtleti;
            procedure CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
        public
            constructor Create;
            destructor Destroy;
            procedure InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
    end;


implementation

constructor ReteNeuraleAtleti.Create();
begin
     MiaReteNeurale:=nil; { Inizializzo a null la variabile }
end;

destructor ReteNeuraleAtleti.Destroy();
var
   app, prossimo: ListaAtleti;
begin
     { cancello tutti i dati possibili }
     //dispose(qualcosa);
     app:=MiaReteNeurale;
     while (app<>nil) do
     begin         
          prossimo:=app^.Next;
          CancellaCollegamentiNeurali(app^.Lista);
          dispose(app);         
          app:=prossimo;
     end;
     { Rivalorizzo a null la variabile }
     MiaReteNeurale:=nil;
end;

procedure ReteNeuraleAtleti.CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
var
   app:ListaCollegamentiNeurali;
begin
     while (Nodo<>nil) do
     begin         
          app:=Nodo^.Next;         
          dispose(Nodo);         
          Nodo:=app;
     end;   
end;

procedure ReteNeuraleAtleti.InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
var
   app, nuovo: ListaAtleti;
begin
     app:=MiaReteNeurale;
     New(nuovo);
     nuovo^.Cognome:=Cognome;
     nuovo^.Nome:=Nome;
     nuovo^.Provenienza:=Provenienza;
     nuovo^.Grado:=Grado;
     nuovo^.Disciplina:=Disciplina;
     nuovo^.Lista:=nil;
     if (app=nil) then {nel caso stia inserendo il primo neurone della rete}
     begin         
          nuovo^.Next:=nil;
     end
     else
     begin
          {vuol dire che ho già inserito qualcosa}
          {per funzionare correttamente nuovo^.Lista:=nil; deve essere valorizzato fuori dall'if altrimenti non funziona InserisciAltriNeuroniDiversiDa}
          nuovo^.Lista:=InserisciAltriNeuroniDiversiDa(nuovo);
          nuovo^.Next:=MiaReteNeurale;
     end;
     MiaReteNeurale:=nuovo;
end;

function ReteNeuraleAtleti.InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaAtleti;
var
   app: ListaAtleti;
   nuovo, ret: ListaCollegamentiNeurali;
begin
     app:=MiaReteNeurale;
     ret:=nil;
     while (app<>nil) do
     begin
          if (app<>Nodo) then
          begin
               { creo la lista del nuovo neurone per avere i collegamenti neuronali }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=app;
               nuovo^.Next:=ret;
               ret:=nuovo;
               { aggiorno i collegamenti neuronali di tutti i vecchi neuroni inseriti }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=Nodo;
               nuovo^.Next:=app^.Lista;
               app^.Lista:=nuovo;
          end;
          app:=app^.next;
     end;
     InserisciAltriNeuroniDiversiDa:=ret;
end;

end.


Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Problem statement structures
« Reply #3 on: June 06, 2011, 02:53:56 pm »
Use class in stead of record and do a foreward declaration:

Code: [Select]
Type Atleta = class;
Type ListaAtleti=^Atleta;
Type ListaCollegamentiNeurali=^Rete;

Type  Rete = class
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;

{ci salvo la rete neurale - singolo neurone}

     Atleta = class
        Cognome: string;
        Nome: string;
        Provenienza: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;
1.0/2.6.0  XP SP3 & OS X 10.6.8

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Problem statement structures
« Reply #4 on: June 06, 2011, 03:02:24 pm »
reteneurale.pas(35,6) Error: Forward type not resolved "Rete"
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Problem statement structures
« Reply #5 on: June 06, 2011, 03:09:28 pm »
Then it is in compiler version. I use fpc 2.5.1 (SVN).
Your second code (Modified code, but not correct. Why ....) has type declaration good.
I cannot compile it due other error:
Code: [Select]
unit2.pas(150,38) Error: Incompatible types: got "ListaCollegamentiNeurali" expected "ListaAtleti"
it is line:
Code: [Select]
InserisciAltriNeuroniDiversiDa:=ret;
But again, type declaration is correct.
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/

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Problem statement structures
« Reply #6 on: June 06, 2011, 03:11:56 pm »
I dumped your code in a small stand alone program and fixed some inconsistencies, among which the one Blaazen referred to.

This compiles for me (fpc 2.4.2)

Code: [Select]
program Project1;

{$mode objfpc}{$H+}



uses
  Classes, SysUtils;

{ci salvo i collegamenti neurali - singolo neurone}
{Type ListaCollegamentiNeurali=^Rete;
     Rete = Record
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;}



{ci salvo la rete neurale - singolo neurone}
{type ListaAtleti=^Atleta;
     Atleta = Record
        Cognome: string;
        Nome: string;
        Provenienza: string;
        Grado: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;}
Type

   ListaCollegamentiNeurali=^Rete;
   ListaAtleti=^Atleta;

   Atleta = class
        Cognome: string;
        Nome: string;
        Grado: string;
        Provenienza: string;
        Disciplina: string;
        TestaDiSerie: boolean;
        Lista:ListaCollegamentiNeurali;
        next: ListaAtleti;
   End;

   Rete = class
        CollegamNeur: ListaAtleti;
        Next:ListaCollegamentiNeurali;
   End;
type
        ReteNeuraleAtleti = class
        private
            MiaReteNeurale: ListaAtleti; {variabile che mi contiene il puntatore a tutti i neuroni}
            function InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaCollegamentiNeurali;
            procedure CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
        public
            constructor Create;
            destructor Destroy;
            procedure InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
    end;




constructor ReteNeuraleAtleti.Create();
begin
     MiaReteNeurale:=nil; { Inizializzo a null la variabile }
end;

destructor ReteNeuraleAtleti.Destroy();
var
   app, prossimo: ListaAtleti;
begin
     { cancello tutti i dati possibili }
     //dispose(qualcosa);
     app:=MiaReteNeurale;
     while (app<>nil) do
     begin
          prossimo:=app^.Next;
          CancellaCollegamentiNeurali(app^.Lista);
          dispose(app);
          app:=prossimo;
     end;
     { Rivalorizzo a null la variabile }
     MiaReteNeurale:=nil;
end;

procedure ReteNeuraleAtleti.CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
var
   app:ListaCollegamentiNeurali;
begin
     while (Nodo<>nil) do
     begin
          app:=Nodo^.Next;
          dispose(Nodo);
          Nodo:=app;
     end;
end;

procedure ReteNeuraleAtleti.InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
var
   app, nuovo: ListaAtleti;
begin
     app:=MiaReteNeurale;
     New(nuovo);
     nuovo^.Cognome:=Cognome;
     nuovo^.Nome:=Nome;
     nuovo^.Provenienza:=Provenienza;
     nuovo^.Grado:=Grado;
     nuovo^.Disciplina:=Disciplina;
     nuovo^.Lista:=nil;
     if (app=nil) then {nel caso stia inserendo il primo neurone della rete}
     begin
          nuovo^.Next:=nil;
     end
     else
     begin
          {vuol dire che ho già inserito qualcosa}
          {per funzionare correttamente nuovo^.Lista:=nil; deve essere valorizzato fuori dall'if altrimenti non funziona InserisciAltriNeuroniDiversiDa}
          nuovo^.Lista:=InserisciAltriNeuroniDiversiDa(nuovo);
          nuovo^.Next:=MiaReteNeurale;
     end;
     MiaReteNeurale:=nuovo;
end;

function ReteNeuraleAtleti.InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaCollegamentiNeurali;
var
   app: ListaAtleti;
   nuovo, ret: ListaCollegamentiNeurali;
begin
     app:=MiaReteNeurale;
     ret:=nil;
     while (app<>nil) do
     begin
          if (app<>Nodo) then
          begin
               { creo la lista del nuovo neurone per avere i collegamenti neuronali }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=app;
               nuovo^.Next:=ret;
               ret:=nuovo;
               { aggiorno i collegamenti neuronali di tutti i vecchi neuroni inseriti }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=Nodo;
               nuovo^.Next:=app^.Lista;
               app^.Lista:=nuovo;
          end;
          app:=app^.next;
     end;
     InserisciAltriNeuroniDiversiDa:=ret;
end;

begin
end.
1.0/2.6.0  XP SP3 & OS X 10.6.8

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Problem statement structures
« Reply #7 on: June 06, 2011, 03:12:52 pm »
Forward declaration must be done in the same type block. e.g.:
Code: Pascal  [Select][+][-]
  1. type
  2.   PForwardedType = ^TForwardedType;
  3.   TForwardedType = record
  4.     Something: PForwardedType;
  5.   end;
  6.  
but not:
Code: Pascal  [Select][+][-]
  1. type
  2.   PForwardedType = ^TForwardedType;
  3. type
  4.   TForwardedType = record
  5.     Something: PForwardedType;
  6.   end;
  7.  

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Problem statement structures
« Reply #8 on: June 06, 2011, 03:22:50 pm »
Ok, now this code in the declaration of the data is correct but it returns the following error.

reteneurale.pas(103,25) Error: Incompatible types: got "ListaAtleti" expected "ListaCollegamentiNeurali"

Code: [Select]

unit reteneurale;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

   Type

      ListaCollegamentiNeurali=^Rete;
      ListaAtleti=^Atleta;

      Atleta = class
           Cognome: string;
           Nome: string;
           Grado: string;
           Provenienza: string;
           Disciplina: string;
           TestaDiSerie: boolean;
           Lista:ListaCollegamentiNeurali;
           next: ListaAtleti;
      End;

      Rete = class
           CollegamNeur: ListaAtleti;
           Next:ListaCollegamentiNeurali;
      End;

type
        ReteNeuraleAtleti = Object
        private
            MiaReteNeurale: ListaAtleti; {variabile che mi contiene il puntatore a tutti i neuroni}
            function InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaAtleti;
            procedure CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
        public
            constructor Create;
            destructor Destroy;
            procedure InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
    end;

implementation

{costruttore: inizializza a null l'oggetto che conterrà tutto}
constructor ReteNeuraleAtleti.Create();
begin
     MiaReteNeurale:=nil; { Inizializzo a null la variabile }
end;

{distruttore: libererà lo spazio in memoria}
destructor ReteNeuraleAtleti.Destroy();
var
   app, prossimo: ListaAtleti;
begin
     { cancello tutti i dati possibili }
     //dispose(qualcosa);
     app:=MiaReteNeurale;
     while (app<>nil) do
     begin      
      prossimo:=app^.Next;
      CancellaCollegamentiNeurali(app^.Lista);
      dispose(app);      
      app:=prossimo;
     end;
     { Rivalorizzo a null la variabile }
     MiaReteNeurale:=nil;
end;

{ cancello tutti i collegamenti neurali di un neurone }
procedure ReteNeuraleAtleti.CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
var
   app:ListaCollegamentiNeurali;
begin
     while (Nodo<>nil) do
     begin      
      app:=Nodo^.Next;      
      dispose(Nodo);      
      Nodo:=app;
     end;
end;

{ inserisco un atleta nel sistema neurale }
procedure ReteNeuraleAtleti.InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
var
   app, nuovo: ListaAtleti;
begin
     app:=MiaReteNeurale;
     New(nuovo);
     nuovo^.Cognome:=Cognome;
     nuovo^.Nome:=Nome;
     nuovo^.Provenienza:=Provenienza;
     nuovo^.Grado:=Grado;
     nuovo^.Disciplina:=Disciplina;
     nuovo^.Lista:=nil;
     if (app=nil) then {nel caso stia inserendo il primo neurone della rete}
     begin          
          nuovo^.Next:=nil;
     end
     else
     begin
          {vuol dire che ho già inserito qualcosa}
          nuovo^.Lista:=InserisciAltriNeuroniDiversiDa(nuovo);
          nuovo^.Next:=MiaReteNeurale;
     end;
     MiaReteNeurale:=nuovo;
end;

{ inserisco i collegamenti neurali necessari nella creazione di un nuovo neurone }
function ReteNeuraleAtleti.InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaAtleti;
var
   app: ListaAtleti;
   nuovo, ret: ListaCollegamentiNeurali;
begin
     app:=MiaReteNeurale;
     ret:=nil;
     while (app<>nil) do
     begin
          if (app<>Nodo) then
          begin
               { creo la lista del nuovo neurone per avere i collegamenti neuronali }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=app;
               nuovo^.Next:=ret;
               ret:=nuovo;
               { aggiorno i collegamenti neuronali di tutti i vecchi neuroni inseriti }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=Nodo;
               nuovo^.Next:=app^.Lista;
               app^.Lista:=nuovo;
          end;
          app:=app^.next;
     end;
     InserisciAltriNeuroniDiversiDa:=ret;
end;

end.
« Last Edit: June 06, 2011, 03:24:57 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Problem statement structures
« Reply #9 on: June 06, 2011, 03:27:40 pm »
ok this is correct

Code: [Select]
unit reteneurale;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

   Type

      ListaCollegamentiNeurali=^Rete;
      ListaAtleti=^Atleta;

      Atleta = class
           Cognome: string;
           Nome: string;
           Grado: string;
           Provenienza: string;
           Disciplina: string;
           TestaDiSerie: boolean;
           Lista:ListaCollegamentiNeurali;
           next: ListaAtleti;
      End;

      Rete = class
           CollegamNeur: ListaAtleti;
           Next:ListaCollegamentiNeurali;
      End;

type
        ReteNeuraleAtleti = Object
        private
            MiaReteNeurale: ListaAtleti; {variabile che mi contiene il puntatore a tutti i neuroni}
            function InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaCollegamentiNeurali;
            procedure CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
        public
            constructor Create;
            destructor Destroy;
            procedure InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
    end;

implementation

{costruttore: inizializza a null l'oggetto che conterrà tutto}
constructor ReteNeuraleAtleti.Create();
begin
     MiaReteNeurale:=nil; { Inizializzo a null la variabile }
end;

{distruttore: libererà lo spazio in memoria}
destructor ReteNeuraleAtleti.Destroy();
var
   app, prossimo: ListaAtleti;
begin
     { cancello tutti i dati possibili }
     //dispose(qualcosa);
     app:=MiaReteNeurale;
     while (app<>nil) do
     begin       
        prossimo:=app^.Next;
        CancellaCollegamentiNeurali(app^.Lista);
        dispose(app);       
        app:=prossimo;
     end;
     { Rivalorizzo a null la variabile }
     MiaReteNeurale:=nil;
end;

{ cancello tutti i collegamenti neurali di un neurone }
procedure ReteNeuraleAtleti.CancellaCollegamentiNeurali(Nodo: ListaCollegamentiNeurali);
var
   app:ListaCollegamentiNeurali;
begin
     while (Nodo<>nil) do
     begin       
        app:=Nodo^.Next;       
        dispose(Nodo);       
        Nodo:=app;
     end;
end;

{ inserisco un atleta nel sistema neurale }
procedure ReteNeuraleAtleti.InserisciAtleta(Cognome: string; Nome: string; Provenienza: string; Disciplina: string; Grado: string; TestaDiSerie: boolean);
var
   app, nuovo: ListaAtleti;
begin
     app:=MiaReteNeurale;
     New(nuovo);
     nuovo^.Cognome:=Cognome;
     nuovo^.Nome:=Nome;
     nuovo^.Provenienza:=Provenienza;
     nuovo^.Grado:=Grado;
     nuovo^.Disciplina:=Disciplina;
     nuovo^.Lista:=nil;
     if (app=nil) then {nel caso stia inserendo il primo neurone della rete}
     begin         
          nuovo^.Next:=nil;
     end
     else
     begin
          {vuol dire che ho già inserito qualcosa}
          nuovo^.Lista:=InserisciAltriNeuroniDiversiDa(nuovo);
          nuovo^.Next:=MiaReteNeurale;
     end;
     MiaReteNeurale:=nuovo;
end;

{ inserisco i collegamenti neurali necessari nella creazione di un nuovo neurone }
function ReteNeuraleAtleti.InserisciAltriNeuroniDiversiDa(Nodo: ListaAtleti): ListaCollegamentiNeurali;
var
   app: ListaAtleti;
   nuovo, ret: ListaCollegamentiNeurali;
begin
     app:=MiaReteNeurale;
     ret:=nil;
     while (app<>nil) do
     begin
          if (app<>Nodo) then
          begin
               { creo la lista del nuovo neurone per avere i collegamenti neuronali }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=app;
               nuovo^.Next:=ret;
               ret:=nuovo;
               { aggiorno i collegamenti neuronali di tutti i vecchi neuroni inseriti }
               nuovo:=New(ListaCollegamentiNeurali);
               nuovo^.CollegamNeur:=Nodo;
               nuovo^.Next:=app^.Lista;
               app^.Lista:=nuovo;
          end;
          app:=app^.next;
     end;
     InserisciAltriNeuroniDiversiDa:=ret;
end;

end.

Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Problem statement structures
« Reply #10 on: June 06, 2011, 03:34:03 pm »
Essence of not much practical class (I always use object) with the following code which use the library before I returned error

unit1.pas(37,29) Error: Class isn't a parent class of the current class


procedure TForm1.FormCreate(Sender: TObject);
var
   app:ReteNeuraleAtleti;
begin
     app:=ReteNeuraleAtleti.Create;
     app.InserisciAtleta('S','Fr','V','1','Karate',true);
     app.InserisciAtleta('S','An','V','1','Karate',true);
     app.InserisciAtleta('S','Lu','V','1','Karate',true);
     app.InserisciAtleta('S','Sa','V','1','Karate',true);
     app.Destroy;
end;       
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Problem statement structures
« Reply #11 on: June 06, 2011, 03:44:00 pm »
ReteNeuraleAtleti is object type, right (as opposed to class type? Therefore, you can't use ReteNeuraleAtleti.Create since app is already an object. In old Turbo Pascal, one usually declares pointer to the object type then use the extended New() syntax (e.g. New(<var of type pointer to object>,@<object constructor>) to create the instance. This is similar to class' constructor in modern Pascal (using class type instead of object).

Example for object: http://www.freepascal.org/docs-html/ref/refse28.html
Example for class: http://www.freepascal.org/docs-html/ref/refse31.html#x67-770006.1

 

TinyPortal © 2005-2018