Jak odczytać czy cos pisane jest indeksem górnym czy doln

0

Jak odczytać z RichEdita czy tekst jest normalnie napisany czy znajduje sie w Indeksie górnym czy dolnym. Chciałbym wyświetlać jak klikne na tekst ze jest to indeks górny lub dolny i przciski sa wciśniete lub oba wycisniete gdy jest to normalnie pisane.

// po co dwa posty na jeden temat? - detox

0

Musisz skorzystać z typu TCharFormat2 zdefiniowanego w unicie RichEdit i pobrać z effect elementy CFE_SUBSCRIPT i CFE_SUPERSCRIPT.
Możesz to zrobić np. w sposób

TRichEdit2=class;

TTextAttributes2= class(TPersistent)
private
RichEdit: TRichEdit2;
function GetSubscript: Boolean;
function GetSuperscript: Boolean;
procedure SetSubscript(Value: Boolean);
procedure SetSuperscript(Value: Boolean);
procedure InitFormat2(var Format2: TCharFormat2);
public
constructor Create(AOwner: TRichEdit2);
procedure GetAttributes2(var Format2: TCharFormat2);
procedure SetAttributes2(var Format2: TCharFormat2);
property Subscript: Boolean read GetSubscript write SetSubscript;
property Superscript: Boolean read GetSuperscript write SetSuperscript;
end;

TRichEdit2 = class(TRichEdit)
private
FFormat2:TTextAttributes2;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

  property Format2: TTextAttributes2 read FFormat2;

end;

{ TTextAttributes2 }

constructor TTextAttributes2.Create(AOwner:TRichEdit2);
begin
inherited Create;
RichEdit:=AOwner;
end;

function TTextAttributes2.GetSubscript: Boolean;
var Format2:TCharFormat2;
begin
GetAttributes2(Format2);
Result:=(Format2.dwEffects and CFE_SUBSCRIPT)<>0;
end;

procedure TTextAttributes2.SetSubscript(Value: Boolean);
var Format2: TCharFormat2;
begin
InitFormat2(Format2);
Format2.dwMask:=CFM_SUBSCRIPT;
if Value then Format2.dwEffects:=CFE_SUBSCRIPT;
SetAttributes2(Format2);
end;

function TTextAttributes2.GetSuperscript: Boolean;
var Format2:TCharFormat2;
begin
GetAttributes2(Format2);
Result:=(Format2.dwEffects and CFE_SUPERSCRIPT)<>0;
end;

procedure TTextAttributes2.SetSuperscript(Value: Boolean);
var Format2: TCharFormat2;
begin
InitFormat2(Format2);
Format2.dwMask:=CFM_SUPERSCRIPT;
if Value then Format2.dwEffects:=CFE_SUPERSCRIPT;
SetAttributes2(Format2);
end;

procedure TTextAttributes2.InitFormat2(var Format2: TCharFormat2);
begin
FillChar(Format2, SizeOf(TCharFormat2), 0);
Format2.cbSize := SizeOf(TCharFormat2);
end;

procedure TTextAttributes2.GetAttributes2(var Format2: TCharFormat2);
begin
InitFormat2(Format2);
if RichEdit.HandleAllocated then
SendMessage(RichEdit.Handle, EM_GETCHARFORMAT, SCF_SELECTION, LPARAM(@Format2));
end;

procedure TTextAttributes2.SetAttributes2(var Format2: TCharFormat2);
begin
RichEdit.HandleNeeded;
if RichEdit.HandleAllocated then
SendMessage(RichEdit.Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(@Format2));
end;

{ TRichEdit2 }

constructor TRichEdit2.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FFormat2:=TTextAttributes2.Create(Self);
end;

destructor TRichEdit2.Destroy;
begin
FFormat2.Free;
inherited Destroy;
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1