# Delphi version 1

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
LVL 5
Asked:
###### Who is Participating?

Improve company productivity with a Business Account.Sign Up

x

Commented:
;-)

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

Commented:
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

Author Commented:
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

Author Commented:
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

Commented:
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

Author Commented:
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

Commented:
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

Commented:
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

Author Commented:
> "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

Author Commented:
Thanks.
JB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Already a member? Login.

All Courses

From novice to tech pro — start learning today.