Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread +1 = 0
Tue, Sep 29 2015 7:31 AMPermanent Link

Michael Dreher

Hi,
I get unexpected results using "+" or "-" as unary prefix operatoras in numeric literals.
Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
 Label1.Caption := 'test123'; // this is only to find the function in the JavaScript output
 Label1.Caption := IntToStr(1);     // prints 1 to label
 Label1.Caption := IntToStr(-1);    // prints -1 to label
 Label1.Caption := IntToStr(+1);    // prints 0  to label   (since the subject of this thread)
 Label1.Caption := IntToStr(-(-1)); // prints 0  to label
 Label1.Caption := IntToStr(+(-1)); // prints 0  to label   
end;   

Since I get no compiler error, the + and - signs should be valid.
In the help (Operators) both "+" , "-" operators are only listed as binary infix.

The JavaScript output:

unit1_tform1.$p.tform1_button1click = function(sender)
{
  var $t = this;
  $t.tform1_label1.tlabelcontrol_setcaption("test123");
  $t.tform1_label1.tlabelcontrol_setcaption(inttostr(1));
  $t.tform1_label1.tlabelcontrol_setcaption(inttostr(-1));
  $t.tform1_label1.tlabelcontrol_setcaption(inttostr(0));
  $t.tform1_label1.tlabelcontrol_setcaption(inttostr(0));
  $t.tform1_label1.tlabelcontrol_setcaption(inttostr(0));
  $t.tform1_label1.tlabelcontrol_setcaption(inttostr(0));
};

Michael Dreher
Tue, Sep 29 2015 7:44 AMPermanent Link

Matthew Jones

Michael Dreher wrote:

> Since I get no compiler error, the + and - signs should be valid.

Not able to answer your question, but EWB2 fixes a few things around +
from what I've seen. I had a line of code that works in EWB 1 of:

 lblCount.Caption := + IntToStr(m_xCart.ProductCount) + ' items';

That failed to compile (correctly) in EWB 2. (There is a + at the start
of the rvalue).

It will be interesting to see what Tim says on this numeric instance.

--

Matthew Jones
Tue, Sep 29 2015 11:52 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

<< I get unexpected results using "+" or "-" as unary prefix operatoras in numeric literals. >>

It's a compiler emit bug.  A fix will be in 2.02.

Tim Young
Elevate Software
www.elevatesoft.com
Image