Question about initialisation in Class Constructor lazarus / 21-General ---------------------------------------------------------------------- Wilko500 · 2025-02-01 14:21 I have working class(s) used to hold variables that are used globally within my program.  These variable are required to persist between program runs and are loaded from an ini file during program startup.  As a sideline I am running on MacOs but using an ini file instead of XML, perhaps not ideal on Mac environment but at leat I am using the Application Support and Library Preferences file location as per good programming rules(?).  The program was migrated from VB6 and one day I'll get rid of the ini file. I have added initialisations in the class constructor and while reviewing my code for other purposes I noticed an inconsistency. For both classes my private variables are prefixed by v_ but in the constructor code I initialise one with the private var name and the other with property name 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   DisplayDate:=300000;  v_SystemName:='XX';The compiler does not object and both work as expected. I don't recall any reason why I coded them differently but I thought the correct way was to use the private var name.  Have I been lucky?  Can someone confirm the correct/preferred method of initialisation in constructor class. 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  unit U_clsGlobals; {$mode ObjFPC}{$H+} interface Type  TGlobals = Class Private  //Timers  v_DisplayDate:              Int64;  v_PvFileScan:               Int64;  v_PvUploadStartDelay:       Int64;  v_PvUploadInt:              Int64;  v_PvUploadSlotCheck:      Int64;  v_PvErrorLogCheck:          Int64; Public  Constructor Create();  //Timers  Property DisplayDate: Int64 Read v_DisplayDate Write v_DisplayDate;  Property PvFileScan: Int64 Read v_PvFileScan Write v_PvFileScan;  Property PvUploadStartDelay: Int64 Read v_PvUploadStartDelay Write v_PvUploadStartDelay;  Property PvUploadInt: Int64 Read v_PvUploadInt Write v_PvUploadInt;  Property PvUploadSlotCheck: Int64 Read v_PvUploadSlotCheck Write v_PvUploadSlotCheck;  Property PvErrorLogCheck: Int64 Read v_PvErrorLogCheck Write v_PvErrorLogCheck;End; Type  TSys = ClassPrivate  v_SystemName:    String;  v_SystemDate:    String;Public  Constructor Create();  Property SystemName: String Read v_SystemName Write v_SystemName;  Property SystemDate: String Read v_SystemDate Write v_SystemDate;End; Implementation Uses  Classes, SysUtils; Constructor TGlobals.Create();Begin  //Timers  DisplayDate:=300000;  PvFileScan:=300000;  PvUploadStartDelay:=300000;  PvUploadInt:=300000;  PvUploadSlotCheck:=300000;  PvErrorLogCheck:=300000;End;Constructor TSys.Create();Begin  v_SystemName:='XX';  v_SystemDate:='XX'; End; End. ---------------------------------------------------------------------- cdbc · 2025-02-01 14:31 Hi No worries mate, you can do both without problems. A lot of times, I have prop-setters with big side-effects, e.g.: loading a library, so it makes sense to initialize the property, which then again load a lib and initializes that, before it returns to the constructor again  HTH Regards Benny ---------------------------------------------------------------------- Wilko500 · 2025-02-01 14:57 Thanks Benny. Good to know that I haven’t broken the rules. By the way I love your strap line. One of my favourite sayings. ---------------------------------------------------------------------- ASerge · 2025-02-01 20:48 Quote from: Wilko500 on February 01, 2025, 03:57:53 pmGood to know that I haven’t broken the rules. I think Benny was being sarcastic, considering the last sentence. It is better to refer to self fields inside methods, rather than properties. ---------------------------------------------------------------------- Wilko500 · 2025-02-01 21:02 Hmmm! Quote from: ASerge on February 01, 2025, 09:48:40 pmIt is better to refer to self fields inside methods, rather than properties. This is what I would usually do. My question appears almost pointless now since both forms are apparently permissible. I was really asking from a point of wanting to lear/gain a better understanding.  You say it is better but is there a why?