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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:36:22+00:00 2026-05-22T15:36:22+00:00

The below code makes application freeze when changing focus from Edit1 to Edit2 after

  • 0

The below code makes application freeze when changing focus from Edit1 to Edit2 after creating the thread.

Steps to reproduce:

  • Click Create thread button
  • Switch focus between Edit1 / Edit2.

I think the ADO object creation inside the thread is causing the application to freeze.

Does anyone have any idea of the what is the exact problem?

Note : I guess the problem occurs when default input language is changed.
Win xp – Text Service and Input langauges dialog – Default input language.

Same issue as :

http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/1d27c2ad-7ef1-45e9-b9af-6bfb458c1165

pas file

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ADODB, SyncObjs, ActiveX,
  ComObj, Menus, StdCtrls;

type

  TMyThread = class(TThread)
  private
    FEvent : TEvent;
    adoConnection : TADOConnection;
  protected
    procedure Execute; override;
  public
    constructor Create(ASuspended : boolean);
    destructor Destroy; override;
  end;


  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TextEdit1Enter(Sender: TObject);
    procedure TextEdit2Enter(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    MyThread : TMyThread;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyThread }

constructor TMyThread.Create(ASuspended: boolean
                            );
begin
  inherited Create(ASuspended);
  FEvent := TEvent.Create(nil,
                          false,
                          false,
                          'test'
                          );
end;

destructor TMyThread.Destroy;
begin
  FreeAndNil(FEvent);
  inherited;
end;

procedure TMyThread.Execute;
begin
  CoInitializeEx(nil,
                 COINIT_MULTITHREADED
                );
  try
    adoConnection := TADOConnection.Create(nil);
    FEvent.WaitFor(INFINITE);
    adoConnection.Free;
  finally
    CoUnInitialize;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyThread.Resume;
end;

procedure TForm1.TextEdit1Enter(Sender: TObject);
begin
  LoadKeyboardLayout(PChar(IntToHex(1081, 8)), KLF_ACTIVATE);
end;

procedure TForm1.TextEdit2Enter(Sender: TObject);
begin
  LoadKeyboardLayout(PChar(IntToHex(1043, 8)), KLF_ACTIVATE);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MyThread.FEvent.SetEvent;
  MyThread.Terminate;
  FreeAndNil(MyThread);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyThread := TMyThread.Create(true);
end;

end.

form file

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 115
  ClientWidth = 147
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 8
    Top = 8
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
    OnEnter = TextEdit1Enter
  end
  object Edit2: TEdit
    Left = 8
    Top = 35
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit2'
    OnEnter = TextEdit2Enter
  end
  object Button1: TButton
    Left = 8
    Top = 62
    Width = 121
    Height = 45
    Caption = 'Create Thread'
    TabOrder = 2
    WordWrap = True
    OnClick = Button1Click
  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-05-22T15:36:23+00:00Added an answer on May 22, 2026 at 3:36 pm

    Solved it.

    In pas file change the line

     CoInitializeEx(nil,
                     COINIT_MULTITHREADED
                    );
    

    to

      CoInitializeEx(nil,
                     COINIT_APARTMENTTHREADED
                    );
    

    and

      FEvent := TEvent.Create(nil,
                              false,
                              false,
                              'test'
                              );
    

    to

      FEvent := TEvent.Create(nil,
                              false,
                              false,
                              'test',
                              true
                              );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The below HTML/CSS/Javascript (jQuery) code displays the #makes select box. Selecting an option displays
In the below code sample, what does {0:X2} mean? This is from the reflection
When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should
When running the below code a type is never returned, despite there being a
In the below code snippet can i replace char * to const char *
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
In the below code, the ListBox gets filled with the names of the colors
I would like to know how to modify the below code to strip =20
Okay so I have a scenario similar to the below code, I have a
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {

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.