DataLab is a compact statistics package aiming at exploratory data analysis. Please visit the DataLab Web site for more information....


OnSortExchange (Vector)

Declaration: TVector.OnSortExchange: TSortExchgEvent;
{ TSortExchgEvent = procedure (Sender: TObject; ExchgWhat: byte; index1, index2, first, last: longint); }
The OnSortExchange property specifies which event handler should be executed when two vector elements are exchanged during the sorting process. An OnSortExchange event is triggered after two elements have been exchanged during a sorting process.

The ExchgWhat parameter specifies whether vector elements ( = 0), matrix columns ( = 1) or matrix rows ( = 2) are exchanged. The parameters index1 and index2 define the indices of the elements to be exchanged. The parameters first and last are always zero in the case of the class TVector.

Example: The following program counts the number of exchanges which occur during the sorting process. The program first copies the first column of the data into the vector MyVec and then starts the sorting process. During the sorting the variable cnt is increased every time two cells of the vector are exchanged. Finally the count is displayed.
program CountSortOperations;

var
  MyVec : TVector;
  cnt   : integer;

procedure MyVecSortExchange (Sender: TObject; ExchgWhat: byte; index1, index2, first, last: longint);

begin
inc(cnt);
end;

begin
cnt := 0;
MyVec := TVector.Create(nil);
DSTore.CopyDataColToVector (MyVec, 1, 0, 0, 1);
MyVec.OnSortExchange := @MyVecSortExchange;
MyVec.SortElems (true, 0, 0);
cout ('Number of Exchanges: ', cnt);
MyVec.Free;
end.