The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
Building a Search Engine .. using Delphi 7
Discuss Building a Search Engine .. using Delphi 7 in the Delphi Programming forum on Dev Shed. Building a Search Engine .. using Delphi 7 Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 28th, 2012, 05:06 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
|
|
|
Building a Search Engine .. using Delphi 7
Greeting Everybody
well, I'm studying ITC in last level of BS..I need many many helps in my graduate project.
it will be Search Engine , using data structures and text Files that's store in Hard disk.I will build and programmed by using Delphi language..
I already started to learn it before 2 weeks ago , but I need strongly help to achieve my tasks .
I wish that you are help me !
Hint: I will keep this page for my Questions..
Thanks
|

December 28th, 2012, 05:15 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
|
|
|
read the text of file
The first attempt to read the text of file and display the text in Memo:
Code:
Var
myFile:TextFile;
text:string;
procedure TForm1.ReadButtonClick(Sender: TObject);
begin
AssignFile(myFile, 'superComputer.txt');
Reset(myFile);
While not eof(myFile) Do
Readln(myFile,text);
Memo1.Lines.LoadFromFile('superComputer.txt');
closeFile(myFile);
end;
|

December 28th, 2012, 05:18 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
|
|
|
Question (1)
|

December 28th, 2012, 05:36 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
Quote: | Originally Posted by iTechnical The first attempt to read the text of file and display the text in Memo:
Code:
Var
myFile:TextFile;
text:string;
procedure TForm1.ReadButtonClick(Sender: TObject);
begin
AssignFile(myFile, 'superComputer.txt');
Reset(myFile);
While not eof(myFile) Do
Readln(myFile,text);
Memo1.Lines.LoadFromFile('superComputer.txt');
closeFile(myFile);
end;
|
Do you realize that most of that code you wrote does nothing useful at all? You could do the same thing with only one line of code
Code:
procedure TForm1.ReadButtonClick(Sender: TObject);
begin
Memo1.Lines.LoadFromFile('superComputer.txt');
end;
That's all there is to it.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|

December 28th, 2012, 05:48 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
Quote: | Originally Posted by iTechnical |
Code:
var
words : TStringList;
MyString : String;
idx: integer;
begin
MyString := "This is a test";
words := TStringList.Create;
// words.Delimiter := ' '; // This is the default. Uncomment and change to another character if you have a different delimiter.
words.DelimitedText := MyString;
// String should now be split by spaces
for idx := 0 to words.count - 1 do
begin
ShowMessage(words[idx]);
end;
words.Free;
end;
|

December 28th, 2012, 06:33 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Scorpions4ever Do you realize that most of that code you wrote does nothing useful at all? You could do the same thing with only one line of code
Code:
procedure TForm1.ReadButtonClick(Sender: TObject);
begin
Memo1.Lines.LoadFromFile('superComputer.txt');
end;
That's all there is to it. |
Thank you Scorpions4ever
But it was evaluation for me...
How do I open the file and read the text inside it .

|

December 28th, 2012, 07:14 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Scorpions4ever
Code:
var
words : TStringList;
MyString : String;
idx: integer;
begin
MyString := "This is a test";
words := TStringList.Create;
// words.Delimiter := ' '; // This is the default. Uncomment and change to another character if you have a different delimiter.
words.DelimitedText := MyString;
// String should now be split by spaces
for idx := 0 to words.count - 1 do
begin
ShowMessage(words[idx]);
end;
words.Free;
end;
|
it's working perfectly .
|

December 28th, 2012, 07:17 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
|
|
but my Supervisor asked me to defined an Array to store each word ! I'm still trying
This is part of my attempt ...
Code:
const size=1000;
var
myFile:TextFile;
text:string;
I:integer;
MyArray:Array [1..size] of string;
begin
AssignFile(myFile, 'concepts.txt');
Reset(myFile);
repeat
Readln(MyFile,text);
// here should be write a condition to check a if the word between 2 spaces then take it and store in Array but I don't know HOW ? :(
// if the condition is True .. do this :
Begin
MyArray [I] := text;
I := I+1;
Until eof(MyFile);
End;
What do you think ??
|

December 29th, 2012, 12:11 AM
|
|
Contributing User
|
|
Join Date: May 2012
Posts: 140
Time spent in forums: 1 Day 4 h 58 m 17 sec
Reputation Power: 2
|
|
There are flaws in your definition of word. If you only capture those between two spaces, then you will fail to capture word at the the start of the string, word at the end of the string, and words followed by punctuations.
Anyway, it is better if you "walk" the source string. Use two integer variables to know the starting and end position to extract a word once one detected.
Something like below (warning, not completed code, more like pseudocode).
Code:
var
T: string;
i, j: Integer;
begin
i := 1;
for j := 1 to Length(SourceStr) do
begin
if SourceStr[j] is end of a word then
begin
T := Copy(ASourceStr, i, j-i);
Add T to your array;
end;
end;
end;
For the array, you can use dynamic array. Declare it something like this.
Code:
var
vArray: array of string;
Note that using dynamic array you need to make sure it has sufficient size. You can alter its size with SetLength, similar like string. And dynamic arrays always start from 0.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|