Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Reto: Justificar un TRichEdit (https://www.clubdelphi.com/foros/showthread.php?t=82560)

darkamerico 19-03-2013 15:09:39

Reto: Justificar un TRichEdit
 
Saludos mis amigos, este es un problema recurrente que tengo haec tiempo y quizas de muchos de ustedes, propongo solucionarlo de una vez por todas, estuve investigando y encontre esta funcion, sin embargo, al parecer tiene un error:

Código Delphi [-]
function Justifica(mCad:string;mMAx:integer):string;
var
mPos,mPont,mTam,mNr,mCont :integer;
mStr : string;

begin
  mTam:=Length(mCad);
  if mTam>=mMax then
  Result:=copy(mCad,1,mMax)
  else
  begin
    mStr:='''';
    mCont:=0;
    mPont:=1;
    mNr:=mMax-mTam;
  end;

  while mCont mPos
    mPos:=pos(mStr,copy(mCad,mPont,100));
    if mPos=0 then
    begin
      mStr:=mStr+' ';
      mPont:=1;
      continue;
    end
    else
    begin
      mCont:=mCont+1;
      Insert(' ',mCad,mPos+mPont);
      mPont:=mPont+mPos+length(mStr);
    end;
  Result:=mCad;
end;

Si alguien tiene una funcion que haga el trabajo, por favor comparta el codigo aqui.


Muchos saludos

darkamerico 19-03-2013 15:31:36

Solucion
 
Encontre esta funcion que realiza el trabajo.

Código Delphi [-]
procedure JustifyRichText(RichEdit :TRxRichEdit; AllText :Boolean);
const
  TO_ADVANCEDTYPOGRAPHY = $1;
  EM_SETTYPOGRAPHYOPTIONS = (WM_USER + 202);
  EM_GETTYPOGRAPHYOPTIONS = (WM_USER + 203);
var
  ParaFormat :TParaFormat;
  SelStart,SelLength :Integer;
begin
  ParaFormat.cbSize := SizeOf(ParaFormat);
  if SendMessage(RichEdit.handle,EM_SETTYPOGRAPHYOPTIONS,TO_ADVANCEDTYPOGRAPHY,TO_ADVANCEDTYPOGRAPHY) = 1 then
  begin
    SelStart := RichEdit.SelStart;
    SelLength := RichEdit.SelLength;
    if AllText then
      RichEdit.SelectAll;
      ParaFormat.dwMask := PFM_ALIGNMENT;
      ParaFormat.wAlignment := PFA_JUSTIFY;
      SendMessage(RichEdit.handle, EM_SETPARAFORMAT, 0, LongInt(@ParaFormat));
      RichEdit.SelStart := SelStart;
      RichEdit.SelLength := SelLength;
  end;
end;

Espero que sea de utilidad para ustedes.

Atte
Americo

ecfisa 19-03-2013 17:51:21

Cita:

Empezado por darkamerico (Mensaje 457074)
Encontre esta funcion que realiza el trabajo.
...
Espero que sea de utilidad para ustedes.

Atte
Americo

Hola darkamerico.

Gracias por compartirla con nosotros.

Saludos. :)


La franja horaria es GMT +2. Ahora son las 05:00:48.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi