안안녕하세요. 초웁니다.
저 경고 먹었나봐요...흑흑~ 히히...
메일로 보내지 않고 여기에 소스를 전부 올려 놓겠습니다.
음 우선 간단하게 폼에 RichEdit를 하나올려 놓고 버튼을 두개,
OpenDialog하나하고, FindDialog하나를 올려 놓은다음 시작하죠.
다음 소스를 보세요.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
FindDialog1: TFindDialog;
OpenDialog1: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
FindDialog1.Execute;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: integer;
begin
with RichEdit1 do
begin
{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
{ ToEnd is the length from StartPos to the end of the text in the rich edit control }
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end;
end;
end;
end.
이 내용은 도움말에 있는 내용을 그대로 한줄도 안빼고 단지 ;(세미콜론)하나
지워버린거 밖에 없어요. (도움말에 버그가?~~ ^^)
그럼 도움이 되길 바랍니다.
좋은 코딩하시구여.....
그럼 이만.
|