TMas.LoadHesh (FileName: String) ;//Завантаження контейнера з файлу
var tf: TextFile; s, si, Key: string; b, bf: Boolean; i: integer;
begin
b: = False;
AssignFile (tf, FileName);
Reset (tf);
while Not Eof (tf) do
begin
Readln (tf, s);
bf: = False;
si: ='';
for i: = 1 to Length (s) do
if s [i] <> '' then si: = si + s [i] else
if b = False then
begin
b: = True;
Key: = si;
Hesh: = TMas.Create (Key);
bf: = true;
si: ='';
end else
begin
if bf = False then
begin
bf: = True;
Key: = si;
end else
begin
Hesh.Add (SI, 0);
end;
si: ='';
end; {End For}
end; {end While}
CloseFile (tf);
end;
end.
Опис Demo-програми. br/>
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons, ExtCtrls, Menus, ComCtrls;
type
TForm1 = Class (TForm)
Panel1: TPanel;
OperationGroup: TRadioGroup;
Edit1: TEdit;
Inicial: TBitBtn;
CloseButton: TBitBtn;
StringGrid1: TStringGrid;
MainMenu1: TMainMenu;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
AddGroup: TRadioGroup;
N5: TMenuItem;
Save: TMenuItem;
Load: TMenuItem;
CloseMenu: TMenuItem;
StatusBar1: TStatusBar;
New: TMenuItem;
SavaBtn: TBitBtn;
LoadBtn: TBitBtn;
procedure FormActivate (Sender: TObject);
procedure CloseButtonClick (Sender: TObject);
procedure InicialClick (Sender: TObject);
procedure FormCreate (Sender: TObject);
procedure SaveClick (Sender: TObject);
procedure LoadClick (Sender: TObject);
procedure CloseMenuClick (Sender: TObject);
procedure NewClick (Sender: TObject);
procedure OperationGroupClick (Sender: TObject);
procedure SavaBtnClick (Sender: TObject);
procedure LoadBtnClick (Sender: TObject);
private
{ Private declarations}
public
{ Public declarations}
end;
var
Form1: TForm1;
Implementation
uses ClassHeshProg;
{$ R *. Dfm}
procedure Output;
var i, j: integer; Cur: TItem;
begin
for i: = 1 to 10 do
begin
j: = 1;
Hesh.Extract (i, Cur);
While Cur <> nil do
begin
form1.StringGrid1.Cells [i-1, j]: = Cur.GetKey;
Cur: = Cur.Getnext;
inc (j);
end;
end;
end;
procedure TForm1.FormActivate (Sender: TObject);
var i: integer;
begin
for i: = 1 to form1.StringGrid1.ColCount do
begin
form1.StringGrid1.Cols [i-1]. Add (inttostr (i));
end;
form1.StatusBar1.Panels.Add.Text: = 'Об'єктна реалізація HESH-пошуку. ';
form1.OperationGroup.ItemIndex: = 0;
form1.AddGroup.ItemIndex: = 1;
end;
procedure TForm1.CloseButtonClick (Sender: TObject);
begin
if MessageDlg ('Зберегти зміни?', MtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
SaveClick (Sender);
NewClick (Sender),
Close; end else
begin
Hesh.DeleteAll;
Close;
end;
end;
procedure TForm1.InicialClick (Sender: TObject);
var i, j, count: integer;
begin
if Hesh = nil then
begin
MessageDlg ('HESH-таблиця не створена. Створюю таблицю. ', MtError, [mbok], 1);
Hesh: = TMas.Create (''); end else
case OperationGroup.ItemIndex of
0: begin {Add}
If Edit1.Text ='' then MessageDlg ('Введіть значення!', MtError, [mbOK], 1) else
if AddGroup.ItemIndex = 0 then
begin {AddFirst}
j: = Hesh.Add (Edit1.Text, 0);
if j <> 0 then MessageDlg ('Конфлікт у комірці '+ Inttostr (j), MtInformation, [mbok], 1);
MessageDlg ('Ключ з значенням '+ Edit1.Text +' доданий. ', MtInformation, [mbok], 1);
end else
begin {AddLast}
j: = Hesh.Add (Edit1.Text, 1);
if j <> 0 then MessageDlg ('Конфлікт у комірці '+ Inttostr (j), MtInformation, [mbok], 1);
MessageDlg ('Ключ з значенням '+ Edit1.Text +' доданий. ', MtInformation, [mbok], 1);
end;
Output;
end;
1: begin {Search}
If Edit1.Text ='' then MessageDlg (&...