RichEdit

Delphi

25/10/2005

Pessoal, uso o codigo abaixo para destacar automaticamente palavras/simbolos no meu RichEdit:

procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
const
  LetrasValidas = [´a´..´z´, ´A´..´Z´, ´0´..´9´, ´<´, ´>´, ´!´,  ´=´];

var
  iPosIni: Integer;
  iPosFim: Integer;
  iSelStart: Integer;
  iSelLength: Integer;
  iLoopFor: Integer;
  sText: String;
begin

  LockWindowUpdate(RichEdit1.Handle);

  { guardaremos a posição inicial }
  iSelStart := RichEdit1.SelStart;
  iSelLength := RichEdit1.SelLength;

  sText := RichEdit1.Text;

  { Acharemos o inicio da palavra }
  iPosIni := iSelStart;
  if sText[ iPosIni ] in LetrasValidas then
    begin
      for iLoopFor := iSelStart-1 downto 0 do
        begin
          if sText[ iLoopFor ] in LetrasValidas then
            iPosIni := iLoopFor
          else
            Break;
        end;
    end;

  { Acharemos o final da palavra }
  iPosFim := iSelStart;
  for iLoopFor := iSelStart+1 to Length( RichEdit1.Text ) do
    begin
      if RichEdit1.Text[ iLoopFor ] in LetrasValidas then
        iPosFim := iLoopFor
      else
        Break;
    end;

  { Selecionaremos a palavra }
  RichEdit1.SelStart := iPosIni-1;
  RichEdit1.SelLength := (iPosFim)-RichEdit1.SelStart;

  { setaremos a cor original }
  RichEdit1.SelAttributes.Color := clBlack;

  { Atribuiremos a nova cor caso encontre a palavra }
  for iLoopFor := 0 to High( APalavras ) do
    begin
      if APalavras[ iLoopFor ].DS_PALAVRA = RichEdit1.SelText then
        begin
          RichEdit1.SelAttributes.Color := APalavras[ iLoopFor ].VR_COR;
          Break;
        end;
    end;

  { Posicionaremos o cursor na posição original }
  RichEdit1.SelStart := iSelStart;
  RichEdit1.SelLength := iSelLength;

  LockWindowUpdate(0);
end;


Onde eu defina as palavras no OnShow()
procedure TForm1.FormShow(Sender: TObject);
begin
  SetLength( APalavras, Length( APalavras )+1 );
  APalavras[ High( APalavras ) ].DS_PALAVRA := ´private´;
  APalavras[ High( APalavras ) ].VR_COR := clBlue;

  SetLength( APalavras, Length( APalavras )+1 );
  APalavras[ High( APalavras ) ].DS_PALAVRA := ´public´;
  APalavras[ High( APalavras ) ].VR_COR := clRed;
end;


  TRPalavras = Record
    DS_PALAVRA: String;
    VR_COR : TColor;
  end;

  TAPalavras = array of TRPalavras;


Sendo que eu não consigo colocar alguns simbolos para destacar automaticamente, nem palavras com delimitiadores.

[b:6e88ad335b]Por exemplo:[/b:6e88ad335b]
Nao funcionam: >= <=
´este texto deve ser destacado´
//este tb deve ser destacado.


Alguem pode me ajudar a implementar isto no codigo citado acima?

Abraços


Aloizio Castro

Aloizio Castro

Curtidas 0
POSTAR