sobhan1990
پنج شنبه 08 آبان 1393, 13:50 عصر
سلام
من یک ترد در دلفی نوشتم به صورت زیر:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids, Data.DB,
Data.Win.ADODB, Vcl.StdCtrls;
type
myThread=class(TThread)
protected
// the main body of the thread
procedure Execute; override;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
class var
adocon : TADOConnection;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
T : myThread;
begin
T := myThread.Create(True);
T.FreeOnTerminate := True;
T.Resume;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
adocon := TADOConnection.Create(Application);
adocon.Provider := 'SQLOLEDB.1';
adocon.LoginPrompt := False;
adocon.ConnectionString := 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=mydb;Data Source=.;';
end;
{ myThread}
procedure myThread.Execute;
begin
inherited;
ShowMessage('before');
Form1.adocon.Open();
ShowMessage('after');
end;
end.
ولی در زمان اجرا فقط کد ShowMessage('before'); اجرا میشه و دو خط بعدی اجرا نمیشه. چون کانکشن من به اسکیوال وصل نمیشه و انتظار دارم که یک پیام خطا عدم اتصال ببینم و بعدش پیام ShowMessage('after'); اجرا بشه.
کسی میدونه مشکل کجاست؟
با تشکر
من یک ترد در دلفی نوشتم به صورت زیر:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids, Data.DB,
Data.Win.ADODB, Vcl.StdCtrls;
type
myThread=class(TThread)
protected
// the main body of the thread
procedure Execute; override;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
class var
adocon : TADOConnection;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
T : myThread;
begin
T := myThread.Create(True);
T.FreeOnTerminate := True;
T.Resume;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
adocon := TADOConnection.Create(Application);
adocon.Provider := 'SQLOLEDB.1';
adocon.LoginPrompt := False;
adocon.ConnectionString := 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=mydb;Data Source=.;';
end;
{ myThread}
procedure myThread.Execute;
begin
inherited;
ShowMessage('before');
Form1.adocon.Open();
ShowMessage('after');
end;
end.
ولی در زمان اجرا فقط کد ShowMessage('before'); اجرا میشه و دو خط بعدی اجرا نمیشه. چون کانکشن من به اسکیوال وصل نمیشه و انتظار دارم که یک پیام خطا عدم اتصال ببینم و بعدش پیام ShowMessage('after'); اجرا بشه.
کسی میدونه مشکل کجاست؟
با تشکر