Q
qiuxing009
Unregistered / Unconfirmed
GUEST, unregistred user!
才学多线程。。下面这个不知道错在那里。。请教各位大侠。。。
unit ThreadHZ;
interface
uses
Classes,ComCtrls,ADODB,SysUtils,Dialogs,Forms;
type
ReSZ=array of Extended;
HZThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
public
ListV:TListView;
AQ:TADOQuery;
ProBar:TProgressBar;
constructor Create(LVName:TListView;AQuery:TADOQuery;PBarName:TProgressBar);
//构造函数
function DateHZ():ReSZ;
Function OpenTable( StrSQL: String;
AQ : TADOQuery ) : Integer;
function KToZero(K:String):Extended;
//将数据转换为 Extended类型
end;
implementation
function HZThread.DateHZ(): ReSZ;
var
iloop,i,n:Integer;
JG:array [1..28,1..21] of Extended;
//1..27
SY:array [1..28,1..21] of Extended;
ZD:TStringList;
begin
for i := 1 to 28do
begin
for n := 1 to 21do
begin
JG[i,n]:=0;
end;
end;
ZD:=TStringList.Create;
ZD.Add('C');
ZD.Add('D');ZD.Add('E');ZD.Add('F');ZD.Add('G');ZD.Add('H');ZD.Add('I');
ZD.Add('J');ZD.Add('K');ZD.Add('L');ZD.Add('M');ZD.Add('N');ZD.Add('O');
ZD.Add('P');ZD.Add('Q');ZD.Add('R');ZD.Add('S');ZD.Add('T');ZD.Add('U');
ZD.Add('V');ZD.Add('W');ZD.Add('X');
//**************
if pos('JG',ListV.Name)>0 then
begin
for iloop := 0 to ListV.Items.Count-1do
begin
ListV.SetFocus;
ListV.Items[iloop].Selected:=true;
OpenTable('select * from TGB_JGBPB where BH0= '+QuotedStr(ListV.Items.Item[iloop].SubItems[0])+' order by XM0',AQ);
for i := 1 to AQ.RecordCountdo
begin
ProBar.Position:=0;
ProBar.Max:=AQ.RecordCount;
for n := 1 to ZD.Count-1do
begin
JG[i,n]:=JG[i,n]+KToZero(AQ.fieldbyname(ZD.Strings[n]).AsString);
end;
Application.ProcessMessages;
ProBar.Position:=i;
AQ.Next;
end;
end;
end;
//************
if pos('SY',ListV.Name)>0 then
begin
for iloop := 0 to ListV.Items.Count-1do
begin
OpenTable('select * from TGB_SYBPB where BH0= '+QuotedStr(ListV.Items.Item[1].SubItems[0])+' order by XM0 ',AQ);
for i := 1 to AQ.RecordCountdo
begin
ProBar.Position:=0;
ProBar.Max:=AQ.RecordCount;
for n := 0 to ZD.Count-2do
begin
SY[i,n]:=SY[i,n]+KToZero(AQ.fieldbyname(ZD.Strings[n]).AsString);
end;
Application.ProcessMessages;
ProBar.Position:=i;
AQ.Next;
end;
end;
end;
end;
function HZThread.OpenTable(StrSQL: String;
AQ: TADOQuery): Integer;
begin
with AQdo
begin
Close;
SQL.Clear;
SQL.Add(StrSQL);
Open;
Result:=RecordCount
end;
end;
procedure HZThread.Execute;
begin
repeat
DateHZ;
until Terminated;
{ Place thread code here }
end;
function HZThread.KToZero(K: String): Extended;
begin
if TryStrToFloat(K,Result) then
else
Result:=0;
end;
constructor HZThread.Create(LVName: TListView;
AQuery: TADOQuery;
PBarName: TProgressBar);
begin
ListV:=LVName;
AQ:= AQuery;
ProBar:=PBarName;
Inherited Create(True);
end;
end.
unit ThreadHZ;
interface
uses
Classes,ComCtrls,ADODB,SysUtils,Dialogs,Forms;
type
ReSZ=array of Extended;
HZThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
public
ListV:TListView;
AQ:TADOQuery;
ProBar:TProgressBar;
constructor Create(LVName:TListView;AQuery:TADOQuery;PBarName:TProgressBar);
//构造函数
function DateHZ():ReSZ;
Function OpenTable( StrSQL: String;
AQ : TADOQuery ) : Integer;
function KToZero(K:String):Extended;
//将数据转换为 Extended类型
end;
implementation
function HZThread.DateHZ(): ReSZ;
var
iloop,i,n:Integer;
JG:array [1..28,1..21] of Extended;
//1..27
SY:array [1..28,1..21] of Extended;
ZD:TStringList;
begin
for i := 1 to 28do
begin
for n := 1 to 21do
begin
JG[i,n]:=0;
end;
end;
ZD:=TStringList.Create;
ZD.Add('C');
ZD.Add('D');ZD.Add('E');ZD.Add('F');ZD.Add('G');ZD.Add('H');ZD.Add('I');
ZD.Add('J');ZD.Add('K');ZD.Add('L');ZD.Add('M');ZD.Add('N');ZD.Add('O');
ZD.Add('P');ZD.Add('Q');ZD.Add('R');ZD.Add('S');ZD.Add('T');ZD.Add('U');
ZD.Add('V');ZD.Add('W');ZD.Add('X');
//**************
if pos('JG',ListV.Name)>0 then
begin
for iloop := 0 to ListV.Items.Count-1do
begin
ListV.SetFocus;
ListV.Items[iloop].Selected:=true;
OpenTable('select * from TGB_JGBPB where BH0= '+QuotedStr(ListV.Items.Item[iloop].SubItems[0])+' order by XM0',AQ);
for i := 1 to AQ.RecordCountdo
begin
ProBar.Position:=0;
ProBar.Max:=AQ.RecordCount;
for n := 1 to ZD.Count-1do
begin
JG[i,n]:=JG[i,n]+KToZero(AQ.fieldbyname(ZD.Strings[n]).AsString);
end;
Application.ProcessMessages;
ProBar.Position:=i;
AQ.Next;
end;
end;
end;
//************
if pos('SY',ListV.Name)>0 then
begin
for iloop := 0 to ListV.Items.Count-1do
begin
OpenTable('select * from TGB_SYBPB where BH0= '+QuotedStr(ListV.Items.Item[1].SubItems[0])+' order by XM0 ',AQ);
for i := 1 to AQ.RecordCountdo
begin
ProBar.Position:=0;
ProBar.Max:=AQ.RecordCount;
for n := 0 to ZD.Count-2do
begin
SY[i,n]:=SY[i,n]+KToZero(AQ.fieldbyname(ZD.Strings[n]).AsString);
end;
Application.ProcessMessages;
ProBar.Position:=i;
AQ.Next;
end;
end;
end;
end;
function HZThread.OpenTable(StrSQL: String;
AQ: TADOQuery): Integer;
begin
with AQdo
begin
Close;
SQL.Clear;
SQL.Add(StrSQL);
Open;
Result:=RecordCount
end;
end;
procedure HZThread.Execute;
begin
repeat
DateHZ;
until Terminated;
{ Place thread code here }
end;
function HZThread.KToZero(K: String): Extended;
begin
if TryStrToFloat(K,Result) then
else
Result:=0;
end;
constructor HZThread.Create(LVName: TListView;
AQuery: TADOQuery;
PBarName: TProgressBar);
begin
ListV:=LVName;
AQ:= AQuery;
ProBar:=PBarName;
Inherited Create(True);
end;
end.