Results 1 to 6 of 6

Thread: Searching Question.

  1. #1

    Searching Question.

    Hello,

    1. Is there any way that I make my Delphi program get the names of all the files in a directory?

    2. Is there a search string function that can search for keywords in a string?

    Thank you.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  2. #2

    Searching Question.

    In short, yes and yes.

    In long, look at findfilefirst in the delphi or windows API help files, look at the pos function or search for regex and delphi.

    Remember, your best friends are the help file, google, google code search, and the borland news groups. All of the fore-mentioned have excessive amounts of info about the topics if you had looked there first.

    If you have something more advanced, or don't understand a specific aspect of the above search first then ask again.

  3. #3

    Searching Question.

    As jdarling told you, Delphi has a good example on FindFirst, which is one of the functions used to search for files:

    [pascal]procedure TForm1.Button1Click(Sender: TObject);

    var
    sr: TSearchRec;
    FileAttrs: Integer;
    begin
    StringGrid1.RowCount := 1;
    if CheckBox1.Checked then
    FileAttrs := faReadOnly
    else
    FileAttrs := 0;
    if CheckBox2.Checked then
    FileAttrs := FileAttrs + faHidden;
    if CheckBox3.Checked then
    FileAttrs := FileAttrs + faSysFile;
    if CheckBox4.Checked then
    FileAttrs := FileAttrs + faVolumeID;
    if CheckBox5.Checked then

    FileAttrs := FileAttrs + faDirectory;
    if CheckBox6.Checked then
    FileAttrs := FileAttrs + faArchive;
    if CheckBox7.Checked then

    FileAttrs := FileAttrs + faAnyFile;

    with StringGrid1 do
    begin
    RowCount := 0;

    if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

    begin
    repeat
    if (sr.Attr and FileAttrs) = sr.Attr then
    begin
    RowCount := RowCount + 1;
    Cells[1,RowCount-1] := sr.Name;
    Cells[2,RowCount-1] := IntToStr(sr.Size);
    end;
    until FindNext(sr) <> 0;
    FindClose(sr);
    end;
    end;
    end;[/pascal]

    For the 2nd question, you can also use PosEx, which lets you set the starting position of the search.

  4. #4

    Searching Question.

    Thank you very much. I'll try that now, and won't bother you again unless necessary.

    Very helpful.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  5. #5

    Searching Question.

    I don't understand the part about Edit1.text?

    How does that code work?
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Searching Question.

    Edit1.Text is just a string. Edit1 is the default name for a TEdit component in a Delphi application.

    I don't know if the newer (higher than 7/2005) editions of Delphi still have the handy documentation, but if you want to know more about the VCL (Visual Component Library) I recommend looking through the Help files.

    Just make a new application and play with the component bar, dropping different components onto your form and see what type of components they are. Then got to Help -> Delphi Help then a little dialog box will popup. Go to the 'Index' tab and type in the name of the function or type that you want to learn more about. Most of everything you'll want to know about the VCL or the language syntax will be listed in there.

    If you cannot find it there, you can altenately use the 'Find' tab and see if information in another topic heading will hold any insight to what you need to know.

    Hope this helps.
    Jason McMillen
    Pascal Game Development
    Co-Founder





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •