unit cfgwebwisacc; {$mode objfpc}{$H+} interface uses Classes, SysUtils; Type { TWebWisaccConfig } TWebWisaccConfig = Class(TComponent) private FAppDir: String; FDBConfig: String; FEndOfSchooljaar: TDateTime; FFileName: String; FFormsDir: String; FLogFile: String; FLogging: Boolean; FNaam: String; FPort: Integer; FProjectID: Integer; FSchooljaar: Integer; FStartOfSchooljaar: TDateTime; FThemes: TStrings; FURL: String; function GetEndOfSchooljaar: TDateTime; function GetStartOfSchooljaar: TDateTime; procedure SetThemes(const AValue: TStrings); Public Constructor Create(AOwner : TComponent); override; Destructor Destroy; override; Procedure LoadFromStream(AStream : TStream); Procedure SaveToStream(AStream : TStream); Procedure LoadFromFile(Const AFileName : String); Procedure SaveToFile(Const AFilename : String); Property AppDirectory : String Read FAppDir Write FAppDir; Property FileName : String Read FFileName; Published Property EventsURL : String Read FURL Write FURL; Property Naam : String Read FNaam Write FNaam; Property Port : Integer Read FPort Write FPort; Property Schooljaar : Integer Read FSchooljaar Write FSchooljaar; Property ProjectID : Integer Read FProjectID Write FProjectID; Property FormsDirectory : String Read FFormsDir Write FFormsDir; Property DBConfig : String Read FDBConfig Write FDBConfig; property Logging : Boolean Read FLogging Write FLogging; Property LogFile : String Read FLogFile Write FLogFile; end; Function Settings : TWebWisaccConfig; implementation uses dateutils; var TheSettings : TWebWisaccConfig; Function Settings : TWebWisaccConfig; begin If (TheSettings=Nil) then begin TheSettings:=TWebWisaccConfig.Create(Nil); TheSettings.Name:='wisaopleidingen'; end; Result:=TheSettings; end; { TWebWisaccConfig } procedure TWebWisaccConfig.SetThemes(const AValue: TStrings); begin if FThemes=AValue then exit; FThemes.Assign(AValue); end; function TWebWisaccConfig.GetEndOfSchooljaar: TDateTime; begin Result:=EncodeDate(Schooljaar+1,8,31); end; function TWebWisaccConfig.GetStartOfSchooljaar: TDateTime; begin Result:=EncodeDate(Schooljaar,9,1); end; constructor TWebWisaccConfig.Create(AOwner: TComponent); Var Y,M,D : Word; begin inherited Create(AOwner); FThemes:=TStringList.Create; FPort:=2015; DecodeDate(Date,Y,M,D); If M<9 then Schooljaar:=Y-1 else Schooljaar:=Y; FNaam:='Inschrijving voor Wisa Opleidingen'; end; destructor TWebWisaccConfig.Destroy; begin FreeAndNil(FThemes); inherited Destroy; end; procedure TWebWisaccConfig.LoadFromStream(AStream: TStream); Var M : TMemoryStream; begin M:=TmemoryStream.Create; try ObjectTextToBinary(AStream,M); M.Position:=0; M.ReadComponent(Self); finally M.free; end; end; procedure TWebWisaccConfig.SaveToStream(AStream: TStream); Var M : TMemoryStream; begin M:=TmemoryStream.Create; try M.WriteComponent(Self); M.Position:=0; ObjectBinaryToText(M,AStream); finally M.free; end; end; procedure TWebWisaccConfig.LoadFromFile(const AFileName: String); Var F : TFileStream; begin F:=TFileStream.Create(AFileName,fmOpenRead); try LoadFromStream(F); FFileName:=AFileName; finally FreeAndNil(F); end; end; procedure TWebWisaccConfig.SaveToFile(const AFilename: String); Var F : TFileStream; begin F:=TFileStream.Create(AFileName,fmCreate); try SaveToStream(F); FFileName:=AFileName; finally FreeAndNil(F); end; end; end.