Print this
window
// In the header
TMenuItem *prevMenu[MAX_PREV_FILE + 1];
// In the body
void __fastcall TfrmPDMain::mmFileClick(TObject *Sender)
{
// Found that if use missing letters, A and C, menu does display correctly
char alpha[] = { 'B', 'D', 'E', 'F', 'G', 'H' };
const NUM_MAX = 9; // Found that if number goes to 10, menu will not display correctly
AnsiString cap;
clearPrevMenuItems();// My responsibility to delete the previous menu (shown below)
TStringList *str = new TStringList(); // Create a new string list so I can read the file
char file[MAXPATH];
sprintf(file, "%s%s", WPDGetDirPath(PD_HOME_DIR), WPDPersistFile[PD_PREV_SCH_PATHS_FILE]);
if (FileExists(file))
{
try
{
int ctr = 0;
int startInsert = INSERT_PREV_FILE;// Where I want the menu items to be inserted at
str->LoadFromFile(file);
while ((ctr < str->Count) && (ctr < MAX_PREV_FILE))// Double check the amount of menu items to load
{
prevMenu[ctr] = new TMenuItem(mmFile);// Create the new menu item
if ((ctr + 1) <= NUM_MAX) // Goes past ten and starts placing underbar on path
cap = (IntToStr(ctr + 1) + ". " + str->Strings[ctr]);
else // Goes past 9 I had problems with display
cap = ((AnsiString)alpha[ctr - NUM_MAX] + ". " + str->Strings[ctr]);
prevMenu[ctr]->Caption = cap; // Assigning the caption to the menu item. It handles the underscore for me
prevMenu[ctr]->OnClick = PrevSearchClick; // Assign the method that will handle a click(shown below)
mmFile->Insert(startInsert, prevMenu[ctr]);// Now insert the menu item
++startInsert; // Increment everything
++ctr;
}// End the while
prevMenu[ctr] = new TMenuItem(mmFile); // I am wanting a spacer after the last inserted menu item
prevMenu[ctr]->Caption = "-";
mmFile->Insert(startInsert, prevMenu[ctr]);
} // End the try
catch (...) {}
} // End the if
delete str;
str = 0;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPDMain::PrevSearchClick(TObject *Sender)
{
AnsiString cap = ((TMenuItem *)Sender)->Caption;
int pos = cap.Pos(" "); // Menu item looks like: 1. C:\test\test2\test3.txt Find pos of the space
cap.Delete(1, pos); // Delete everything up to and including the space
beginSearch(cap);
} // End the PrevSearchClick method
//============================================================================
void TfrmPDMain::clearPrevMenuItems()
{
for (int i=0;i {
if (prevMenu[i])
{
delete prevMenu[i];
prevMenu[i] = 0;
} // End the if
} // End the for
} // End the clearPrevMenuItems method