Here's one way to do it:
unit mainJustified;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, Graphics, StdCtrls, types;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var r: TRect;
s: string = 'this string is long enough to test';
sz: TSize;
topLeft: integer = 30;
ts: TTextStyle;
begin
sz:= Canvas.TextExtent(s);
r := Rect(topLeft, topLeft, topLeft+sz.cx, topLeft+sz.cy);
ts.SingleLine:=True;
ts.SystemFont:=True;
Canvas.TextRect(r, 0, 0, s, ts);
canvas.Frame(r);
end;
end.