I'm tidying up some code I've been given, for some reason, if the variables are defined under 'Private' (where they need to be to constrain access within this unit). I get EAccessViolation error when writing to them. If I loosely define them under Var just before implementaion they can be accessed ok. I'm comparing my structure with other similar units, where the Private units work fine & cant spot any significant differences.. Any suggestions?
Error MSG: Project --- raised exception class EAccessViolation Error with message 'access vilation error in module----. Read of address 0000050F
interface
uses
dialogs, math, dateutils, SysUtils, classes;
type
//double = extended;
TDoubleDoubleArray = array of array of double;
TSunPositionAlgorithm = class (TObject)
private
FLocationChanged: boolean;
public
Constructor Create;
Destructor Destroy;
procedure SetDefaults;
end;
Var
SunPositionAlgorithm : TSunPositionAlgorithm;
F_L0: Double;
F_L1: TDoubleDoubleArray;
implementation
{TSunPositionAlgorithm }
constructor TSunPositionAlgorithm.Create;
begin
SetDefaults;
end;
procedure TSunPositionAlgorithm.SetDefaults;
Begin
F_L0:= 1; // works ok
FLocationChanged:=true; // throws eaccess violation error
End;
Calling function (added to Post after David H's 1st question):
procedure TSun.NRELPositionOfSun(const DateTime: TDateTime; var Azimuth, Elevation, Declination: double);
Var
LSunPositionAlgorithm : TSunPositionAlgorithm;
Begin
LSunPositionAlgorithm := TSunPositionAlgorithm.Create;
Try
LSunPositionAlgorithm.SetDefaults;
blah..
Finally
LSunPositionAlgorithm.Destroy;
End;
End;