Recent

Author Topic: [SOLVED] Thread creation problems  (Read 3031 times)

JD

  • Hero Member
  • *****
  • Posts: 1848
[SOLVED] Thread creation problems
« on: March 31, 2015, 04:51:18 pm »
Hi there everyone,

I'm working on rewriting an application I wrote a while ago.

Code: [Select]
  { TParentThread }

  TParentThread = class(TThread)
  private
    { private decelarations }
    // a critical section
    FCriticalSection: TCriticalSection;
  protected
    { protected decelarations }
    procedure Execute; override;
  public
    { public decelarations }
    // the TCP client
    FTCPClient: TIdTCPClient;
    // constructor and destructor
    constructor Create(ATCPClient: TIdTCPClient);
    destructor Destroy; override;
    // enter critical section
    procedure Lock;
    // leave critical section
    procedure Unlock;
  end;

constructor TParentThread.Create(ATCPClient: TIdTCPClient);
begin
  // set reference to the TCP client
  FTCPClient := ATCPClient;
  // create a critical section instance
  FCriticalSection := TCriticalSection.Create;
  inherited Create(True);
end;

  { TThreadVilles }

  TThreadVilles = class(TParentThread)
  private
    { private declarations }
    FOnVille: TFillComboBoxEx;
    procedure DoFillComboBoxEx;
  protected
    { protected declarations }
    procedure Execute; override;
  public
    { public declarations }
    // constructor and destructor
    constructor Create(ATCPClient: TIdTCPClient);
    destructor Destroy; override;
    // property
    property OnVille: TFillComboBoxEx read FOnVille write FOnVille;
  end;

constructor TThreadVilles.Create(ATCPClient: TIdTCPClient);
begin
  inherited;
  Create(ATCPClient);
end;

procedure TfrmVilles.FormShow(Sender: TObject);
begin
   // Create the thread
  DataThread := TThreadVilles.Create(FTCPClient);   <-- The error occurs here
  //
  DataThread.Start;
  //
  DataThread.DoFillComboboxEx;
end;


The code above is part of the program & I keep getting an error on the line where the thread is created which says Thread creation error: insufficient space to treat this command. See attachment. I've never had such a problem before. The message is rather confusing because I have 4GB of RAM.

I would appreciate the insight of the community about how to get round this problem.

Thanks,

JD
« Last Edit: March 31, 2015, 05:28:00 pm by JD »
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Thread creation problems
« Reply #1 on: March 31, 2015, 04:59:59 pm »
I assume you have a typo. Change:
Code: [Select]
constructor TThreadVilles.Create(ATCPClient: TIdTCPClient);
begin
  inherited;
  Create(ATCPClient);
end;

to:

Code: [Select]
constructor TThreadVilles.Create(ATCPClient: TIdTCPClient);
begin
  inherited Create(ATCPClient);
end;

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: Thread creation problems
« Reply #2 on: March 31, 2015, 05:27:30 pm »
@engkin Thanks a lot. I completely missed that!  :D
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

 

TinyPortal © 2005-2018