{*******************************************************} { } { Responsive Software http://www.responsive.co.nz } { } { Copyright (c) 2003-2006 Responsive Software Limited } { } {*******************************************************} unit Globals; interface uses Classes, DB, SyncObjs, IBDatabase, Windows, DatabaseObjects, GeneralUtilities, AccountsCacheUnit, CashbooksCacheUnit, CommunicatorUnit, ClientCommunicatorUnit, ServerCommunicatorUnit, BusinessObjects, SalesManagerUnit, HTTPServerCommunicatorUnit, AttachmentCacheManagerUnit; const { Alias for database } BaseDatabaseName = 'FRAMEWORK'; { Registry key } BaseRegistryKey = 'Software\Responsive Software\Framework'; // identifying strings DevelopmentCompanyName = 'Responsive Software'; DevelopmentCompanyWebsite = 'www.responsive.co.nz'; ProgramName = 'Framework'; // help text HelpText = 'For help please call ???' + Chr(VK_RETURN) + Chr(VK_RETURN) + 'or email ???'; { BDE error codes } { The full list of these error codes can be found in \Program Files\Borland\Delphi6\Doc\Bde.int } eNoSuchTable = $2728; // the no of times a database operation should be retried // before showing an error message NoOfDatabaseRetries = 20; // the time to pause (in milliseconds) between retries PauseBetweenRetries = 100; // length of note text field NoteTextLength = 80; // default initial values DefaultControlColor = 11783167; DefaultPortNumber = 2557; DefaultHTTPPortNumber = 2558; DefaultCompanyName = 'Unregistered Software'; DefaultExpiryPeriod = 182; DefaultNoOfWorkstations = 3; // this is the initial id value used to generate unique ids InitialId = 1000; // used to specify non-selections in combo box ComboBoxNoneIndicator = ''; ComboBoxDefaultIndicator = ''; ComboBoxAllIndicator = ''; // used to replace null characters in strings before storing in a string field NullReplacement = '%0#'; // used to replace space characters in strings before storing in a string field SpaceReplacement = '%b#'; // used to replace CR characters in strings before storing in a string field CRReplacement = '%c#'; // used to replace LF characters in strings before storing in a string field LFReplacement = '%l#'; // descriptions used to indicate particular types of entries in accounts POSSalesDescription = 'POS Sales'; POSCreditsDescription = 'POS Credits'; CRLF = Chr(13) + Chr(10); var BDEDatabaseName : string; FirebirdDatabaseName : string; RegistryKey : string; // configuration settings which apply to all workstations GlobalConfiguration : TGlobalConfiguration; // configuration settings for this workstation only WorkstationConfiguration : TWorkstationConfiguration; // configuration settings for POS client (stored in registry) POSConfiguration : TPOSConfiguration; // user object (only relevant in client mode) User : TUser; // these globally accessible collections are populated // and kept up-to-date as required Companies : TDatabaseObjectCollection; Accounts : TDatabaseObjectCollection; Cashbooks : TDatabaseObjectCollection; Items : TDatabaseObjectCollection; LookupCodes : TDatabaseObjectCollection; Salespersons : TDatabaseObjectCollection; PaymentTypes : TDatabaseObjectCollection; // ? : TDatabaseObjectCollection; ReportLayouts : TBusinessObjectCollection; // this is a cache of general ledger accounts which have had their entries // loaded from the database // they are kept up to date whenever a change is made to any account by // creating, updating or deleting a combined entry AccountsCache : TAccountsCache; // this is a cache of cashbooks which have had their entries // loaded from the database // they are kept up to date whenever a change is made to any cashbook by // creating, updating or deleting an entry CashbooksCache : TCashbooksCache; // this object is used to manage queued sales before they are // posted to the database SalesManager : TSalesManager; // this object is used to manage the attachment cache AttachmentCacheManager : TAttachmentCacheManager; // this object is used to maintain conversations with and // send data to and from other workstations which are running // this application when running in a standard peer-to-peer // configuration Communicator : TCommunicator; // this object is used to faciliate communications with a server when // the application is running as a client ClientCommunicator : TClientCommunicator; // this object is used to provide services to connected clients // when the application is running as a server ServerCommunicator : TServerCommunicator; // this object is used to service requests from HTTP clients // when the application is running as a server with HTTP server turned on HTTPServerCommunicator : THTTPServerCommunicator; // general message log MessageLog : TMessageLog; ProgramVersion : string; ComputerName : string; UserName : string; IPAddresses : TStringList; ModeString : string; ClientUserName : string; ClientPassword : string; QuickReportOpen : boolean; DevelopmentMode : boolean; GenerateRegCodes : boolean; AllowPurgeLedger : boolean; AllChars : TFieldChars; AccountTypeChars : TFieldChars; // flag to indicate running mode ClientMode : boolean; ServerMode : boolean; StandardMode : boolean; ConversionMode : boolean; // flag to indicate POS mode // note that ClientMode will also be set to true in POS mode // however the program will still run even if there is no // connection established with the server // in this case the Offline flag will be set POSMode : boolean; Offline : boolean; // flag to turn on server logging ServerLogging : boolean; // flag to indicate HTTP server in operation // only relevant in server mode HTTPServer : boolean; // flag to indicate we are using Firebird database server // instead of default BDE and Paradox Firebird : boolean; // firebird login details FirebirdUserName : string; FirebirdPassword : string; FirebirdServerIPAddress : string; // server details to use when running in client mode ServerIPAddress : string; ServerPortNumber : integer; // values for client/server communications (in milliseconds) ClientTimeout : integer; // client timeout ServerTimeout : integer; // server timeout MaxDatabaseLockTime : integer; // maximum time database can be locked MessagingPollTime : integer; // time between message polls POSSalesDataPostTime : integer; // time between posts of queued sales POSDataLoadTime : integer; // time between loads of POS data in offline mode // seeds used for encryption & registration code generation ClientServerEncryptRandSeed : integer; UserPasswordEncryptRandSeed : integer; RegistrationCodeRandSeed : integer; threadvar // session name used for access to BDE database TVSessionName : string; // TIBDatabase used for access to Firebird database TVFirebirdDatabase : TIBDatabase; // TThread reference to current thread TVThread : TThread; procedure Initialize; procedure CreateGlobalCollections; procedure CreateCommunicator; procedure CreateClientCommunicator; procedure CreateServerCommunicator; procedure CreateHTTPServerCommunicator; procedure DestroyCommunicator; implementation uses SysUtils, Dialogs, Utilities; procedure Initialize; var i : integer; begin SaveRegistryString('',''); DevelopmentMode := GetRegistryString('DEV') = 'DEV'; GenerateRegCodes := GetRegistryString('REG') = 'REG'; AllowPurgeLedger := GetRegistryString('PURGE') = 'PURGE'; if ClientMode or Firebird then MessageLog := TMessageLog.Create (ExeDirectory + 'Message.Log',$100000) else MessageLog := TMessageLog.Create (DatabaseDirectory + 'Message.Log',$100000); ProgramVersion := GetProgramVersion; ComputerName := GetComputerName; UserName := GetUserName; IPAddresses := TStringList.Create; if not StandardMode then GetIPAddresses(IPAddresses); ModeString := GetModeString; if DevelopmentMode then begin ClientTimeout := 86400000; // 24 hours ServerTimeout := 86400000; // 24 hours MessagingPollTime := 1000; // 1 second POSSalesDataPostTime := 1000; // 1 second POSDataLoadTime := 1000; // 1 second end else begin ClientTimeout := 600000; // 10 minutes ServerTimeout := 1800000; // 30 minutes MessagingPollTime := 20000; // 20 seconds POSSalesDataPostTime := 30000; // 30 seconds POSDataLoadTime := 30000; // 30 seconds end; MaxDatabaseLockTime := 60000; // 1 minute AccountsCache := TAccountsCache.Create; CashbooksCache := TCashbooksCache.Create; SalesManager := TSalesManager.Create; AttachmentCacheManager := TAttachmentCacheManager.Create; // used to allow any character to be typed into a numeric field AllChars := ['a'..'z','A'..'Z','0'..'9','(',')',' ']; // used to validate entry into account type field AccountTypeChars := [' ','A','L','P','I','E','a','l','p','i','e']; // create encryption seeds ClientServerEncryptRandSeed := 3412; UserPasswordEncryptRandSeed := 637834; RegistrationCodeRandSeed := 72323; for i := 1 to Length(ProgramName) do begin ClientServerEncryptRandSeed := ClientServerEncryptRandSeed + Ord(ProgramName[i]); UserPasswordEncryptRandSeed := UserPasswordEncryptRandSeed - Ord(ProgramName[i]); RegistrationCodeRandSeed := RegistrationCodeRandSeed + Ord(ProgramName[i]); end; end; procedure CreateGlobalCollections; begin {$IFDEF ACCOUNTS} CreateGlobalMaintainedCollection(Companies,TCompany); CreateGlobalMaintainedCollection(Accounts,TAccount); CreateGlobalMaintainedCollection(Cashbooks,TCashbook); {$ENDIF} {$IFDEF POS} CreateGlobalMaintainedCollection(Items,TItem); CreateGlobalMaintainedCollection(LookupCodes,TLookupCode); CreateGlobalMaintainedCollection(Salespersons,TSalesperson); CreateGlobalMaintainedCollection(PaymentTypes,TPaymentType); {$ENDIF} end; procedure CreateCommunicator; begin try // in development mode simulate communications locally if DevelopmentMode or (NoOfWorkstations <= 1) then Communicator := TCommunicator.Create(true) else Communicator := TCommunicator.Create(false); except // display exception message on E:Exception do begin ShowMessage(E.Message); Communicator := nil; end; end; end; procedure CreateClientCommunicator; begin ClientCommunicator := TClientCommunicator.Create(ServerIPAddress,ServerPortNumber); end; procedure CreateServerCommunicator; begin try ServerCommunicator := TServerCommunicator.Create; except // display exception message on E:Exception do begin ShowMessage(E.Message); ServerCommunicator := nil; end; end; end; procedure CreateHTTPServerCommunicator; begin try HTTPServerCommunicator := THTTPServerCommunicator.Create; except // display exception message on E:Exception do begin ShowMessage(E.Message); HTTPServerCommunicator := nil; end; end; end; procedure DestroyCommunicator; begin Communicator.Free; ClientCommunicator.Free; ServerCommunicator.Free; HTTPServerCommunicator.Free; end; end.