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
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.
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 = Class
Private
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.