Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi version 1

Posted on 2000-04-06
10
Medium Priority
?
1,671 Views
Last Modified: 2012-06-21
Hi

Please could somebody who has Delphi 1 installed tell me the result of the following code.  Delphi 2 would be a bonus too!!

(The reason I ask is that I suspect that either the code won't run in Delphi 1 or the result will be different from versions 4 and 5.)

procedure TestSomething;
var
  B1: Boolean;
  B2: WordBool;
begin
  B1 := True;
  B2 := True;
  if (B1 = B2) then
  begin
    ShowMessage ('B1 = B2');
    if (Integer(B1) = Integer(B2)) then
      ShowMessage('Integer(B1) = Integer(B2)')
    else
      ShowMessage('Integer(B1) <> Integer(B2)');
  end
  else
    ShowMessage('B1 <> B2');
end;

Thanks,
JimBob
0
Comment
Question by:JimBob091197
  • 5
  • 5
10 Comments
 

Expert Comment

by:sarc
ID: 2689970
Hi!

It's right! In Delphi 5 you get the TRUE path ;-) in both ways, at Delphi1 Integer(B1)<>Integer(B2).

If you read the Delphi-Help you will find that they recommend not to do type conversion on boolean variables. (Try to use the "normal" way - see helpfile at "BOOLSHORT").
(remember - you are converting ONE byte into TWO(D1)/Four(D5) bytes.)!!!
0
 
LVL 5

Author Comment

by:JimBob091197
ID: 2692363
Wrong, in Delphi 5 you get the following:
  B1 = B2
  Integer(B1) <> Integer(B2)

This is because Delphi 3, 4 and 5 store LongBool, WordBool and ByteBool as -1 when you set them to True, but Boolean is stored as 1 when set to True.

I think Delphi 1 (and 2???) store LongBool, etc. as 1 (not -1) when True.

Did you try the code in Delphi 1?

JB
0
 
LVL 5

Author Comment

by:JimBob091197
ID: 2692373
P.S.  That is why I think that Delphi 1 (and 2?) will either not compile (i.e. don't have WordBool declared) or will produce the following:

B1 = B2  (i.e. True = True)
Integer(B1) = Integer(B2)   (i.e. 1 = 1)

JB
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:sarc
ID: 2692678
Hi!

I didn't have much time to test it yesterday, but JimBob is right! D1 AND D5 store boolean values as 1, but D1 stores Long/Byte/Wordbools as -1. Sorry - I can't find my old D2-CD so I can't test it there.
But it definitely compiles under D1 and runs.
0
 
LVL 5

Author Comment

by:JimBob091197
ID: 2692759
D5 also stores Long/Byte/WordBools as -1, but I think D1 stores them as +1.

When you get a chance to compile it in Delphi 1, please confirm the exact responses that Delphi 1 gives.

I think Delphi 1 should give the following:
B1 = B2
AND
Int(B1) = Int(B2)

Thanks,
JB
0
 

Expert Comment

by:sarc
ID: 2692813
As I said, I tested it today and the results are:

D1 (boolean): Integer(true) = 1
D1 (wordbool): Integer(true) = 1

D3 (boolean):integer = 1
D3 (wordbool): integer = -1 !!!

D5 (boolean):integer = 1
D5 (wordbool): integer = -1 !!!

The type conversion of D5 works very fine...

The testfunction was:
functionname......
var
  b : boolean/wordbool;
begin
  b:=true;
  ShowMessage( inttostr ( integer (b) ) );
end;

hmmm... if you really need the conversion - and want to make shure all Versions handle it the same way.... why not use  abs(x) - not the fastest and finest way - but it works ;-)

greetz
Carsten
0
 

Expert Comment

by:sarc
ID: 2692818
Ah, by the way:

NOW I see what JimBob meant with WRONG:

["It's right! In Delphi 5 you get the TRUE path ;-) in both ways, at Delphi1 Integer(B1)<>Integer(B2). "]

Hups... It was the other way round.... (oh, oh - two hours of sleep where not enogh) ;-)
0
 
LVL 5

Author Comment

by:JimBob091197
ID: 2693103
> "It's right! In Delphi 5 you get the TRUE path ;-) in both ways, at Delphi1 Integer(B1)<>Integer(B2). "

Thanks - that's what I needed to know.  As far as I remember, D2 is the same as D1.  The change came in with D3 to make it compatible with Microsoft products (VB stores True as -1) because of COM requirements, etc...

Thanks - please answer the Q again...

JB
0
 

Accepted Solution

by:
sarc earned 100 total points
ID: 2693271
;-)

Okay - here the summary - just for the ones who don't want to read through the whole question history:

At Delphi1 Boolean AND WordBool use integer "1" as TRUE,
Delphi 3+ uses "-1" for Word/Byte/LongBool but stilll "1" for Boolean.

If you use the testfunction:

functionname......
var
  b : boolean/wordbool;
begin
  b:=true;
  ShowMessage( inttostr ( integer (b) ) );
end;

you get the following results:

D1 (boolean): Integer(true) = 1
D1 (wordbool): Integer(true) = 1

D3 (boolean):integer = 1
D3 (wordbool): integer = -1 !!!
D5 (boolean):integer = 1
D5 (wordbool): integer = -1 !!!

The type conversion of D5 works very fine...


greetz
Carsten
0
 
LVL 5

Author Comment

by:JimBob091197
ID: 2693581
Thanks.
JB
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question