Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:23:20+00:00 2026-06-05T23:23:20+00:00

hello i am trying to load a list of filenames from a folder into

  • 0

hello i am trying to load a list of filenames from a folder into a Stringlist. I only want to add the names of files that end in .jpg When i run it now i get access violation errors. Here is what i got.

Selects directory.

procedure TMainForm.Load1Click(Sender: TObject);
var
  DirName: string;
begin
    mylist.Free;
    myList := TList<TBitmap>.Create;
  DirName := 'c:\';
  if SelectDirectory(DirName,[sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP)
  then;
    LoadImages(DirName);
end;

Gets number of totalfiles in folder

function GetFilesCount(Dir : string; Mask : string) : integer;
var
  Path : string;
begin
  Result := 0;
  for Path in TDirectory.GetFiles(Dir, Mask) do
    inc(Result);
end;

Gets filenames from folder

function TMainForm.GetFilenames(Path: string ):TStrings;
var
  Dest: TStrings;
  SR: TSearchRec;
begin
  Dest.create;
  if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
  repeat
    Dest.Add(SR.Name);
  until FindNext(SR) <> 0;
  FindClose(SR);
  Result := Dest;
  Dest.Free;
end;

and the load iamges

    procedure TMainForm.LoadImages(const Dir: string);
    const
      FIRST_IMAGE = 0;
    var
      iFile : Integer;
      CurFileName: string;
      FoundFile : boolean;
      FileNameTemplate : string;
      FileNames : Tstrings;
    begin
       FileNames.Create;
       FileNameTemplate := IncludeTrailingPathDelimiter(Dir) + '*.jpg';          FileNames:=GetFileNames(FileNameTemplate);                                                 
      try
        ifile := 0;                                                                 
        repeat
          CurFileName := FileNames.Names[ifile];                                      
          showmessage(Curfilename);
 if FoundFile then
      begin
        end;
        Inc(iFile);
      end;
    until not FoundFile;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:23:22+00:00Added an answer on June 5, 2026 at 11:23 pm

    The problem is here (where you actually have two problems) – actually, you have the same problems twice in your code:

    Dest.Create;  // In GetFileNames
    
    FileNames.Create; // In LoadImages
    

    First, TStrings is an abstract class. You can’t create an instance of it; it’s the basis for other more concrete classes like TStringList. Create one of those concrete classes instead.

    Second, you have to create the TStringList and store a reference to it.

    FileNames := TStringList.Create;
    

    The better way to do it is to create your stringlist and pass it into the function or procedure, since you need the results when it returns. I’ll take a quick pass at one of them for you:

    function TMainForm.GetFilenames(const Path: string; const FileList: TStringList ): Boolean;
    var
      SR: TSearchRec;
    begin
      Assert(Assigned(FileList));      // Make sure it was created and passed in
      FileList.Clear;                  // Remove any previous names
      if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
      repeat
        FileList.Add(SR.Name);
      until FindNext(SR) <> 0;
      FindClose(SR);
      Result := FileList.Count > 0;  // Return true if we have found any files
    end;
    

    Call it like this:

    FileNames := TStringList.Create;
    try
      if GetFileNames(PathToFolder, FileNames) then
      begin
        // Process files here
        for i := 0 to FileNames.Count - 1 do
        begin
          CurrFile := FileNames[i];
          // Use the file here from CurrFile
        end;
    
      end;
    finally
      FileNames.Free;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am trying to load images from files in the start of my
Hello I was trying to remove objects from object array that I have and
hello I am trying to load coordinates for plotting from a text file and
Hello I'm trying to load my listview with data from a database via a
Hello im trying to echo only the 50 letters, but something in my code
I am trying to load some JavaScript files inside another JavaScript file in the
Hello I am getting xml feed from expedia and trying to parse it onto
hello iam trying to get the id from a url and send it to
I'm trying to load a text file from res/raw. I've looked at several code
Hello I'm trying to make a simple web chat, and I want the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.