My program, a total of three form, Form1 is landing window, Form2 and 3 work window (including 6 adoquery),
I double click on the EXE file to run takes about 10 seconds (blank jump out of the window at this time is no response), how to display the progress bar in the 10 seconds???????
White, not the following code, open applications and no response, just open the 10 s, how to change into 10 s display progress bar:
Procedure TForm1. FormCreate (Sender: TObject);
Var
I: integer;
The begin
ProgressBar1. Visible:=True;
ProgressBar1. Min:=0; ProgressBar1. Max:=100;//here N for chief
ProgressBar1. Value:=0;//initializes the starting position
For I:=0 to 100 do
The begin
ProgressBar1. Value:=I + 1; Application. ProcessMessages;
end;
ProgressBar1. Visible:=False;
With Form1. ADOQuery1 do
The begin
close;
SQL. The clear;
SQL. The Add (' select * from the users');
The open;
While not Eof do
The begin
ComboEdit1. Items. The Add (Fieldbyname (' name '). AsString) are identical.
Next;
end;
end;
end;
CodePudding user response:
You this became synchronous operation: first get the progress bar to load the database,The correct approach is: put the database operations in the thread, and starting a thread before the progress bar
CodePudding user response:
Upstairs, specific how to do excuse me, have to order embarrassed!CodePudding user response:
Try this:Procedure TForm1. FormCreate (Sender: TObject);
Var
I: integer;
The begin
ProgressBar1. Visible:=True;
ProgressBar1. Value:=0;//initializes the starting position
ProgressBar1. Min:=0;
//progressBar1. Max:=100;//here N for chief
With Form1. ADOQuery1 do
The begin
close;
SQL. The clear;
SQL. The Add (' select * from the users');
The open;
ProgressBar1. Max:=RecordCount;//here N for chief
While not Eof do
The begin
ProgressBar1. Value:=ProgressBar1. Value + 1;
Application. ProcessMessages;
ComboEdit1. Items. The Add (Fieldbyname (' name '). AsString) are identical.
Next;
end;
end;
ProgressBar1. Visible:=False;
end;
CodePudding user response:
Create a new Thread, assuming named TThread1, in Unit2, USES in Unit2 plus Form1 unit, hypothesis of Unit1. Add a private variable to TThread1: Form: TForm1.Overloaded constructor first:
add a private to TThread1 process DoInit () :
The constructor TThread1. Create (F: TForm1);
The begin
Inherited the Create (True);
Form:=F;
end;
Procedure TThread1. DoInit () :
The begin
With the Form. ADOQuery1 do
The begin
close;
SQL. The clear;
SQL. The Add (' select * from the users');
The open;
While not Eof do
The begin
Form.Com boEdit1. Items. The Add (Fieldbyname (' name '). AsString) are identical.
Next;
end;
end;
end;
In the Execute TThread1 write:
Procedure TThread1. Execute;
The begin
The Synchronize (DoInit);
end;
Unit1 implementation and USES Unit2;
TForm1. FormCreate modified as follows:
Procedure TForm1. FormCreate (Sender: TObject);
Var
I: integer;
Thread: TThread1;
The begin
ProgressBar1. Visible:=True;
ProgressBar1. Min:=0; ProgressBar1. Max:=100;//here N for chief
ProgressBar1. Value:=0;//initializes the starting position
Thread:=TThread1. Create (self);
Thread. Resume;
While not Thread. Terminated do
The begin
ProgressBar1. Value:=I + 1;
end;
ProgressBar1. Visible:=False;
Thread. Free;
end;
According to the truth to modify ProgressBar1. Max
CodePudding user response:
If the initialization work is so regular cycle, 3/f is one of the bestCodePudding user response:
Thank you upstairs! But I don't spend time FROM1 which query, is that many in Form2 database query time, if there is no Form2, that is very fast, so, consider upstairs From2 query, there are six adoquery Form2 (1-6), six Datasource (-- 6),Can you solve?
CodePudding user response:
Didn't see you call Form2 code, look on the post, or you can refer to my above threads, as the truthCodePudding user response:
The main query Form2 content is as follows:Procedure TForm2. CheckBox1Change (Sender: TObject);
Var
I: integer;
SQLSTR: string;
King: string;
Lables: TLabel;
The Edits: TEdit;
J: integer;
The begin
If CheckBox1. IsChecked then
The begin
With Form2. ADOQuery7 do
The begin
close;
SQL. The Clear;
SQL. The Add (' select cc from tops where c=: uuu ');
The Parameters. ParamByName (" uuu "). The Value:=Edit1. Text;
The Open;
If recordCount & lt; 1 then
The begin
Showmessage (' not exit! ');
The Exit;
end;
ADOQuery2. Close;
ADOQuery2. SQL. Text:='Select * from tops where cc=' "+ trim (edit1. Text) +" '"';
ADOQuery2. Open;
Label11. Text:=ADOQuery2. Fieldbyname (' as'). The asstring;
.
ADOQuery3. Close;
ADOQuery3. SQL. The Clear;
ADOQuery3. SQL. The Add (' select * from matrix1 where cc='" + trim (edit1. Text) + "' ");
Adoquery3. Open;
King:=';
For j:=0 to ADOQuery3. Do FieldCount - 1
If ADOQuery3. Fields [j]. Value='https://bbs.csdn.net/topics/Y' then
King:=king + ', '+ ADOQuery3. Fields [j]. J FieldName;
King:='select vv + king,' the from rules where vv='" + ADOQuery3. Fieldbyname (' cc'). AsString + "'" ';
ADOQuery5. Close;
ADOQuery5. SQL. The Clear;
Adoquery5. SQL. The add (king);
Adoquery5. Open;
ADOQuery3. Close;
ADOQuery3. SQL. The Clear;
ADOQuery3. SQL. The Add (' select * from matrix where vv='" + trim (edit1. Text) + "' ");
Adoquery3. Open;
SQLSTR:=';
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull