全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1205
推到 Plurk!
推到 Facebook!

ReplaceDialog問題~想做大量搜尋修改

答題得分者是:cashyy
Miki-lion
中階會員


發表:90
回覆:180
積分:54
註冊:2005-04-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-08 00:18:33 IP:218.162.xxx.xxx 未訂閱
好不容易看書上的學到這裡了(Dialog最後一個)~卻出了問題~~ 其他的部分都ok,只有ReplaceDialog這部份,問題在這行(下面有程式碼)     程式碼 //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if(OpenDialog1->Execute()) { RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { if(SaveDialog1->Execute()) { RichEdit1->Lines->SaveToFile(SaveDialog1->FileName); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { if(FontDialog1->Execute()) { RichEdit1->Font=FontDialog1->Font; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { ReplaceDialog1->Position = Point(RichEdit1->Left + RichEdit1->Width, RichEdit1->Top); ReplaceDialog1->Execute(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender) { TReplaceDialog *dlg = (TReplaceDialog *)Sender; /* perform a global case-sensitive search for FindText in Memo1 */ int SelPos = RichEdit1->Lines->Text.Pos(dlg->FindText); if (SelPos > 0) { RichEdit1->SelStart = SelPos - 1; RichEdit1->SelLength = dlg->FindText.Length(); // Replace selected text with ReplaceText RichEdit1->SelText = dlg->ReplaceText; } else MessageBeep(0); } //--------------------------------------------------------------------------- void __fastcall TForm1::ReplaceDialog1Find(TObject *Sender) { int FoundAt, StartPos, ToEnd; // 如果不是第一次搜尋,將接著下一個搜尋 if (RichEdit1->SelLength) StartPos = RichEdit1->SelStart + RichEdit1->SelLength; else // 如果是第一次搜尋,初始化StartPos StartPos = 0; // ToEnd是搜尋字串起始位址到RichEdit最末端位置的剩餘字串長度 ToEnd = RichEdit1->Text.Length() - StartPos; FoundAt = RichEdit1->FindText(ReplaceDialog1->FindText, StartPos, ToEnd, TSearchTypes()<< stMatchCase); if (FoundAt != -1) { RichEdit1->SetFocus(); RichEdit1->SelStart = FoundAt; RichEdit1->SelLength = ReplaceDialog1->FindText.Length(); } } //--------------------------------------------------------------------------- 感謝這裡的大大陪我成長。
cashyy
高階會員


發表:117
回覆:322
積分:212
註冊:2004-04-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-08 00:59:48 IP:59.104.xxx.xxx 未訂閱
您好!我試過相同的程式碼!可以正常執行!程式碼如下:
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if(OpenDialog1->Execute())
    RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button2Click(TObject *Sender)
{
  if(SaveDialog1->Execute())
    RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
  if(FontDialog1->Execute())
    RichEdit1->Font=FontDialog1->Font;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
  ReplaceDialog1->Position = Point(RichEdit1->Left + RichEdit1->Width, RichEdit1->Top);
  ReplaceDialog1->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender)
{
  TReplaceDialog *dlg = (TReplaceDialog *)Sender;
  /* perform a global case-sensitive search for FindText in Memo1 */
  int SelPos = RichEdit1->Lines->Text.Pos(dlg->FindText);
  if (SelPos > 0)
  {
    RichEdit1->SelStart = SelPos - 1;
    RichEdit1->SelLength = dlg->FindText.Length();
    // Replace selected text with ReplaceText
    RichEdit1->SelText = dlg->ReplaceText;
  }
  else
    MessageBeep(0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReplaceDialog1Find(TObject *Sender)
{
  int FoundAt, StartPos, ToEnd;
  // 如果不是第一次搜尋,將接著下一個搜尋
  if (RichEdit1->SelLength)
    StartPos = RichEdit1->SelStart + RichEdit1->SelLength;
  else
    // 如果是第一次搜尋,初始化StartPos
    StartPos = 0;
    // ToEnd是搜尋字串起始位址到RichEdit最末端位置的剩餘字串長度
    ToEnd = RichEdit1->Text.Length() - StartPos;
    FoundAt = RichEdit1->FindText(ReplaceDialog1->FindText, StartPos, ToEnd, TSearchTypes()<< stMatchCase);
    if (FoundAt != -1)
    {
      RichEdit1->SetFocus();
      RichEdit1->SelStart = FoundAt;
      RichEdit1->SelLength = ReplaceDialog1->FindText.Length();
    }
}
//---------------------------------------------------------------------------
[code]    請看一下.H裡面有沒有這些function或物件
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
        TButton *Button1;
        TButton *Button2;
        TButton *Button3;
        TButton *Button4;
        TOpenDialog *OpenDialog1;
        TReplaceDialog *ReplaceDialog1;
        TRichEdit *RichEdit1;
        TSaveDialog *SaveDialog1;
        TFontDialog *FontDialog1;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall Button2Click(TObject *Sender);
        void __fastcall Button3Click(TObject *Sender);
        void __fastcall Button4Click(TObject *Sender);
        void __fastcall ReplaceDialog1Replace(TObject *Sender);
        void __fastcall ReplaceDialog1Find(TObject *Sender);
private:        // User declarations
public:                // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
Miki-lion
中階會員


發表:90
回覆:180
積分:54
註冊:2005-04-24

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-08 02:52:32 IP:218.162.xxx.xxx 未訂閱
真的是少 void __fastcall ReplaceDialog1Replace(TObject *Sender); void __fastcall ReplaceDialog1Find(TObject *Sender); 這2行 不過我都有照著書上做 這地方怎會出錯呢? 另外跑出來的取代功能視窗,都在螢幕外面 跳出來的視窗位置我知道有個屬性可調~請問是哪裡呢? 最重要的是好像也沒有功能...XD 跟wordpad一樣的取代功能~~
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-08 13:16:33 IP:219.81.xxx.xxx 未訂閱
引言: 真的是少 void __fastcall ReplaceDialog1Replace(TObject *Sender); void __fastcall ReplaceDialog1Find(TObject *Sender); 這2行 不過我都有照著書上做 這地方怎會出錯呢?
這應該是你照著書KEY進去的吧 應該要選擇BCB的元件,他才會自動加到.h檔
系統時間:2024-11-23 18:35:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!