現在 TMemoコンポーネントをTRichEditに変更しようと思っています。
ものとしては SQLを記載するのですが、
Editorの単語をダブルクリックした時に
UNDERSCORE(_)を含む場合
TMemoコンポーネントでは、UNDERSCOREを区切文字として判定しておらず
TRichEditでは、UNDERSCOREを区切文字として判定されています。
例) KAI_CD で CD部分をダブルクリック
TMemo ⇒ KAI_CD が選択
TRichEdit ⇒ CD が選択
TMemoの挙動にしたいのですが、わかる方いましたら
教えてください。
自分で現在書いているソースを記載しますが、
うまくいきません。(そもそもが違う気もしていますが・・・)
以下
const
WB_CLASS_WHITESPACE = 0;
WB_CLASS_LINEBREAK = 1;
WB_CLASS_DELIMITER = 2;
WB_CLASS_NORMALCHAR = 3;
WBF_CLASS = $0000000F;
WBF_ISWHITE = $00000010;
WBF_BREAKLINE = $00000020;
WBF_BREAKAFTER = $00000040;
WB_CLASSIFY = 3;
WB_MOVEWORDLEFT = 4;
WB_MOVEWORDRIGHT = 5;
WB_LEFTBREAK = 6;
WB_RIGHTBREAK = 7;
WHITESPACE: Set of Char = [#9, #32];
DELIMITERS: Set of Char = ['"', '[', ']', '(', ')', ';', ',','.', '\', ''''];
LINEBREAKERS: Set of Char = [#10, #13];
procedure TForm1.FormShow(Sender: TObject);
begin
// {$IFDEF WIN32}
NewWordBreakProc := @MyWordBreakProc;
// {$ELSE}
NewWordBreakProc := MakeProcInstance(@MyWordBreakProc,
hInstance);
SendMessage(RichEdit1.Handle,
EM_SETWORDBREAKPROC,
0,
longint(NewWordBreakProc));
end;
function isInDelimiterList(c : char ) : boolean ;
begin
result:=(C in LINEBREAKERS);
end;
function MyWordBreakProc(pchText : pchar;
ichCurrent : integer;
cch : integer;
code : integer) : integer;
{$IFDEF WIN32} stdcall; {$ELSE} ; export; {$ENDIF}
var
lRet : integer;
i : integer ;
found : boolean;
initialPos : integer ;
begin
lRet := 0 ;
i := 0 ;
found := False;
initialPos := ichCurrent ;
result:=0;
case code of
WB_LEFT : begin
while (not(IsInDelimiterList(pchText[ichCurrent])) and (ichCurrent > 0)) do Dec(ichCurrent);
if (ichCurrent > 0) then result:=Succ(ichCurrent)
else result:=-1;
end ;
WB_RIGHT : begin
while (not(IsInDelimiterList(pchText[ichCurrent])) and (ichCurrent <cch)) do Inc(ichCurrent);
if (ichCurrent > 0) then result:=ichCurrent
else result:=-1;
end;
WB_ISDELIMITER : begin
result:=1 ;
end;
WB_CLASSIFY: begin
if (pchText^ in WHITESPACE) then result:=WBF_ISWHITE or WB_CLASS_WHITESPACE
else if (pchText^ in DELIMITERS) then result:=WBF_BREAKAFTER or WB_CLASS_DELIMITER
else if (pchText^ in LINEBREAKERS) then result:=WBF_BREAKLINE or WB_CLASS_DELIMITER
else result:=WB_CLASS_NORMALCHAR;
end;
WB_MOVEWORDLEFT : begin
Dec(ichCurrent);
found:=False;
while IsInDelimiterList(pchText[ichCurrent]) do Dec(ichCurrent);
while (ichCurrent < cch) and not(found) and (ichCurrent >= 0) do begin
found:=IsInDelimiterList(pchText[ichCurrent]);
if (found and (ichCurrent >=0)) then begin
result:=Succ(ichCurrent)
end else begin
//result:=MaxInt; isCoresponse
result := -1 ;
Dec(ichCurrent);
end;
end;
end;
WB_MOVEWORDRIGHT : begin
if not(IsInDelimiterList(pchText[ichCurrent])) then begin
while (not(IsInDelimiterList(pchText[ichCurrent])) and (ichCurrent < cch)) do begin
Inc(ichCurrent);
end;
end;
while (IsInDelimiterList(pchText[ichCurrent]) and (ichCurrent < cch)) do Inc(ichCurrent);
if (ichCurrent <= cch) then result:=Succ(ichCurrent)
else result:=-1;
end;
WB_LEFTBREAK : begin
while (not(IsInDelimiterList(pchText[ichCurrent])) and (ichCurrent > 0)) do Dec(ichCurrent);
if (ichCurrent > 0) then result:=ichCurrent
else result:=-1;
end;
WB_RIGHTBREAK : begin
while (not(isInDelimiterList(pchText[ichCurrent])) and (ichCurrent <cch)) do Inc(ichCurrent);
if (ichCurrent > 0) then result:=ichCurrent
else result:=-1;
end ;
end;
end;
ツイート | ![]() |