home *** CD-ROM | disk | FTP | other *** search
- unit Spl2Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, spl;
-
- type
- TForm1 = class(TForm)
- GroupBox1: TGroupBox;
- Edit1: TEdit;
- GroupBox2: TGroupBox;
- Edit2: TEdit;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- Button5: TButton;
- Button6: TButton;
- Button7: TButton;
- Button8: TButton;
- Button9: TButton;
- Button10: TButton;
- Button11: TButton;
- Memo1: TMemo;
- spl1: Tspl;
- procedure Button9Click(Sender: TObject);
- procedure Button10Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button6Click(Sender: TObject);
- procedure Button7Click(Sender: TObject);
- procedure Button8Click(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure Button11Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
- dogen: boolean {Starts and stops automatic data generation};
-
- implementation
-
- {$R *.DFM}
-
-
- function spellnum ( num : string ) : string;
- {This procedure converts a string digits into its English
- string equivalent. The number must be a value less than 10
- billion converted into a string of length 10 and filled
- left with zeroes if necessary}
- var
- x : integer;
- s, s1 : string;
- ar : array [0..32] of string[10];
- p, p3, cnt, ck : integer;
- begin
- p := 32;
- p3 := 1;
- s := '';
- if strtointdef ( num, -1 ) < 0 then
- num := '';
- if num <> '' then
- begin
- ar[0] := 'zero';
- ar[1] := 'one';
- ar[2] := 'two';
- ar[3] := 'three';
- ar[4] := 'four';
- ar[5] := 'five';
- ar[6] := 'six';
- ar[7] := 'seven';
- ar[8] := 'eight';
- ar[9] := 'nine';
- ar[10] := 'ten';
- ar[11] := 'eleven';
- ar[12] := 'twelve';
- ar[13] := 'thirteen';
- ar[14] := 'fourteen';
- ar[15] := 'fifteen';
- ar[16] := 'sixteen';
- ar[17] := 'seventeen';
- ar[18] := 'eighteen';
- ar[19] := 'nineteen';
- ar[20] := 'twenty';
- ar[21] := 'thirty';
- ar[22] := 'fourty';
- ar[23] := 'fifty';
- ar[24] := 'sixty';
- ar[25] := 'seventy';
- ar[26] := 'eighty';
- ar[27] := 'ninety';
- ar[28] := 'hundred';
- ar[29] := '';
- ar[30] := 'thousand';
- ar[31] := 'million';
- ar[32] := 'billion';
- if num [1] <> '0' then
- begin
- x := strtoint ( num[1] );
- s := s + ar [x] + ' ' + ar [p] + ' ';
- end;
- end
- else
- s := '';
- p := p - 1;
- cnt := 2;
- ck := 0;
-
- while cnt <= length ( num ) do
- begin
- if num[cnt] <> '0' then
- begin
- if p3 = 1 then
- begin
- x := strtoint ( num[cnt] );
- s := s + ar [x] + ' hundred ';
- cnt := cnt + 1;
- p3 := p3 + 1;
- ck := 2;
- end
- else if p3 = 2 then
- begin
- if num[cnt] = '1' then
- begin
- s1 := num[cnt] + num [cnt + 1];
- x := strtoint ( s1 );
- s := s + ar [x] + ' ';
- p3 := p3 + 1;
- cnt := cnt + 1;
- ck := 1;
- end
- else
- begin
- s1 := num[cnt];
- x := strtoint ( s1 );
- s := s + ar [x + 18] + ' ';
- p3 := p3 + 1;
- cnt := cnt + 1;
- if num[cnt] = '0' then
- ck := 1
- else
- ck := 3;
- end
- end
- else
- begin
- if ck <> 1 then
- begin
- x := strtoint ( num[cnt] );
- s := s + ar [x] + ' ';
- ck := 2;
- end;
- if ck > 0 then
- s := s + ar [p] + ' ';
- cnt := cnt + 1;
- ck := 0;
- p := p - 1;
- p3 := 1;
- end
- end
- else
- begin
- if p3 = 3 then
- begin
- if ck <> 1 then
- begin
- x := strtoint ( num[cnt] );
- if ( x > 0 ) or ( ( s = '' ) and
- ( cnt = 10 ) ) then
- begin
- s := s + ar [x] + ' ';
- ck := 2;
- end
- end;
- if ck > 0 then
- s := s + ar [p] + ' ';
- cnt := cnt + 1;
- ck := 0;
- p := p - 1;
- p3 := 1;
- end
- else
- begin
- cnt := cnt + 1;
- p3 := p3 + 1;
- end;
- end;
- end;
- spellnum := s;
- end;
-
- procedure TForm1.Button9Click(Sender: TObject);
- begin
- close
- end;
-
- procedure TForm1.Button10Click(Sender: TObject);
- {Automatically inputs 1 million even numbers from 2 to
- 2000000 into the database from different angles to also
- test its strength. Process can be terminated by clicking
- the "stop" button.}
- var
- x : integer;
- ll : array [1..4] of longint;
- cnt : longint;
- s1, s2 : string;
- begin
- if not ( spl1.activedb ) then
- begin
- showmessage ('No active database.');
- dogen := true;
- end;
- if dogen then
- begin
- button10.Caption := '&Generate';
- dogen := false;
- end
- else
- begin
- dogen := true;
- button10.Caption := '&Stop';
- ll[1] := 500000;
- ll[2] := 500002;
- ll[3] := 1500000;
- ll[4] := 1500002;
- x := 1;
- cnt := 0;
- s1 := timetostr ( time );
- edit1.Text := s1;
- repeat
- s1 := inttostr ( ll[x] );
- while length ( s1 ) < 10 do
- s1 := '0' + s1;
- setlength ( s1, 10 );
- s2 := spellnum ( s1 );
- if s2 <> '' then
- begin
- edit2.Text := s1;
- memo1.Text := s2;
- if odd ( x ) then
- ll[x] := ll[x] - 2
- else
- ll[x] := ll[x] + 2;
-
- if spl1.addfield ( s1, 1 ) then
- begin
- if spl1.addfield ( s2, 2 ) then
- begin
- if not ( spl1.addrec ( s1 ) ) then
- showmessage ( inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString );
- end
- else
- showmessage ( inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString );
- end
- else
- showmessage ( inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString );
-
- x := x + 1;
- if x = 5 then
- x := 1;
- cnt := cnt + 1;
- end
- else
- begin
- edit2.Text := 'Error generating number.';
- memo1.Text := 'Illegal or non positive number.';
- dogen := false
- end;
-
- application.ProcessMessages;
-
- {until (topbox^.count = splmax) or (dogen = false);}
- until (cnt >= 1000000) or (dogen = false);
- edit1.Text := edit1.Text + ' - ' + timetostr ( time )
- + ' - ' + inttostr ( cnt ) + ' - ' +
- inttostr ( spl1.reccount );
- end;
-
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- {spl1 := tspl.Create ( self );}
- dogen := false;
- {spl1.initbase;}
- if spl1.initspl then
- begin
- spl1.initbase;
- edit2.Text := 'Splitter database system initialized.'
- end
- else
- edit2.text := 'Initialization failed.'
- end;
-
- procedure TForm1.Button6Click(Sender: TObject);
- var
- s : string;
- begin
- spl1.initbase;
- if spl1.setspl ('010140') then
- begin
- if spl1.createspl ('test') then
- edit2.Text := 'Splitter Database created.'
- else
- begin
- s := inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString;
- edit2.Text := s;
- end
- end
- else
- begin
- s := inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString;
- edit2.Text := s;
- end
- end;
-
- procedure TForm1.Button7Click(Sender: TObject);
- var
- s : string;
- begin
- spl1.initbase;
- if spl1.openspl ('test') then
- begin
- spl1.reclimit := spl1.reccount;
- edit2.Text := 'Splitter Database opened.';
- memo1.text := {spl1.currentdb + ' - ' +
- inttostr ( spl1.allrec.size ) + ' - ' +}
- inttostr ( spl1.Reclimit );
- end
- else
- begin
- s := inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString;
- edit2.Text := s;
- end
- end;
-
- procedure TForm1.Button8Click(Sender: TObject);
- var
- s1, s2 : string;
- begin
- if spl1.activedb then
- begin
- s1 := edit1.Text;
- while length ( s1 ) < 10 do
- s1 := '0' + s1;
- setlength ( s1, 10 );
- s2 := spellnum ( s1 );
- if s2 <> '' then
- begin
- edit2.Text := s1;
- memo1.Text := s2;
- if spl1.addfield ( s1, 1 ) then
- begin
- if spl1.addfield ( s2, 2 ) then
- begin
- if spl1.addrec ( s1 ) then
- showmessage ('Record sucessfuly inserted.')
- else
- showmessage ( inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString );
- end
- else
- showmessage ( inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString );
- end
- else
- showmessage ( inttostr ( Spl1.ErrorNumber ) + ' ' +
- Spl1.ErrorString );
- end
- else
- begin
- showmessage ('Illegal input. Not a positive number.');
- edit2.Text := s1;
- memo1.Text := 'Illegal value.';
- end;
- end
- else
- showmessage ('No active database.');
- end;
-
- procedure TForm1.Button5Click(Sender: TObject);
- var
- s : string;
- begin
- if spl1.activedb then
- begin
- s := edit1.Text;
- while length ( s ) < 10 do
- s := '0' + s;
- edit1.Text := s;
- if spl1.getrec ( s ) then
- begin
- showmessage ('Record found.');
- memo1.Text := 'Record found.';
- edit2.text := spl1.getfield ( 1 );
- memo1.Text := spl1.getfield ( 2 );
- end
- else
- begin
- showmessage ('Record not found.');
- memo1.Text := inttostr ( Spl1.ErrorNumber ) + ' '
- + Spl1.ErrorString;
- end
- end
- else
- showmessage ('No active database.');
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if not (spl1.dbempty) then
- begin
- if spl1.firstrec then
- begin
- edit2.text := spl1.getfield ( 1 );
- memo1.Text := spl1.getfield ( 2 );
- end
- else
- memo1.Text := inttostr ( Spl1.ErrorNumber ) + ' '
- + Spl1.ErrorString;
- end
- else
- showmessage ('Database empty or not loaded.')
- end;
-
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- if not (spl1.dbempty) then
- begin
- if spl1.lastrec then
- begin
- edit2.text := spl1.getfield ( 1 );
- memo1.Text := spl1.getfield ( 2 );
- end
- else
- memo1.Text := inttostr ( Spl1.ErrorNumber ) + ' '
- + Spl1.ErrorString;
- end
- else
- showmessage ('Database empty or not loaded.')
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- if not (spl1.dbempty) then
- begin
- if spl1.nextrec then
- begin
- edit2.text := spl1.getfield ( 1 );
- memo1.Text := spl1.getfield ( 2 );
- end
- else
- memo1.Text := inttostr ( Spl1.ErrorNumber ) + ' '
- + Spl1.ErrorString;
- end
- else
- showmessage ('Database empty or not loaded.')
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- if not (spl1.dbempty) then
- begin
- if spl1.prevrec then
- begin
- edit2.text := spl1.getfield ( 1 );
- memo1.Text := spl1.getfield ( 2 );
- end
- else
- memo1.Text := inttostr ( Spl1.ErrorNumber ) + ' '
- + Spl1.ErrorString;
- end
- else
- showmessage ('Database empty or not loaded.')
- end;
-
- procedure TForm1.Button11Click(Sender: TObject);
- begin
- if spl1.delrec then
- showmessage ('Record properly deleted.')
- else
- memo1.Text := inttostr ( Spl1.ErrorNumber ) + ' '
- + Spl1.ErrorString;
-
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if spl1.releasespl then
- showmessage ('Splitter database system released.')
- else
- showmessage ('Error releasing Splitter database system.');
- end;
-
- end.
-