- Offizieller Beitrag
Re: How to auto-capitalize first char of new sentence
This code uses the BeforeInitializePar. It expects the start of a sentence at the start of the paragraph and after .?! + space.
The line
if WPRichText1.ActiveParagraph = par then
avoids that the complete text is updated after loading.
Code
procedure TForm1.WPRichText1BeforeInitializePar(Sender: TObject;
RTFEngine: TWPRTFEngineBasis; RTFDataBlock: TWPRTFDataBlock;
par: TParagraph);
var i : Integer;
sentenceend1,sentenceend2 : Boolean;
begin
sentenceend1 := TRUE;
sentenceend2:= TRUE;
if WPRichText1.ActiveParagraph = par then // Only when working with cursor paragraph!
for i:=0 to par.CharCount-1 do
begin
if par.ANSIChr[i] in ['a'..'z'] then
begin
if (sentenceend1=true) and (sentenceend2=true) then
begin
par.CharItem[i] := WideChar(Integer(par.CharItem[i]) - 32);
end;
sentenceend1 := FALSE;
sentenceend2 := FALSE;
end else if par.ANSIChr[i] in ['.','!','?'] then
begin
sentenceend1 := TRUE;
sentenceend2 := FALSE;
end else
if par.ANSIChr[i] in [#32,#9] then
begin
if sentenceend1 then
sentenceend2 := TRUE;
end
else
begin
sentenceend1 := FALSE;
sentenceend2 := FALSE;
end;
end;
end;
Alles anzeigen