TMain (09/05/02)

CRHM

TMain - CRHM main window.

Routines

void __fastcall FormCreate(TObject *Sender);

  1. Changes Application->OnHelp to AppHelp.
  2. Sets default directories to CRHM program directory.
  3. Global::crhmMain set to Main->Handle for messaging.
  4. Creates Global Lists.
  5. Moves modules to CRHM by calling MoveModulesToGlobal();
  6. Updates models in Build menu.
  7. Determines if CRHM is DLL version and enables DLL menu.

void __fastcall FormActivate(TObject *Sender);

  1.  

void __fastcall FormDestroy(TObject *Sender);

  1. If (_HHwinHwnd) call HtmlHelp(...) and null _HHwinHwnd.
  2. Close observation files by deleting ClassData instances in ObsFilesList->Objects.
  3. Delete ObsFilesList.
  4. Call ModVarRemove(Global::MapVars) to remove all variable (observation and module).
  5. Delete ProjectList.
  6. Delete Global::OurModulesList.
  7. Delete Global::ModelModulesList.
  8. Free all TChart series.
  9. Call ClearListBox4(...) to
  10. If CRHM_DLL defined call FreeLibrary(...) for each DLL in OpenDLLs list.
  11. Delete OpenDLLs.

void __fastcall ExitClick(TObject *Sender);

  1. 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);

  1. Updates HRU # label when HRU changed.

void __fastcall UpDownOBSIndxClick(TObject *Sender, TUDBtnType Button);

  1.  

void __fastcall OpenClick(TObject *Sender);

  1. calls OpenDialog for observation file
  2. calls routine OpenObsFile

void __fastcall ObsFileClose(TObject *Sender);

  1.  

void __fastcall ObsCloseClick(TObject *Sender);

    Purpose - close all observation files.

  1. generates  "First observation File affects Obs timebase" prompt.
  2. clears ListBox2
  3. deletes all ClassData instances.

bool __fastcall OpenObsFile(TObject *Sender, String FileName);

    Purpose -  read observation file.

  1. Checks if file is already open.
  2. If the first observation file sets Global::DTstart and Global::DTend = 0.
  3. Status bar text set to "Reading Data File".
  4. Instantiates ClassData object.
  5. Status bar text set to "Idle".
  6. If the first observation file sets Global and DateTimePickers.
  7. Remove any of the obsevation variables currently in ListBox1 and ListBox3.
  8. Clear ListBox2 and rescan MapVars for observation variables.
  9. Update Observation menu.

void __fastcall BldModelClick(TObject *Sender);

    Purpose - build current model.

  1. Call ClearModulesClick().
  2. Load Global::OurModulesList from
  3. Search Global::AllModulesList->Strings for Global::OurModulesList modules and put their addresses in Global::OurModulesList->Objects list.
  4. Call InitModules()

void __fastcall RunClick(TObject *Sender);

    Purpose - Execute CRHM model.

  1. If any "Declaration Errors" exit.
  2. Call ClearRunLogs().
  3. Free any series currently in TChart.
  4. Exit if no model ouput requested in ListBox3.
  5. Instantiate TChart series required by ListBox3 count.
  6. Instantiate array of pointers to be set to variable value pointers.
  7. Process ListBox3 variables,  find object, decode dimension and layer from string and save in long or float array.
  8. Call InitReadObs() to clear storage for observation read and function lists.
  9. Call initbase() to initialise and declare modules.
  10. 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.
  11. Calculate the long indices, DTmin and DTmax from DTstart, DTEnd and DateTimePicker values DTstartR and DTendR.
  12. Initialise try exceptions for "Runtime Error" (Exception class) and module errors (CHMException class).
  13. Loop from DTmin to DTmax the following:
    1. Every 168 steps display date and time in status bar.
    2. Call ReadObs() to read current observation values.
    3. Loop through all modules->run() to execute module code.
    4. Loop through all variables to be displayed and add latest value to TChart series.
  14. 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.

  1. If not previously displaying module variable, load UpDownOBSIndex control and updat LabelOBSIndex.
  2. Display in status bar module variable help and units.
  3. If one or fewer layers reset to "LAY 1".

void __fastcall AddListBox1Click(TObject *Sender);

    Purpose - Handle ListBox1 pop-up.

  1. If ClassName == "TListBox" and Name == "ListBox1" do the following:
  2. If item in ListBox1 is selected do the following:
  3. Create name string with dimension and optional layer.
  4. If name string not already in ListBox3 add.

void __fastcall HRUsAddListBox1Click(TObject *Sender);

void __fastcall AddListBox2Click(TObject *Sender);

    Purpose - Handle ListBox2 pop-up.

  1. If ClassName == "TListBox" and Name == "ListBox2" or  If ClassName == "TLabel" and Name == "LabelFunct"do the following:
  2. If item in ListBox2 is selected do the following:
  3. Create name string with dimension and function.
  4. If name string is not already in ListBox4 add as follows.
  5. Create new TChart line series or point series if sparse data.
  6. Add to ListBox4 making the Object a pointer to the TChart series.
  7. Call AddObsPlot(...) to generate series on TChart.

void __fastcall ListBox2Click(TObject *Sender);

    Purpose - Change UpDownOBSIndex to display OBS# and update status bar.

  1. If not previously displaying observation, load UpDownOBSIndex control and updat LabelOBSIndex.
  2. Display in status bar observation variable help, units and file name.
  3. Update function label.

void __fastcall ListBox3Click(TObject *Sender);

    Purpose - delete module variable from ListBox3.

  1. If model not yet run, i.e. SeriesCnt <= 0, simply delete item from ListBox3 and exit.
  2. Search TChart cdSeries for variable name and then free series.
  3. Move following series up to fill hole.
  4. 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);

  1. Free all Tchart series defined by ListBox4.
  2. Call ListBox4-Clear().

void __fastcall FunctionListBox2Click(TObject *Sender);

    Purpose - Display RadioGroup1

  1. Set RadioGroup1 = Funct.
  2. Show RadioGroup1 control.

void __fastcall RadioGroup1Click(TObject *Sender);

    Purpose - update observation function display label.

  1. Set Funct = RadioGroup1->ItemIndex.
  2. Set LabelFunct->Caption = Function.
  3. 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);

  1. Call SaveDialogPrj-Execute().
  2. Call SaveProject().

void __fastcall PrjSaveClick(TObject *Sender);

  1. Call SaveProject() if project file name not empty,
  2. 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

  1. If function is last goto first otherwise increment Funct.
  2. 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.

  1. If the desired end time after defined data exit.
  2. Calculate the DTmin and DTmax data indices.
  3.  

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

  1. Display on screen Project file name.
  2. Add Description.
  3. Add Dimensions.
  4. Add Observations.
  5. If CRHM_DLL defined add DLLs.
  6. Add Modules.
  7. Add Dates.
  8. Add Parameters.
  9. Add Initial_State.
  10. Add Display_Variable.
  11. Add Display_Observation.
  12. Call ProjectList->SaveToFile().
  13. 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;