Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Stange results with TTime variables


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 15 - Last Post: Mar 29, 2016 4:57 PM Last Post By: Quentin Correll
pss edn

Posts: 45
Registered: 1/13/04
Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 1:33 AM
Using XE7.
After spending some time and google searching, I can not get working TTime/TDateTime variables.

Using this small piece of code in a debugging session I allways get 0 in the resulting asignments in the Local Variables pane.
That is, for tm I get 0:00:00, and for dttm 30/12/1899

uses
System.DateUtils

var
tm: TTime;
dttm: TDateTime;

begin
tm := Time;
dttm := Time;
dttm := Date;
dttm := Now;
end;

How can I get this working.
Arnaud BOUCHEZ

Posts: 143
Registered: 2/17/02
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 2:05 AM   in response to: pss edn in response to: pss edn
pss edn wrote:
Using this small piece of code in a debugging session I allways get 0 in the resulting asignments in the Local Variables pane.

The variables are not used later on, so the compiler optimize the code to NOT store anything in the local variable.
I guess there are compiler hints message... trust them!
Arnaud BOUCHEZ

Posts: 143
Registered: 2/17/02
Re: Stange results with TTime variables
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 2:54 AM   in response to: Arnaud BOUCHEZ in response to: Arnaud BOUCHEZ
Arnaud BOUCHEZ wrote:
The variables are not used later on, so the compiler optimize the code to NOT store anything in the local variable.

Just use the variable:

begin
tm := Time;
writeln(tm);
dttm := Time;
writeln(dttm);
dttm := Date;
writeln(dttm);
dttm := Now;
writeln(dttm);
end;


And I guess you will see the point.
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 2:32 AM   in response to: pss edn in response to: pss edn
How can I get this working.

This is strange because you don't see an optimization message behind your var's in the local var pane..
Did you put the breakpoint on the "tm := Time;" line and when it breaks you step with F8 through the lines?
pss edn

Posts: 45
Registered: 1/13/04
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 3:57 AM   in response to: pss edn in response to: pss edn
As Arnaud points, the reason is that there is a linker optimization action over the variable.

Trying to solve it using the following code, I go into another problem:

Using IncMinute, now the linker does not optimize, and tm shows the actual time, but the IncMinute line does not increment anything.

And this occurs in both TTime variable and TDateTime variable.

var
tm: TTime;
dttm: TDateTime;

tm := Time;
tm:= IncMinute(tm, 10);

dttm := Time;
dttm:= IncMinute(dttm, 10);

Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 4:10 AM   in response to: pss edn in response to: pss edn
pss edn wrote:
As Arnaud points, the reason is that there is a linker optimization action over the variable.

Trying to solve it using the following code, I go into another problem:

Using IncMinute, now the linker does not optimize, and tm shows the actual time, but the IncMinute line does not increment anything.

And this occurs in both TTime variable and TDateTime variable.

var
tm: TTime;
dttm: TDateTime;

tm := Time;
tm:= IncMinute(tm, 10);

dttm := Time;
dttm:= IncMinute(dttm, 10);


same problem the var are not being used after th1e assignment
  tm := Time;
  tm:= IncMinute(tm, 10);
  tm:= IncMinute(tm, 10);
  tm:= IncMinute(tm, 10);
  tm:= IncMinute(tm, 10);
  tm:= IncMinute(tm, 10);
  tm:= IncMinute(tm, 10);
  tm:= IncMinute(tm, 10);

--Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Arnaud BOUCHEZ

Posts: 143
Registered: 2/17/02
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2016 4:29 AM   in response to: Linden ROTH in response to: Linden ROTH
Linden ROTH wrote:
same problem the var are not being used after th1e assignment

Why is this is a "problem"?
This is IMHO a feature, and a very welcome feature of the compiler, to avoid code generation for pointless operations, like assignment to a non-used variable.

Your expectations are wrong, I'm afraid.
The compiler does its job here - like any other optimized compiler in the wild!
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2016 11:49 PM   in response to: Arnaud BOUCHEZ in response to: Arnaud BOUCHEZ
Arnaud BOUCHEZ wrote:
Linden ROTH wrote:
same problem the var are not being used after th1e assignment

Why is this is a "problem"?
This is IMHO a feature, and a very welcome feature of the compiler, to avoid code generation for pointless operations, like assignment to a non-used variable.

Your expectations are wrong, I'm afraid.
The compiler does its job here - like any other optimized compiler in the wild!

Never said it was not a good thing just that was why he couldn't see a change

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
pss edn

Posts: 45
Registered: 1/13/04
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 25, 2016 11:15 AM   in response to: pss edn in response to: pss edn
Solved the problem with a combination of other instructions to make the linker not to optimize.
It could be helpful to have some inline linker directive to tell not to optimize a zone of code
In my case, I suspect that the linker does not go further to know what is happening inside my code.
The schematic of my full code is something like that

with (Planner.Items.Add) do
begin
StartTime := mclsVisD.tArrVisitas[iK].tHour;
.../...
end;

And in other routines, I am using StartTime initialized with this code.

mclsVisD is a normal class and tArrVisitas is a member of this clas: it is an array of another simple class like a record.
The array is defined as TObjectList<TVisita>
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 26, 2016 1:23 AM   in response to: pss edn in response to: pss edn
Am 25.03.2016 um 19:15 schrieb pss edn:
Solved the problem with a combination of other instructions to make the linker not to optimize.
It could be helpful to have some inline linker directive to tell not to optimize a zone of code
In my case, I suspect that the linker does not go further to know what is happening inside my code.
The schematic of my full code is something like that

with (Planner.Items.Add) do
begin
StartTime := mclsVisD.tArrVisitas[iK].tHour;
.../...
end;

And in other routines, I am using StartTime initialized with this code.

mclsVisD is a normal class and tArrVisitas is a member of this clas: it is an array of another simple class like a record.
The array is defined as TObjectList<TVisita>

Hello,

a small hint (even if this group is not about source code normally): get
rid of your width's. ;-)

Greetings

Markus
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 26, 2016 1:30 PM   in response to: Markus Humm in response to: Markus Humm
Markus,

| a small hint (even if this group is not about source code normally):
| get rid of your width's. ;-)

...with's... (?)

--

Q -- XanaNews 1.19.1.372 - 2016-03-26 13:29:04
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 27, 2016 8:56 AM   in response to: Quentin Correll in response to: Quentin Correll
Am 26.03.2016 um 21:30 schrieb Quentin Correll:
Markus,

| a small hint (even if this group is not about source code normally):
| get rid of your width's. ;-)

...with's... (?)

Oops! Sure Quentin, your're right. ;-)

Greetings

Markus
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2016 10:51 AM   in response to: Markus Humm in response to: Markus Humm
Markus,

| | ...with's... (?)
| |

| Oops! Sure Quentin, your're right. ;-)

Cool. <g>

--

Q -- XanaNews 1.19.1.372 - 2016-03-28 10:51:35
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 28, 2016 11:47 PM   in response to: Quentin Correll in response to: Quentin Correll
Quentin Correll wrote:

Markus,

a small hint (even if this group is not about source code
normally): get rid of your width's. ;-)

...with's... (?)

But I would like to get rid of some of my width. <g>

--
Rudy Velthuis http://www.rvelthuis.de

"Woman was God's second mistake."
-- Friedrich Nietzsche (1844-1900)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2016 9:04 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Am 29.03.2016 um 08:47 schrieb Rudy Velthuis (TeamB):
Quentin Correll wrote:

Markus,

a small hint (even if this group is not about source code
normally): get rid of your width's. ;-)

...with's... (?)

But I would like to get rid of some of my width. <g>

Hm, now that's a thing the proposed new refactoring "remove withs" I
recently proposed cannot fullfill, even if EMBT finally provides such a
refactoring ;-)

Greetings

Markus
Quentin Correll


Posts: 2,412
Registered: 12/1/99
Re: Stange results with TTime variables  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 29, 2016 4:57 PM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy,

| But I would like to get rid of some of my width. <g>

<chuckle>

--

Q -- XanaNews 1.19.1.372 - 2016-03-29 16:57:47
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02