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

  • SEARCH
  • Home
  • 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 8985315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:18:12+00:00 2026-06-15T21:18:12+00:00

How can I properly free the component once i make it with a loop

  • 0

How can I properly free the component once i make it with a loop like this? If I free it like I do now I get some GETMEM.INC exception. I am coming from Indy so i don’t really know ICS too much.

Thanks

  const
    URLs : array[0..3] of string =
    (
      'http://www.example.com',
      'http://www.example.com',
      'http://www.example.com',
      'http://www.example.com'
    ) ;

    var
      Output: array of TStringList;
      S: array of TMemoryStream;
      Async: array of TSslHttpCli;
    implementation

    procedure RequestDone(Sender: TObject; RqType: THttpRequest;
      ErrCode: Word);
    begin
        with Sender as TSSLHTTPCLI do  begin
          S[Tag].Position:=0;
          Output[Tag].LoadFromStream(S[Tag]);
        end;
      end;


    procedure TForm1.Button1Click(Sender: TObject);
    var
    i:integer;
    begin
        for i := 0 to High(URLS) do begin
           S[i]:=TMemoryStream.Create;
           Output[i]:=TStringList.Create;
           Async[i]:=TSslHttpCli.Create(nil);
           Async[i].Tag:=i;
           Async[i].FollowRelocation:=true;
           Async[i].NoCache:=true;

           Async[i].SocketFamily:=sfAny;
           Async[i].OnRequestDone:=RequestDone;
           Async[i].RcvdStream:=S[i];
           Async[i].URL:= URLs[i];
           Async[i].MultiThreaded:=true;
           Async[i].GetASync;
        end;
    end;

    procedure TForm1.Button4Click(Sender: TObject);
    var
    i:integer;
    begin
        for i := 0 to High(URLS) do begin
           Output[i].Free;
           Async[i].RcvdStream.Free;
           Async[i].Free; // << -- EXCEPTION
           //  S[i].Free;
        end;
    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-15T21:18:14+00:00Added an answer on June 15, 2026 at 9:18 pm

    You never allocate any memory for Result, Asynch, or S. You need to SetLength on each of them before you can put anything into them (or take anything back out).

    procedure TForm1.Button1Click(Sender: TObject);
    var
    i:integer;
    begin
      SetLength(Result, Length(URLS));
      SetLength(S, Length(URLS));
      SetLength(Asynch, Length(URLS));
    
      for i := 0 to High(URLS) do begin
        S[i]:=TMemoryStream.Create;
        Result[i]:=TStringList.Create;
        Async[i]:=TSslHttpCli.Create(nil);
    
        // etc.
    
      end;
    end;
    

    BTW, Result is a terrible name for a variable, especially one that’s global in scope. It’s the return value from a function that’s automatically generated by the compiler, and use anywhere but in a function makes your code hard to read. See this, for instance:

    var
      Result: string = '';
    
    procedure AddToReslt(CharToAdd: Char);
    begin
      // Many many lines of code
      // go in here. Maybe a few loops
      // of if statements.
      Result := Result + CharToAdd;
    end;
    
    function DoSomeMath: Integer;
    begin
      // Some really complex numeric code, maybe
      // calculating the value of `pi` to the 900th
      // digit 
      Result := 2 * 2;
    end;
    

    Now quickly – remembering that each of them containss lots of code – which one is a function and which is a procedure?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out how I can do this properly. The print_r looks like
How can I make this print properly without using two printf calls? char* second
I'm hoping I named this question right and that I can explain properly what
I hope I can explain this properly. I'm using flashDevelop for an avatar creation
Can someone help me understand how to write this case statement properly its not
I can't get my divs to layout properly. I'm trying to have a top
I am looking for a free/open source database which can properly store (multi-dimensional) arrays.
I have tried several different submit buttons but can not seem to get this
I will try to explain this the best way I can, but feel free
I use asp:Login control, user can login properly, but while checking user Profile information

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.