I currently face the problem of not being able to divide my ClientWidth by 2 (or multiply with 0.5 because of the error message Delphi is giving me:
[Error] Unit1.pas(59): Incompatible types: 'Integer' and 'Extended'
[Error] Unit1.pas(60): Incompatible types: 'Integer' and 'Extended'
[Error] Unit1.pas(61): Incompatible types: 'Integer' and 'Extended'
procedure TForm1.FormResize(Sender: TObject);
begin
// responsive design
with form1 do begin
cmdFakultat.left:=0.5*ClientWidth-60;
txtEingabe.left:=0.5*ClientWidth-60;
lblAusgabe.left:=0.5*ClientWidth-60;
end;
end;
end.
Use the Trunc
or Round
functions, depending on your desired behavior, like this...
lblAusgabe.left := Trunc(0.5 * ClientWidth) - 60;
or
lblAusgabe.left := Round(0.5 * ClientWidth) - 60;
This cuts everything off after the decimal, leaving just an Integer
type as a result.
As an alternative, you could also use div
to accomplish this, which is a bit more straight-forward and does this conversion for you...
lblAusgabe.left := (ClientWidth div 2) - 60;