[solve] Object inside a class lazarus / 62-General ---------------------------------------------------------------------- cappe · 2020-04-28 09:06 With this example   ca = class   public     type     { r }     r = object       procedure Esegui;     end;   public     c : String;     rec :r;   end; procedure ca.r.Esegui; begin     How can I access here the variable c of the class ca end;    What I would like to know is how can I access the procedure  ca.r.Esegui to the variable c of the class ca? Thanks ---------------------------------------------------------------------- Otto · 2020-04-28 09:52 Ciao It depends on what you want to achieve. Dipende da ciò che vuoi ottenere. (Ho dedotto che tu conosca l'italiano ma potrei sbagliarmi). ---------------------------------------------------------------------- cappe · 2020-04-28 09:56 Scrivo in inglese procedure ca.r.Esegui; begin   How can I access here the variable c of the class ca?     I want to access the variable "c" (string) of the "ca" class which contains "r" end; ---------------------------------------------------------------------- marcov · 2020-04-28 10:00 Pass a reference to the class to the objects. Nested symbols (classes,objects,records) don't automatically have access to their parent reference. ---------------------------------------------------------------------- Thaddy · 2020-04-28 10:43 Example program: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}type  TMyClass = class  private    Type       TmyObject = object      public        procedure doIt;      end;  public    procedure DoIt;  end;    procedure TMyClass.TMyObject.DoIt;  begin    writeln('DoIt from nested object');  end;    procedure TMyClass.DoIt;  var     d:TMyObject;    begin    d.DoIt;  end;    var  c:TMyClass;begin  c:=TMyClass.Create;  try    c.doit;  finally    c.free;  end;end. But indeed, Marco's answer is correct. The example is merely to illustrate the parent class can use variables from the child object, so you can also move that variable to the object instead. ---------------------------------------------------------------------- bytebites · 2020-04-28 14:02 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   { ca }   ca = class  public    type     { r }     r = object      parent: ca;      procedure Esegui;    end;  public    c: string;    rec: r;  constructor Create;  end;   { ca }   constructor ca.Create;  begin    rec.parent := self;  end;   procedure ca.r.Esegui;  begin    //How can I access here the variable c of the class ca    writeln(parent.c);  end; var  ci: ca;begin  ci:=ca.create;  ci.c:='Hello';  ci.rec.Esegui;end. ---------------------------------------------------------------------- Thaddy · 2020-04-28 15:10 That is what Marco referred. ---------------------------------------------------------------------- cappe · 2020-04-28 15:23 Nice idea. Thank you all. Quote from: bytebites on April 28, 2020, 04:02:14 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   { ca }   ca = class  public    type     { r }     r = object      parent: ca;      procedure Esegui;    end;  public    c: string;    rec: r;  constructor Create;  end;   { ca }   constructor ca.Create;  begin    rec.parent := self;  end;   procedure ca.r.Esegui;  begin    //How can I access here the variable c of the class ca    writeln(parent.c);  end; var  ci: ca;begin  ci:=ca.create;  ci.c:='Hello';  ci.rec.Esegui;end.