Thank you Mr.LLoyd, that did the trick.
But I'm having problems implementing this function. I don't think I
totally understand how to call it, or how works. I've commented the
function with some guesses and questions.
Basically, if I call the function from my procedure
TForm1.edSearchBoxChange(Sender: TObject); procedure, how can I make use
of its return value if it returns boolean? What I need to do is have a
way to return all permutations of the typed-in word that exist in the
list and display them in the listbox.
Am I even close to being on the right track with what I have so far? :
unit MainWindow;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, Menus, StdCtrls, ExtCtrls, Mask, ComCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
muFile: TMenuItem;
muLo{*word*60}: TMenuItem;
Search1: TMenuItem;
muSearch: TMenuItem;
muSave: TMenuItem;
N1: TMenuItem;
muExit: TMenuItem;
Help1: TMenuItem;
muAbout: TMenuItem;
sbStatusBar: TStatusBar;
Panel1: TPanel;
edSearchBox: TEdit;
dbOpenFile: TOpenDialog;
lbFoundList: TListBox;
procedure muAboutClick(Sender: TObject);
procedure muLo{*word*60}Click(Sender: TObject);
procedure muSearchClick(Sender: TObject);
procedure edSearchBoxChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
DictText: TextFile;
index: integer;
IsDictLoaded : boolean = false;
I, P: integer;
DictArray: Array[1..100000] of string;
implementation
uses AboutWindow;
{$R *.dfm}
procedure TForm1.muAboutClick(Sender: TObject);
begin
fmAboutWindow.ShowModal
end;
procedure TForm1.muLo{*word*60}Click(Sender: TObject);
begin
index := 1;
if dbOpenFile.Execute then // If the open dialog box is executed
AssignFile(DictText,dbOpenFile.FileName);
Reset(DictText);
While (not eof(DictText)) do
begin
Readln(DictText,DictArray[index]);
if (index mod 10) = 0 Then
sbStatusBar.Panels[0].Text :='Dictionary Size:' + IntToStr
(index);
application.ProcessMessages;
inc(index);
end;
CloseFile(DictText);
IsDictLoaded := true;
end;
procedure TForm1.muSearchClick(Sender: TObject);
begin
if (not IsDictLoaded) then
Application.MessageBox(' Dictionary is not loaded! Please try
again.'
, 'ERROR!!')
end;
function Check(SrchWrd, ListWord: string): Boolean;
begin
// Result is true if list word is equal to typed word
Result := Length(SrchWrd) = length(ListWord); I := 1;
// Doesn't this eliminate any words not of equal length?
// What does I <= length(SrchWrd) do
while Result and (I <= length(SrchWrd)) do
begin
// Does this compare the first character of both words?
P := Pos(SrchWrd[I], ListWord);
// Does this say that the character cannot be in the 0 position of
the string
// I'm confused
Result := P <> 0;
// If not the 0th character change the P'th character to a blank
// character so that it won't be read again...
// Inc(I) = go to the next character
if Result then begin
ListWord[P] := ' ' {to handle repetitions}; Inc(I)
end;
end;
end;
procedure TForm1.edSearchBoxChange(Sender: TObject);
var
TypedWord, DictWord : string;
i : integer;
begin
i := 1;
TypedWord := edSearchBox.Text;
while (i <= index ) do
begin
DictWord := DictArray[i];
check(TypedWord, DictWord);
lbFoundList.Items.Add(DictArray[i]);
inc(i);
end;
end;
end.