- Offizieller Beitrag
ZitatI have some inputeditfields in my document. Cursor walks from field to field by using tab key. I would like to select the actual *content* of the fields in the moment they get the focus. No problem so far - but my field limiters get selected too. I would like to select *only* the content of the field so that I can delete it but leave the field itself and its limiters unselected in the document. Any hints?
This functionality requires an delayed selection of the field since after the EditFiedFocus event was triggered the selection is usually cleared.
Please add to your interface section:
Code
const WM_SELECTFIELDATCP = WM_USER + 100;TForm1 = class(TForm)protectedprocedure WMSelectFieldAtCP(var Message : TMessage); message WM_SELECTFIELDATCP; end;
Then add this procedure and an event handler for the WPRichText OnEditFieldFocus event:
Code
procedure TForm1.WMSelectFieldAtCP(var Message : TMessage);
var p,l : Integer;
begin
while WPRichText1.CPChar^<>WPEditFieldStart do
if not WPRichText1.CPMoveBack then break;
p := WPRichText1.CPPosition;
l := 0;
while WPRichText1.CPChar^<>WPEditFieldEnd do
begin
if not WPRichText1.CPMoveNext then break;
inc(l);
end;
WPRichText1.CPPosition := p+1;
WPRichText1.SelStart := p+1;
WPRichText1.SelLength := l-1;
end;
procedure TForm1.WPRichText1EditFieldFocus(Sender: TObject;
const InspName: String; iTag: Integer; Enter: Boolean;
var Abort: Boolean);
begin
if Enter then
begin
PostMessage(Handle, WM_SELECTFIELDATCP,0,0);
end;
end;
Alles anzeigen