Solved

Delphi version 1

Posted on 2000-04-06
10
1,626 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
Using idhttp to login to instagram 2 89
Delphi - replicating a form 8 74
Working with hours 3 57
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…
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 give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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