TMain - CRHM main window.
Routines
void __fastcall FormCreate(TObject *Sender);
- Changes Application->OnHelp to AppHelp.
- Sets default directories to CRHM program directory.
- Global::crhmMain set to Main->Handle for messaging.
- Creates Global Lists.
- Moves modules to CRHM by calling MoveModulesToGlobal();
- Updates models in Build menu.
- Determines if CRHM is DLL version and enables DLL menu.
void __fastcall FormActivate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
- If (_HHwinHwnd) call HtmlHelp(...) and null _HHwinHwnd.
- Close observation files by deleting ClassData instances in ObsFilesList->Objects.
- Delete ObsFilesList.
- Call ModVarRemove(Global::MapVars) to remove all variable (observation and module).
- Delete ProjectList.
- Delete Global::OurModulesList.
- Delete Global::ModelModulesList.
- Free all TChart series.
- Call ClearListBox4(...) to
- If CRHM_DLL defined call FreeLibrary(...) for each DLL in OpenDLLs list.
- Delete OpenDLLs.
void __fastcall ExitClick(TObject *Sender);
- calls Application->terminate() to close the CRHM application.
void __fastcall DateTimePicker1Change(TObject *Sender);
void __fastcall DateTimePicker2Change(TObject *Sender);
void __fastcall UpDownHRUIndxClick(TObject *Sender, TUDBtnType Button);
- Updates HRU # label when HRU changed.
void __fastcall UpDownOBSIndxClick(TObject *Sender, TUDBtnType Button);
void __fastcall OpenClick(TObject *Sender);
- calls OpenDialog for observation file
- calls routine OpenObsFile
void __fastcall ObsFileClose(TObject *Sender);
void __fastcall ObsCloseClick(TObject *Sender);
Purpose - close all observation files.
- generates "First observation File affects Obs timebase" prompt.
- clears ListBox2
- deletes all ClassData instances.
bool __fastcall OpenObsFile(TObject *Sender, String FileName);
Purpose - read observation file.
- Checks if file is already open.
- If the first observation file sets Global::DTstart and Global::DTend = 0.
- Status bar text set to "Reading Data File".
- Instantiates ClassData object.
- Status bar text set to "Idle".
- If the first observation file sets Global and DateTimePickers.
- Remove any of the obsevation variables currently in ListBox1 and ListBox3.
- Clear ListBox2 and rescan MapVars for observation variables.
- Update Observation menu.
void __fastcall BldModelClick(TObject *Sender);
Purpose - build current model.
- Call ClearModulesClick().
- Load Global::OurModulesList from
- Search Global::AllModulesList->Strings for Global::OurModulesList modules and put their addresses in Global::OurModulesList->Objects list.
- Call InitModules()
void __fastcall RunClick(TObject *Sender);
Purpose - Execute CRHM model.
- If any "Declaration Errors" exit.
- Call ClearRunLogs().
- Free any series currently in TChart.
- Exit if no model ouput requested in ListBox3.
- Instantiate TChart series required by ListBox3 count.
- Instantiate array of pointers to be set to variable value pointers.
- Process ListBox3 variables, find object, decode dimension and layer from string and save in long or float array.
- Call InitReadObs() to clear storage for observation read and function lists.
- Call initbase() to initialise and declare modules.
- Exit after cleaning up, if there are LogForm errors or the Start time of the model run is greater or equal to the End time.
- Calculate the long indices, DTmin and DTmax from DTstart, DTEnd and DateTimePicker values DTstartR and DTendR.
- Initialise try exceptions for "Runtime Error" (Exception class) and module errors (CHMException class).
- Loop from DTmin to DTmax the following:
- Every 168 steps display date and time in status bar.
- Call ReadObs() to read current observation values.
- Loop through all modules->run() to execute module code.
- Loop through all variables to be displayed and add latest value to TChart series.
- Catch exceptions for "Runtime Error" and module errors.
void __fastcall ExportClick(TObject *Sender);
void __fastcall AboutClick(TObject *Sender);
Purpose - display About box.
void __fastcall ListBox1Click(TObject *Sender);
Purpose -Change UpDownOBSIndex to display LAY# and update status bar.
- If not previously displaying module variable, load UpDownOBSIndex control and updat LabelOBSIndex.
- Display in status bar module variable help and units.
- If one or fewer layers reset to "LAY 1".
void __fastcall AddListBox1Click(TObject *Sender);
Purpose - Handle ListBox1 pop-up.
- If ClassName == "TListBox" and Name == "ListBox1" do the following:
- If item in ListBox1 is selected do the following:
- Create name string with dimension and optional layer.
- If name string not already in ListBox3 add.
void __fastcall HRUsAddListBox1Click(TObject *Sender);
void __fastcall AddListBox2Click(TObject *Sender);
Purpose - Handle ListBox2 pop-up.
- If ClassName == "TListBox" and Name == "ListBox2" or If ClassName == "TLabel" and Name == "LabelFunct"do the following:
- If item in ListBox2 is selected do the following:
- Create name string with dimension and function.
- If name string is not already in ListBox4 add as follows.
- Create new TChart line series or point series if sparse data.
- Add to ListBox4 making the Object a pointer to the TChart series.
- Call AddObsPlot(...) to generate series on TChart.
void __fastcall ListBox2Click(TObject *Sender);
Purpose - Change UpDownOBSIndex to display OBS# and update status bar.
- If not previously displaying observation, load UpDownOBSIndex control and updat LabelOBSIndex.
- Display in status bar observation variable help, units and file name.
- Update function label.
void __fastcall ListBox3Click(TObject *Sender);
Purpose - delete module variable from ListBox3.
- If model not yet run, i.e. SeriesCnt <= 0, simply delete item from ListBox3 and exit.
- Search TChart cdSeries for variable name and then free series.
- Move following series up to fill hole.
- Delete module variable from ListBox3.
void __fastcall DeleteListBox3Click(TObject *Sender);
void __fastcall NegateListBox3Click(TObject *Sender);
void __fastcall ListBox4Click(TObject *Sender);
void __fastcall DeleteListBox4Click(TObject *Sender);
void __fastcall NegateListBox4Click(TObject *Sender);
void __fastcall ClearListBox4(TObject *Sender);
- Free all Tchart series defined by ListBox4.
- Call ListBox4-Clear().
void __fastcall FunctionListBox2Click(TObject *Sender);
Purpose - Display RadioGroup1
- Set RadioGroup1 = Funct.
- Show RadioGroup1 control.
void __fastcall RadioGroup1Click(TObject *Sender);
Purpose - update observation function display label.
- Set Funct = RadioGroup1->ItemIndex.
- Set LabelFunct->Caption = Function.
- Hide RadioGroup1 control.
void __fastcall ConstructClick(TObject *Sender);
void __fastcall InitModules(TObject *Sender);
void __fastcall ClearModules1Click(TObject *Sender);
void __fastcall Analysis1Click(TObject *Sender);
void __fastcall PrjOpenClick(TObject *Sender);
void __fastcall PrjExitClick(TObject *Sender);
void __fastcall PrjCloseClick(TObject *Sender);
void __fastcall PrjSaveAsClick(TObject *Sender);
- Call SaveDialogPrj-Execute().
- Call SaveProject().
void __fastcall PrjSaveClick(TObject *Sender);
- Call SaveProject() if project file name not empty,
- Else call PrjSaveAsClick(),
void __fastcall PrjAutoRunClick(TObject *Sender);
void __fastcall PrjReportClick(TObject *Sender);
void __fastcall StatSaveStateAsClick(TObject *Sender);
void __fastcall StatSaveClick(TObject *Sender);
void __fastcall StatOpenInitClick(TObject *Sender);
void __fastcall LogClick(TObject *Sender);
void __fastcall ParametersClick(TObject *Sender);
void __fastcall SqueezeParams(TObject *Sender);
void __fastcall HTMLhelp1Click(TObject *Sender);
void __fastcall ShapeClick(TObject *Sender);
void __fastcall Recall1Click(TObject *Sender);
void __fastcall Chart1ClickBackground(TCustomChart *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall DLL1OpenClick(TObject *Sender);
void __fastcall DLL1CloseALLClick(TObject *Sender);
void __fastcall LabelFunctClick(TObject *Sender);
Purpose - to select next observation function
- If function is last goto first otherwise increment Funct.
- Set LabelFunct->Caption to Fstrings[Funct];
void __fastcall VariablesClick(TObject *Sender); private: // User declarations
void __fastcall AddObsPlot(TObject *Sender, ClassVar *thisVar, TLineSeries *cdSeries, String S, TFun Funct);
Purpose - to display observation or function of observation on the TChart.
- If the desired end time after defined data exit.
- Calculate the DTmin and DTmax data indices.
void __fastcall FreeChart1(TObject *Sender);
void __fastcall SaveProject(TObject *Sender);
Purpose to save model to file. All strings are inserted into an instance ProjectList of type TStringList. When completed the list is saved to file using ProjectList->SaveToFile(). Finally ProjectList->clear() is called
- Display on screen Project file name.
- Add Description.
- Add Dimensions.
- Add Observations.
- If CRHM_DLL defined add DLLs.
- Add Modules.
- Add Dates.
- Add Parameters.
- Add Initial_State.
- Add Display_Variable.
- Add Display_Observation.
- Call ProjectList->SaveToFile().
- ProjectList->clear().
void __fastcall TMain::SaveState(TObject *Sender);
void __fastcall TMain::ReadStateFile(TObject *Sender, bool & GoodRun);
void __fastcall TMain::OnHint(TObject *Sender);
bool __fastcall AppHelp(Word Command, int Data, bool &CallHelp);
void __fastcall Update_Main(TDim Dim, long dim);
bool __fastcall DllinUse(String FileName);
void __fastcall DllFileClose(TObject *Sender);
void __fastcall CompactDlls(void);
bool __fastcall OpenDLLFile(String FileName);
void __fastcall DllDelete(String FileName);
void __fastcall UpDateModelMenu(void);
protected: void __fastcall WMGetMinMaxInfo(TWMGetMinMaxInfo &Msg); // prototype for msg handler
void __fastcall WMMainUpdate(TMessage &Message); // prototype for msg handler
void __fastcall WMMainStatus(TMessage &Message); // prototype for msg handler
BEGIN_MESSAGE_MAP MESSAGE_HANDLER(WM_GETMINMAXINFO,TWMGetMinMaxInfo, WMGetMinMaxInfo) MESSAGE_HANDLER(WM_CRHM_Main_UPDATE,TMessage, WMMainUpdate) MESSAGE_HANDLER(WM_CRHM_Main_STATUS,TMessage, WMMainStatus) END_MESSAGE_MAP(TForm)
public: // User declarations __fastcall TMain(TComponent* Owner);
TLineSeries **cdSeries; long SeriesCnt;
TStringList *ObsFilesList; TStringList *ProjectList; TStringList *OpenDLLs;
bool SaveStateFlag; bool OpenStateFlag; bool ProjectOpen;
typedef void __declspec(dllimport) LoadModuleType(String DllName);
LoadModuleType *LoadUserModules;
TDateTime ProjectFileDate;