RE: [DUG]: Comparison of records

1999-04-09 Thread Chris Crowe

C, I remember having operator overloaded functions for = well == in C. Does D4 support 
this? I know it supports default parameters which is really cool. It seems to me that 
D4 is very close to the C language these days, but is still a bit behind 
(about 5 years).

It was really nice for structures as you could do

if (record1 == Record2)

Well I suppose you still had to do the compare routine, but it makes code a lot easier 
to write.


How about friend functions?, and one I really miss from c is:

Say name is a string

Captionm := (Name   '') ? 'Hello'+Name : 'You should enter a name'

it is like an IF THEN ELSE in a line. first the comparason, then the ? means if TRUE 
and the : means ELSE

So you could save a lot of typing if you wanted say 4 or 5 checks in one line of code.


Chris

Christopher Crowe (Software Developer)
Microsoft MVP, MCP

Adrock Software
Byte Computer  Software LTD
P.O Box 13-155 
Christchurch
New Zealand
Phone/Fax (NZ) 03-3651-112


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
 Behalf Of YanboL
 Sent: Thursday, 8 April 1999 15:54
 To: Multiple recipients of list delphi
 Subject: RE: [DUG]: Comparison of records
 
 
 It's a typical Pascal concept, same as C.
 
 Suppose the record type has a TYourObject field,  TYourObject in the two 
 records reference the same date area. How can you expect the compiler to 
 compile "=".
 
 If you really want to compare records, you have to define you own 
 function 
 or method.
 
 Cheers
 
 -Original Message-
 From: Phil Scadden [SMTP:[EMAIL PROTECTED]]
 Sent: Thursday, 8 April 1999 13:59
 To:   Multiple recipients of list delphi
 Subject:      Re: [DUG]:  Comparison of records
 
 
  This got to be a naive question, but I need an enlightenment either
  theoretical or practical. In the following code I tried to compare
  two record type variables which belong to the same record type:
 
 If the record contains strings, objects, pchars, etc. then its 
 did it hard 
 way
 as far as I know. Fixed size records of simple types (eg a common one for
 me is Record
  x,y:Double;
  end; )
 then you can try type Casting to fixed type for comparison.
 
 --
 Phil Scadden, Institute of Geological and Nuclear Sciences
 PO Box 30368, Lower Hutt, New Zealand
 Ph +64 4 5704821, fax +64 4 5704603
 --
 -
 New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
   Website: http://www.delphi.org.nz
 
 
 --
 -
 New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
   Website: http://www.delphi.org.nz
 

---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
  Website: http://www.delphi.org.nz



Re: [DUG]: Comparison of records

1999-04-09 Thread Aaron Scott-Boddendijk

C, I remember having operator overloaded functions for
= well == in C. Does D4 support this? I know it supports
default parameters which is really cool. It seems to me
that D4 is very close to the C language these days, but
is still a bit behind (about 5 years).
It was really nice for structures as you could do
if (record1 == Record2)

(You're actually referring to C++ a slightly different beast than
C).  It's not really an issue of who's behind but rather a design
decision and the Delphi team decided that they would not implement
operator overloading in the extended pascal syntax.  Originally
they also ruled out overloading of functions but this was the influence
of certain team members and changes in the team have resulted in
overloading being implemented.  There are areas of the Delphi
syntax which surpass C++ such as the property syntax allowing
expression assignment to have an event attached whereas in
C++ and java (java doesn't do op overloading either) both require
SetProperty(Value) to be used by the enduser.  Delphis properties
enable the user to not need to know the inner implementation
of the class only that it is a property as opposed to C++ where the
end user see Fields and methods not really encapsulated properties.

and one I really miss from c is:

Say name is a string
Captionm := (Name   '') ? 'Hello'+Name : 'You should enter a name'
it is like an IF THEN ELSE in a line. first the comparason, then the ?
means if TRUE and the : means ELSE
So you could save a lot of typing if you wanted say 4 or 5 checks in one
line of code.

First the bad news Delphi doesn't support this operator and most likely
never will.

Actually it's better than an IF THEN ELSE since it performs substitution
which can be a statement, variable or constant.  So this would have been

if Name'' then Captionm := 'Hello '+Name
else 'You should enter a name';

this would be even more obvious in something like

Showmessage('There '+((Count==1)?'is ':'are ')+IntToStr(Count)+'
item'+((Count==1)?' ':'s ')+'selected.');

producing either (assuming I didn't bollocks the code)
There is 1 item selected.
or
There are 4 items selected.

without needing an if statement and 2 complete showmessage statements. Note
that this is a simple
case because you could have a number of other twists... There are algorithms
in B-tree implementation
where you need to select one of two different pointer to pointers to pass
down a recursive add.   The
code in pseudo or pascal looks ugly next to Cs Tertiary operator.  Now if
there was a switch that could
perform substitution... ;)

there are a number of things I'd like to see in Delphi such as template
implementation and stronger
syntax support for Delphi set notations.  Stronger enumeration definition
would also be nice.

--
Aaron@home

---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
  Website: http://www.delphi.org.nz



Re: [DUG]: Comparison of records

1999-04-08 Thread Postmaster

 Try the following function:  (Good fast ASM function that has been around
 for a VERY long time).
 function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
 Eg.
 if CompareMem (@record1, @record2, sizeof (record1)) then
 This will only work provided the records do not have pointers to data or
 strings.

or have any datatypes which are not word aligned... Note that nonpacked
records
have padding bytes that are not initialised (or at least I don't believe you
can
trust them to be initialised)...

Thus byte fields or byte arrays would be out... Comments?

--
Aaron@home

---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
  Website: http://www.delphi.org.nz



RE: [DUG]: Comparison of records

1999-04-08 Thread Myles Penlington

If you initialised the records first using FillChar( ) it would work okay, then you 
know it's all unused areas are initialised.
Is there a better way than fillChar() these days??.
Myles.

-Original Message-
From:   Postmaster [SMTP:[EMAIL PROTECTED]]
Sent:   Thursday, April 08, 1999 10:48 PM
To: Multiple recipients of list delphi
Subject:Re: [DUG]:  Comparison of records

 Try the following function:  (Good fast ASM function that has been around
 for a VERY long time).
 function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
 Eg.
 if CompareMem (@record1, @record2, sizeof (record1)) then
 This will only work provided the records do not have pointers to data or
 strings.

or have any datatypes which are not word aligned... Note that nonpacked
records
have padding bytes that are not initialised (or at least I don't believe you
can
trust them to be initialised)...

Thus byte fields or byte arrays would be out... Comments?

--
Aaron@home

---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
  Website: http://www.delphi.org.nz
 application/ms-tnef


Re: [DUG]: Comparison of records

1999-04-07 Thread Aaron Scott-Boddendijk

This got to be a naive question, but I need an enlightenment either
theoretical or practical. In the following code I tried to compare 
two record type variables which belong to the same record type:


var record1, record2 : TRecordType;
if record1 = record2 then  
Is there a way to compare two records at once without check
each of its filed one by one?


I think Record assignment is permitted but I'm not so sure about
comparison... There are also issues about references since it won't
copy a referenced object only the reference itself.

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
  Website: http://www.delphi.org.nz



Re: [DUG]: Comparison of records

1999-04-07 Thread Phil Scadden


 This got to be a naive question, but I need an enlightenment either
 theoretical or practical. In the following code I tried to compare 
 two record type variables which belong to the same record type:

If the record contains strings, objects, pchars, etc. then its did it hard way
as far as I know. Fixed size records of simple types (eg a common one for
me is Record
 x,y:Double;
 end; )
then you can try type Casting to fixed type for comparison. 

--
Phil Scadden, Institute of Geological and Nuclear Sciences
PO Box 30368, Lower Hutt, New Zealand
Ph +64 4 5704821, fax +64 4 5704603
---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
  Website: http://www.delphi.org.nz