CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MDI - Determining what child window is selected??



Here is a routine that determines the active child and sets a pointer to it.
It is part of a routine from Kent's 14 day book, I think, that comes with
BCB3. Anyway, it uses a dynamic cast to avoid problems with null pointers, I
think. Sorry, I'm kind of rushed, dinner's ready!


void __fastcall TMainForm::FileSave(TObject *Sender)
{
 //---- Add code to save current file under current name ----
    TRTFChild* rtfchild = dynamic_cast<TRTFChild*>(ActiveMDIChild);
    if(!rtfchild) return;
    if (rtfchild->fname.Length())
	rtfchild->RichEdit1->Lines->SaveToFile(rtfchild->fname);
    else {
        if (SaveDialog->Execute()) {
            rtfchild->fname = SaveDialog->FileName;
            rtfchild->Caption = ExtractFileName(rtfchild->fname);
            if (ExtractFileExt(SaveDialog->FileName) == ".rtf")
		rtfchild->RichEdit1->PlainText = false;
            else 
		rtfchild->RichEdit1->PlainText = true;
            rtfchild->RichEdit1->Lines->SaveToFile(rtfchild->fname);
        }
    }
}


W Komornicki's Home Page | Main Index | Thread Index