//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ReplaceText.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: ReplaceText
// Event: Dialogs.TReplaceDialog.OnReplace
// Property: Dialogs.TReplaceDialog.ReplaceText

// BeginCode
/*
The following event handler searches a TMemo object called
Memo1 and replaces FindText with ReplaceText. It uses
TMemo’s SelStart, SelLength, and SelText properties.
*/
void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender)
{
  TReplaceDialog *dlg = dynamic_cast<TReplaceDialog *>(Sender);
  /* perform a global case-sensitive search for FindText in Memo1 */
  int SelPos = Memo1->Lines->Text.Pos(dlg->FindText);
  if (SelPos > 0)
  {
    Memo1->SelStart = SelPos - 1;
	Memo1->SelLength = dlg->FindText.Length();
	// Replace selected text with ReplaceText
	Memo1->SelText = dlg->ReplaceText;
  }
  else
	MessageBeep(0);
}
// EndCode
// EndExample: ReplaceText

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ReplaceDialog1->Execute();
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  AnsiString Path = "../overview.RTF";
  Memo1->Lines->LoadFromFile(Path);
}
//---------------------------------------------------------------------------

