in other PL
we can declare const
Test = 'my test '+inc(someVar)+' is work';
how to simulate this in delphi?
my delphi example may be like that:
const
Msg = 'some todo-Tasks will Start in [ '+Timer1.Tag.ToString+' ] Seconds.';
in other PL
we can declare const
Test = 'my test '+inc(someVar)+' is work';
how to simulate this in delphi?
my delphi example may be like that:
const
Msg = 'some todo-Tasks will Start in [ '+Timer1.Tag.ToString+' ] Seconds.';
In modern versions of Delphi, this can be achieved by means of inline variable (and constant) declarations:
begin
// code
const Msg = 'Some text ' + (a + b).ToString + '.';
// more code...
Classical (non-inline) Delphi constant declarations cannot contain non-constant expressions; they are evaluated at compile time. An inline constant declaration like the one above, on the other hand, is executed at runtime as a statement. The RHS can be any valid expression. You can think of this as declaring a read-only variable with local scope and the statement being an ordinary variable assignment.
implementation const UserName = InputBox('Enter your name'); procedure Greet; begin ShowMessageFmt('Welcome, %s!', [UserName]); end; ...
. When exactly would the input box be shown? Every time you invoke Greet
? At the first invocation of Greet
? At unit initialization?
May 14 at 9:17
const msg = 'some todo-Tasks will start in %d seconds.';
then in your code you useFormat(Msg,[Time1.Tag]);
to return the string with the seconds filled in.