Solved

Delphi version 1

Posted on 2000-04-06
10
1,619 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now