Solved

Delphi version 1

Posted on 2000-04-06
10
1,645 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month6 days, 10 hours left to enroll

634 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