Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Componente Memo Com Texto Justificado


Guest carlinhosprog
 Share

Question

1 answer to this question

Recommended Posts

  • 0

Função para alinhar texto em um memo

function StrPad(AValue: String; const ALength: Integer; const ASide: TAlignment): String;
begin
   AValue := Trim(AValue);
   if Length(AValue) > ALength then
      AValue := Copy(AValue,1,ALength);
   case ASide of
      taLeftJustify:
         while Length(AValue) < ALength do AValue := AValue + ' ';
      taRightJustify:
         while Length(AValue) < ALength do AValue := ' ' + AValue;
      taCenter:
         while Length(AValue) < ALength do if (Length(AValue) mod 2)= 0 then
            AValue := AValue + ' ' else AValue := ' ' + AValue;
   end;
   Result := AValue;
end;


// tamanho da linha = 80 caracteres 

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
   showmessage(inttostr(MEMO1.LINES.Count));
   for i := 1 to MEMO1.LINES.Count do
      begin
         if Length(MEMO1.LINES.Strings[i]) < 80 then 
            MEMO2.LINES.Append(StrPad(MEMO1.LINES.Strings[i],80,TACENTER))
         else
            begin
               MEMO2.LINES.Append(StrPad(MEMO1.LINES.Strings[i],80,TACENTER));
               MEMO2.LINES.Append(StrPad(copy(MEMO1.LINES.Strings[i],81,80),80,taLeftJustify));
            end;
      end;

end;

OBS: a fonte a ser utilizada deve ser a Courier ou Courier New ( os caracteres tem espaçamentos iguais )

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...