Mega Code Archive

 
Categories / Delphi / Examples
 

Bigprojects

MANAGING LARGE PROJECTS There are a number of things to bear in mind when embarking on a large project: first off: * ensure that the names of all units, and all forms in those units, are UNIQUE * ensure that when opening files, you don't just say 'open(filename)' without specifying a path. ALWAYS be careful about how you deal with filenames. Say you end up with the main code for a large project in a certain directory, with the code for a 'module' in a subdirectory, then IF YOU WANT TO KEEP DATA FILES FOR THE MODULE IN A SUBDIRECTORY, make sure you i) keep track of the initial 'startup' directory ii) hold the name of the subdirectory as a constant iii) hold the names of files you want to open at some point as constants, OR iv) get the startup path from Application.ExeName and lastly iv) put them all together so that you have, for example (See also ANOTHER ALTERNATIVE below -possibly better...) (in main application)-> public {public declarations} initialDir: String; procedure TMnREForm.FormCreate(Sender: TObject); begin initialDir := ExtractFilePath('WToolkit.exe'); end; (and then in a module)-> const subDirName = 'Cross\'; dictName = 'DICT.ASC'; var dictFile: TextFile; fileName: String; begin fileName := MnREForm.initialDir + subDirName + dictName; {associate a 'handle' variable with the file we want to open} AssignFile(dictFile, fileName); Reset(dictFile); {do stuff} Close(dictFile); end; OK? * And IF you have data files in some special place then you must always manage the way you keep track of their location BECAUSE the 'current directory' might easily be changed by users using Open Dialogue boxes or whatever to CHANGE the current directory and therefore the paths... ************************************************************************ ANOTHER ALTERNATIVE is to keep all important data files such as a wordlist that loads into memory when a module runs IN THE STARTUP DIRECTORY. Then, every time you use a file opening routine on one of these important files, you do it like this: const dataFileName = 'MyData.txt'; var exeFileName, pathToExe, fileName: String; begin exeFileName := Application.ExeName; pathToExe := ExtractFilePath(exeFileName); fileName := pathToExe + dataFileName; {and then open the file...} end; ************************************************************************ * Name the 'main' unit of a module appropriately so that you will always KNOW that it's the main unit for that module -this helps when later managing many many .pas files when coding up the main APPLICATION module -you might (often) easily want to go to a module's main .pas file and make changes (eg to hand a parameter across from the main 'application' module -so it helps if you know where to look immediately.