The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



ExChange


Unit:SDL_math1
Class:None
Declaration: [1] procedure ExChange (var x,y; size: word);
[2] procedure ExChange (var x,y: integer);
[3] procedure ExChange (var x,y: byte);
[4] procedure ExChange (var x,y: word);
[5] procedure ExChange (var x,y: single);
[6] procedure ExChange (var x,y: double);
[7] procedure ExChange (var x,y: extended);
[8] procedure ExChange (var x,y: string);
[9] procedure ExChange (var x,y: char);
[10] procedure ExChange (var x,y: AnsiChar);
[11] procedure ExChange (var x,y: ShortInt);
[12] procedure ExChange (var x,y: Cardinal);
[13] procedure ExChange (var x,y: Int64);
[14] procedure ExChange (var x,y: UInt64);
[15] procedure ExChange (var x,y: integer);

The procedure ExChange exchanges the values of two variables. The variables can be of any simple type.

There is one special overloaded version [1] which is only available for Win32 but not for .NET; it uses a byte buffer of arbitrary length to exchange any kind of structure, e.g. records. The only requirement for a successful utilization of version [1] of ExChange is that the variables x and y are of the same size. The parameter size specifies the size of the two variables in bytes. The best way to determine the size of the variables is to use the Delphi function SizeOf.

Hint: The variables x and y can be of different types as long as the size of them is equal. The following example shows an application of this case.

Example: The sample code below shows the utilization of the procedure ExChange for the dissection of a floating point number into single bytes. The same result could be obtained by an absolute declaration of two variables sharing the same address.

var
  r  : double;
  bf : array[1..sizeof(r)] of byte;

...
Exchange (r,bf,sizeof(r));
           { now the byte array bf contains the floating
             point number r, represented by 8 bytes }
...



Last Update: 2023-Feb-06