Class constants lazarus / 8-Other ---------------------------------------------------------------------- PX · 2007-09-21 11:01 Hello, is it possible to have constants or read-only variables in a class? like: Quote type    TClass = class         const hello = 'hi';     end; Ive been pulling my hair trying to do this... Is there a way? Thanks! ---------------------------------------------------------------------- antonio · 2007-09-21 13:23 Couldn't you use a field? ---------------------------------------------------------------------- PX · 2007-09-21 15:04 a field? ---------------------------------------------------------------------- antonio · 2007-09-21 15:17 Code: [Select] type    TClass = class     FField:string;    public     property MyString:string read FField;  // a readonly property    end;     (...) constructor tclass.create; begin   // inherited Create here;   FField := 'hi'; end;        (...) ---------------------------------------------------------------------- PX · 2007-09-21 15:50 ah I see thanks =) ---------------------------------------------------------------------- pinaxe · 2016-07-04 17:22 Yep it is easy. //------------------------------------------- tMyClass = class(TObject)     MyInt  :integer;   private     const MYCONSTANT1=3;     procedure MyProc();   public     const MYCONSTANT2=4; end; //------------------------------------------- ---------------------------------------------------------------------- User137 · 2016-07-05 01:12 Or a function guarantees to be readonly 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  TClass = class  public    function MyString: string;  end;...function TClass.MyString;begin  Result := 'hi';end; If you add "inline" to it, it might remove all the overhead of a function call too.