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 7887213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:31:14+00:00 2026-06-03T05:31:14+00:00

I am creating a multithreaded application, it creates a dynamic array of a class

  • 0

I am creating a multithreaded application, it creates a dynamic array of a class TThread, but the mystery for me, is that it causes an error ‘Access Violation’ to ‘Create’

Code Form:

Unit UNT_Main;

Interface

Uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UNT_Socks;

Type
  TFRM_Main = Class(TForm)
    Procedure FormCreate(Sender: TObject);
  Private
    Procedure OnUpload(Success: Boolean; SockAction: TSockAction);
  Public
    { Public declarations }
  End;

Var
  FRM_Main: TFRM_Main;
  Socks: Array Of TSocks;
  SA: Array Of TSockAction;

Implementation

{$R *.dfm}

Procedure TFRM_Main.OnUpload(Success: Boolean; SockAction: TSockAction);
Begin
  ShowMessage(SockAction.Response);
End;

Procedure TFRM_Main.FormCreate(Sender: TObject);
Var
  I: Integer;
Begin

  SetLength(Socks, 5);
  SetLength(SA, 5);

  For I := 0 To High(Socks)-1 Do
  Begin
    SA[I].SUrl := 'http://google.com.co';
    Socks[I].Create(SA[I]);
    Socks[I].OnUpload := Self.OnUpload;
    Socks[I].Start;
  End;

End;

End.

Code UNT_Socks:

Unit UNT_Socks;

Interface

Uses Classes, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

// action script
Type
  TSockAction = Record
    SUrl: String;
    Response: String;
  End;

  // Eventos
Type
  // on upload event
  TUpload = Procedure(Success: Boolean; SockAction: TSockAction) Of Object;

  // Clase Socks, ejecuta las acciones
Type
  TSocks = Class(TThread)
    // Http indy sock
    Http: TIdHTTP;
    // action script
    FAtnSck: TSockAction;
    // Temp boolean response
    FbTempRet: Boolean;
  Private
    { Eventos }
    FOnUpload: TUpload;
    { Destructor }
    { Metodos & Funciones }
    Function UploadFile: Boolean;
    { Eventos }
    Procedure DoUpload;
  Protected
    Procedure Execute; Override;
  Public
    { Constructor }
    Constructor Create(SockAction: TSockAction);
    { Eventos }
    Property OnUpload: TUpload Read FOnUpload Write FOnUpload;
  End;

Implementation

{ Constructor }
Constructor TSocks.Create(SockAction: TSockAction);
Begin
  Inherited Create(True);

  FAtnSck := SockAction; // <===== Access Violation Here!
  Http := TIdHTTP.Create(Nil);
End;

{ Eventos }
Procedure TSocks.DoUpload;
Begin
  // check if the event is assign
  If Assigned(FOnUpload) Then
    // call it
    FOnUpload(FbTempRet, FAtnSck);
End;

{ Execute }
Procedure TSocks.Execute;
Begin

  FbTempRet := UploadFile;
  Synchronize(DoUpload);

End;

Function TSocks.UploadFile: Boolean;
Var
  SRes: String;
Begin

  Try
    With Http Do
      FAtnSck.Response := Get(FAtnSck.SUrl);
  Except
    Result := False;
  End;

  Result := True;
End;

End.

What could be wrong?

Thank you.

  • 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-03T05:31:16+00:00Added an answer on June 3, 2026 at 5:31 am

    Your creation loop has 2 bugs in it:

    1) You are looping to High(Socks)-1 when you should be looping to High(Socks) instead. You are allocating arrays of 5 elements but only initializing 4 of them. Don’t use -1 with High(), use it with Length() instead.

    2) You are misusing TSocks.Create(), which is why you are getting an AV. You are calling it like an instance method instead of a constructor, but no instance has been constructed yet, thus the crash.

    Use this instead:

    For I := 0 To High(Socks) Do
    Begin
      SA[I].SUrl := 'http://google.com.co';
      Socks[I] := TSocks.Create(SA[I]); // <-- here
      Socks[I].OnUpload := Self.OnUpload;
      Socks[I].Start;
    End;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have heard that in Haskell, creating a multi-threaded application is as easy as
I am creating some multi-threaded code, and I have created a JobDispatcher class that
I am looking for the Flickr multithreaded example application that is used in lecture
I'm creating an app that is a sort of client- multithreaded server. The problem
I am creating an application that does screen shots of websites using the following
I have a high-level goal of creating a static utility class that encapsulates the
I have a multithreaded app that is creating a list of strings on a
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
I have a project that I have recently started working on seriously but had
I'm trying to create a multithreaded opengl application with libx11 - with one separate

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.