Hola amigos:
Estoy intentando crear un componente TRichEdit con un corrector ortografico basado en Hunspell. De momento funciona correctamente y me marca en rojo las palabras incorrectas.
Al hacer clic sobre la palabra desearía crear un panel para poder, mediante un memo visulizar las palabras correctas.
Pero no se como hacerlo, he conseguido crear un panel pero dentro del RichEdit y claro yo necesito que se cree fuera.
Adjunto el código del componente por si alguien puede ayudarme.
Código Delphi
[-]
type
TRichDic = class(TRichEdit)
private
FOldBackColor: TColor;
FColorOnEnter: TColor;
FHunspell: TNHunspell;
FDic: TStringList;
Paraula: string;
property OldBackColor: TColor read FOldBackColor write FOldBackColor;
procedure UpdateDics;
procedure ComprovarParaula(ValorLl, ValorIn, ValorOut: integer);
protected
procedure DoEnter; override;
procedure DoExit; override;
procedure KeyPress(var Key: Char); override;
procedure Click; override;
public
constructor Create(AOwner: TComponent); override;
destructor destroy; override;
published
property ColorOnEnter: TColor read FColorOnEnter write FColorOnEnter;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('jrComponents', [TRichDic]);
end;
procedure TRichDic.ComprovarParaula(ValorLl, ValorIn, ValorOut: integer);
var
tmpStr: TUnicodeStringList;
POsi: integer;
begin
if TNHSpellDictionary(FDic.Objects[0]).Spell(Paraula) then
SelAttributes.Color := clBlack
else begin
selStart := ValorIn;
SelLength := ValorLl;
SelAttributes.Color := clRed;
SelText := Paraula;
SelAttributes.Color := clBlack;
end;
end;
constructor TRichDic.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FColorOnEnter := Color;
UpdateDics;
end;
destructor TRichDic.destroy;
begin
inherited;
end;
procedure TRichDic.DoEnter;
begin
OldBackColor := Color;
Color := ColorOnEnter;
inherited;
end;
procedure TRichDic.DoExit;
begin
Color := OldBackColor;
inherited;
end;
procedure TRichDic.KeyPress(var Key: Char);
var
inici, Fi: integer;
PosIni, Llarc: integer;
begin
inici := 0;
if Key = #32 then begin
if Length(Paraula) > 0 then begin
Fi := selStart;
Llarc := Length(Paraula);
inici := Fi - Llarc;
ComprovarParaula(Llarc, inici, Fi);
Paraula := '';
Llarc := 0;
end;
end
else begin
if (Key > #64) and (Key < #142) then begin
Paraula := Paraula + Key;
Inc(Llarc);
end;
if (Key = #8) then begin
Paraula := '';
PosIni := selStart;
while text[selStart] <> ' ' do begin
Paraula := text[selStart] + Paraula;
selStart := selStart - 1;
end;
selStart := PosIni;
end;
end;
end;
procedure TRichDic.Click;
begin
inherited;
Aqui deberia crear el Panel
end;
procedure TRichDic.UpdateDics;
begin
with Hunspell do begin
ReadFolder(ExtractFilePath
('E:\RAD Studio\Projects\PRESSUPOSTOS\catalan.oxt'));
FDic := TStringList.Create;
FDic.AddObject('Diccionari', SpellDictionaries[0]);
SpellDictionaries[0].Active := True;
UpdateAndLoadDictionaries;
end;
end;
Muchas gracias