Hola... Espero no te moleste pero cambie un poquito tu codigo. No lo he probado mucho pero ahi tienes la idea
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
RichEditSQLConsulta: TRichEdit;
procedure RichEditSQLConsultaChange(Sender: TObject);
private
procedure SetTextFormat(SelStart, SelLength: Integer;
Color: TColor; Style: TFontStyles);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
SQL_RESERVED_WORDS =
'|SELECT|DISTINC|TOP|PERCENT|AS|FROM|WHERE|LIKE|BETWEEN|AND|OR|LEFT|RIGHT|ORDER|GROUP|BY|';
SQL_SEPARATOR_CHAR = [' ', #13, #10];
procedure TForm1.SetTextFormat(SelStart, SelLength: Integer;
Color: TColor; Style: TFontStyles);
begin
RichEditSQLConsulta.SelStart := SelStart;
RichEditSQLConsulta.SelLength := SelLength;
RichEditSQLConsulta.SelAttributes.Color := Color;
RichEditSQLConsulta.SelAttributes.Style := Style;
end;
procedure TForm1.RichEditSQLConsultaChange(Sender: TObject);
var
TmpSelStart: Integer;
P, SelStart, SelFinish, SelLength: Integer;
WordIn: string;
I: Integer;
begin
TmpSelStart := RichEditSQLConsulta.SelStart;
SelStart := 0; for I := RichEditSQLConsulta.SelStart downto 1 do
if RichEditSQLConsulta.Text[i] in SQL_SEPARATOR_CHAR then
begin SelStart := I;
Break;
end;
SelFinish := RichEditSQLConsulta.SelStart; for I := RichEditSQLConsulta.SelStart + 1 to RichEditSQLConsulta.GetTextLen do
if RichEditSQLConsulta.Text[i] in SQL_SEPARATOR_CHAR then
Break else
SelFinish := I;
SelLength := SelFinish - (SelStart + 1) + 1;
WordIn := Copy(RichEditSQLConsulta.Text, SelStart + 1, SelLength);
P := Pos('|' + UpperCase(WordIn) + '|', SQL_RESERVED_WORDS);
if 0 < P then
SetTextFormat(SelStart, SelLength, clBlue, [fsBold]) else
SetTextFormat(SelStart, SelLength, clWIndowText, []);
RichEditSQLConsulta.SelStart := TmpSelStart;
end;
end.
Me olvidaba sobre controlar el portapapeles (esta ultima parte no la probe pero ahi ta como deberia de implementarse)
Código Delphi
[-]
...
private
procedure WMDrawClipboard (var message : TMessage); message WM_DRAWCLIPBOARD;
procedure WMChangeCBCHain (var message : TMessage); message WM_CHANGECBCHAIN;
...
var
Form1: TForm1;
hClipboardViewer : THandle;
...
procedure TForm1.WMDrawClipboard (var message : TMessage);
begin
message.Result := SendMessage(WM_DRAWCLIPBOARD, hClipboardViewer, 0, 0);
if Clipboard.HasFormat(CF_TEXT) then
begin
end;
end;
procedure TForm1.WMChangeCBCHain (var message : TMessage);
begin
if message.wParam = Integer(hClipboardViewer) then
begin
hClipboardViewer := message.lParam;
message.Result := 0;
end else
begin
message.Result := SendMessage(hClipboardViewer, WM_CHANGECBCHAIN,
message.wParam, message.lParam);
end;
end;