home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 January / Chip_1999-01_cd.bin / zkuste / delphi / D4 / MRECSORT.ZIP / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-09-15  |  1.8 KB  |  77 lines

  1. {+--------------------------------------------------------------------------+
  2.  | Created:     12.97
  3.  | Author:      Martin Waldenburg
  4.  | Copyright    1997, all rights reserved.
  5.  | Description: Demo for TmSor.
  6.  | Version:     1.0
  7.  | Status       FreeWare
  8.  | It's provided as is, without a warranty of any kind.
  9.  | You use it at your own risc.
  10.  | E-Mail me at Martin.Waldenburg@t-online.de
  11.  +--------------------------------------------------------------------------+}
  12.  
  13. unit Unit1;
  14.  
  15. interface
  16.  
  17. uses
  18.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  19.   StdCtrls, mwFixedRecSort, mwFastTime, mwCompFrom;
  20.  
  21. type
  22.   PDemoData=^TDemoData;
  23.   TDemoData=record
  24.     Data1: String[50];
  25.     Data2: String[210];
  26.     Data3: String[237];
  27.   end;
  28.  
  29.   TForm1=class(TForm)
  30.     Button1: TButton;
  31.     OpenDialog1: TOpenDialog;
  32.     Time1: TmwFastTime;
  33.     Edit1: TEdit;
  34.     procedure Button1Click(Sender: TObject);
  35.   private
  36.     { Private-Deklarationen }
  37.   public
  38.     { Public-Deklarationen }
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.  
  44. implementation
  45.  
  46. {$R *.DFM}
  47.  
  48. function Compare(Item1, Item2: Pointer): Integer;
  49. begin
  50.   Result:=CompareTextFrom(Item1, Item2, 2, 50);
  51.  
  52.    {Result:= CompareText(PDemoData(Item1)^.Data1, PDemoData(Item2)^.Data1);
  53.     The same as above, more comfortable but slower.
  54.     A typecast can cost lots of time.
  55.     However, for large amounts of Records (Millions) Windows file buffering system
  56.     will equalize this..}
  57. end;
  58.  
  59. procedure TForm1.Button1Click(Sender: TObject);
  60. var
  61.   Sorter: TFixRecSort;
  62. begin
  63.   if OpenDialog1.Execute then
  64.   begin
  65.     Time1.Start;
  66.     Sorter:=TFixRecSort.Create(500);
  67.     Sorter.Stable:=True;
  68.     Sorter.Start(OpenDialog1.FileName, 'aSorTest.out', Compare);
  69.     Time1.Stop;
  70.     Edit1.Text:=Time1.ElapsedTime;
  71.     Sorter.Free;
  72.   end;
  73. end;
  74.  
  75. end.
  76.  
  77.