PDA

View Full Version : select کردن یک متن در memo



Delphi Skyline
پنج شنبه 08 اردیبهشت 1384, 22:04 عصر
select کردن یک متن در memo ?

m-khorsandi
پنج شنبه 08 اردیبهشت 1384, 22:26 عصر
درود
منظورت اینه که یک متنی رو جستجو کنی و بعد هم همون رو توی Memo انتخاب شده ببینی؟

vcldeveloper
جمعه 09 اردیبهشت 1384, 02:28 صبح
از راهنمای دلفی :


The following OnFind event handler searches a memo component for the text specified in the FindText property of a find dialog component. If found, the first occurrence of the text in Memo1 is selected. The code uses the Pos function to compare strings, and stores the number of characters to skip when determining the selection position in the SkipChars variable. Because there is no handling of case, whole word, or search direction in this algorithm, it is assumed that the Options property of FindDialog1 was set to [frHideMatchCase, frHideWholeWord, frHideUpDown].

procedure TForm1.FindDialog1Find(Sender: TObject);

var
I, J, PosReturn, SkipChars: Integer;
begin
for I := 0 to Memo1.Lines.Count do
begin
PosReturn := Pos(FindDialog1.FindText,Memo1.Lines[I]);
if PosReturn <> 0 then {found!}
begin
SkipChars := 0;
for J := 0 to I - 1 do
SkipChars := SkipChars + Length(Memo1.Lines[J]);
SkipChars := SkipChars + (I*2);
SkipChars := SkipChars + PosReturn - 1;

Memo1.SetFocus;
Memo1.SelStart := SkipChars;
Memo1.SelLength := Length(FindDialog1.FindText);
Break;
end;
end;

end;

Delphi Skyline
جمعه 09 اردیبهشت 1384, 11:14 صبح
متشکرم آقای کشاورز . اما من منظورم اینه که اونو select کرد . مثلا از کاراکتر 2 تا 7 را select کرد . یعنی به صورت سیاه دیده شود.

Touska
جمعه 09 اردیبهشت 1384, 11:49 صبح
از RichEdit استفاده کن که خیلی راحته و Demo شو خود دلفی داره.

موفق باشید :flower:

m-khorsandi
جمعه 09 اردیبهشت 1384, 11:55 صبح
Memo1.SetFocus;
Memo1.SelStart := SkipChars;
Memo1.SelLength := Length(FindDialog1.FindText);

خوب این چند خط آخر همین کار رو میکنه!

Touska
جمعه 09 اردیبهشت 1384, 11:57 صبح
یا با این روش Send Message ها


#23: How can I get a line/column number that a memo/richtext cursor is on?

If you want to retrieve the line and/or column number you must send a messages to control and retrieve the result:

For TRichEdit you must send a EM_EXLINEFROMCHAR and EM_LINEINDEX messages.
For TMemo you must send a EM_LINEFROMCHAR and EM_LINEINDEX messages.

The WParam contains the character number that you wish the line number for, or -1 for the current line (where the caret is located or the beginning of a text selection).

View examples:
- for TMemo
LineNumber := SendMessage(Memo1.Handle, EM_LINEFROMCHAR, -1, 0);

- for TRichEdit
LineNumber := SendMessage(RichEdit1.Handle, EM_EXLINEFROMCHAR, 0, RichEdit1.SelStart);
ColNumber := (RichEdit1.SelStart - SendMessage(RichEdit1.Handle, EM_LINEINDEX, LineNumber, 0));


موفق باشید :flower:

m-khorsandi
جمعه 09 اردیبهشت 1384, 11:58 صبح
ساده تر از اینم دیگه نمیشه:



Memo1.SetFocus;
Memo1.SelStart := 2;
Memo1.SelLength := 7;

Delphi Skyline
جمعه 09 اردیبهشت 1384, 12:34 عصر
متشکرم . از همه !!!