unit Form.Main;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 =
class( TForm )
ToolBar1: TToolBar;
Text1: TText;
Label1: TLabel;
procedure FormCreate( Sender: TObject );
private
procedure MeasureTextControl( AText: TText );
procedure QueueMeasureTextControl( AText: TText );
procedure DontDoMeasureTextControl( AText: TText );
public
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{ TForm1 }
procedure TForm1.FormCreate( Sender: TObject );
begin
Text1.Align := TAlignLayout.Client;
// funktioniert
// MeasureTextControl( Text1 );
// funktioniert - Best Practice
QueueMeasureTextControl( Text1 );
// Fehlerhafte Darstellung
// DontDoMeasureTextControl( Text1 );
end;
procedure TForm1.DontDoMeasureTextControl( AText: TText );
begin
Application.ProcessMessages;
MeasureTextControl( AText );
end;
procedure TForm1.MeasureTextControl( AText: TText );
begin
Label1.Text := AText.Width.ToString;
end;
procedure TForm1.QueueMeasureTextControl( AText: TText );
begin
TThread.Queue(
nil,
procedure
begin
MeasureTextControl( AText );
end );
end;
end.