home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Examples / Apps / FindRep / MAINFORM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  2.7 KB  |  85 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8.  
  9. #include "mainform.h"
  10. //---------------------------------------------------------------------------
  11. #pragma resource "*.dfm"
  12. TForm1 *Form1;
  13. //---------------------------------------------------------------------------
  14. __fastcall TForm1::TForm1(TComponent* Owner)
  15.     : TForm(Owner)
  16. {
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TForm1::Find1Click(TObject *Sender)
  20. {
  21.     FindDialog1->FindText = RichEdit1->SelText;
  22.     FindDialog1->Execute();
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::Replace1Click(TObject *Sender)
  26. {
  27.     ReplaceDialog1->FindText = RichEdit1->SelText;
  28.     ReplaceDialog1->Execute();
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TForm1::Find(TObject *Sender)
  32. {
  33.     TSearchTypes st;
  34.     TFindDialog *cd;
  35.     int newpos;
  36.  
  37.     if ((cd = dynamic_cast<TFindDialog *> (Sender)) == 0)
  38.         MessageBox(NULL, "Dynamic Cast Failed!", "Find/Rep", MB_OK);
  39.  
  40.     if (cd->Options.Contains(frMatchCase))
  41.         st << stMatchCase;
  42.     if (cd->Options.Contains(frWholeWord))
  43.         st << stWholeWord;
  44.  
  45.     if (RichEdit1->SelLength)
  46.         RichEdit1->SelStart += 1;
  47.  
  48.     newpos = RichEdit1->FindText(cd->FindText,
  49.                         RichEdit1->SelStart,
  50.                         RichEdit1->Text.Length(),
  51.                         st);
  52.  
  53.     if (newpos != -1)
  54.     {
  55.         RichEdit1->SelStart = newpos;
  56.         RichEdit1->SelLength = cd->FindText.Length();
  57.     }
  58.     else
  59.     {
  60.         MessageBox(NULL, "End of document reached.", "Find/Rep", MB_OK);
  61.         RichEdit1->SelStart = 0;
  62.     }
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm1::Replace(TObject *Sender)
  66. {
  67.     if (RichEdit1->SelLength == 0)
  68.         Find(Sender);
  69.     else
  70.     {
  71.         RichEdit1->SelText =  ReplaceDialog1->ReplaceText;
  72.         Find(Sender);
  73.     }
  74.  
  75.     if (ReplaceDialog1->Options.Contains(frReplaceAll))
  76.         while (RichEdit1->SelLength !=0)
  77.             Replace(Sender);
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TForm1::FormCreate(TObject *Sender)
  81. {
  82.     RichEdit1->SelStart = 0;
  83. }
  84. //---------------------------------------------------------------------------
  85.