Hallo,
Ich habe in einer Klasse einen Thread integriert der die Summe eines Tabellenfeldes ermittel.
Rufe ich den Thread einzel auf. Klappt es wunderbar. Rufe ich den Thread mehrmals "Parralell" auf ist mein Rückgabe wert 0.
Environment
Delphi 7
Datenbank Postgres SQl 7
ZEOSLIB Komponenten
Hat hier jemand eine Idee zu ?
------------- Klassendeklaration -----------
<PRE>
unit TSummaryAuftrag1;
interface
uses
{$Include uses.pas} Classes,sysutils,rbtypes,windows,forms;
type ESummaryErloesart = Class( Exception );
type TStateChangeEvent = Procedure( State : TThreadStatus ) of object;
type
TCustomSummaryErloesart = Class( Tobject )
private
FErloesarten : string;
FBetrag : Currency;
FTeile : Integer;
FGruppenName : string;
Fauftragsid : Integer;
FState : TThreadStatus;
FOnStateChange: TStateChangeEvent;
FAOwner : TComponent;
FTag : Integer;
protected
procedure SetState(const Value: TThreadStatus);
public
constructor Create( AOwner : Tcomponent; DbConnection : TZConnection );
published
property Erloesarten : string read FErloesarten Write FErloesarten;
property Betrag : Currency read FBetrag Write FBetrag;
property Teile : Integer read FTeile Write FTeile;
property GruppenName : string read FGruppenName Write FGruppenName;
property auftragsid : Integer read Fauftragsid Write Fauftragsid;
property State : TThreadStatus read FState Write SetState;
property Tag : Integer read Ftag Write Ftag;
property OnStateChange : TStateChangeEvent read FOnStateChange Write FOnStateChange;
end;
type
ThSummaryAuftrag = class(TThread)
public
constructor Create( AOwner : Tcomponent; DbConnection : TZConnection; SummaryErloesart : TCustomSummaryErloesart; TableName : string );
private
FqryAuftrag : TZReadOnlyQuery;
FSummaryErloesart : TCustomSummaryErloesart;
{ Private-Deklarationen }
protected
procedure Execute; override;
procedure updateResults;
end;
type
TSummaryErloesart = Class( TCustomSummaryErloesart)
private
FThread : ThSummaryAuftrag;
FTimeout : Integer;
procedure WaitFor;
protected
public
procedure execute;
constructor Create( AOwner : Tcomponent; dbConnection : TZConnection; TableName : string );
destructor destroy;
published
property Erloesarten ;
property Betrag ;
property Teile ;
property GruppenName ;
property auftragsid ;
property State ;
property OnStateChange ;
end;
implementation
constructor ThSummaryAuftrag.Create( AOwner : Tcomponent; DbConnection : TZConnection; SummaryErloesart : TCustomSummaryErloesart; TableName : string );
begin
inherited Create( True );
freeonTerminate := True;
FSummaryErloesart := SummaryErloesart;
FqryAuftrag := TZReadOnlyQuery.Create( Nil );
with FqryAuftrag do
begin
Name := 'FqryAuftrag';
Connection := dbConnection;
SQL.Add('select sum( preis1 ) as betrag , sum(menge) as teile from ' + TableName + ' where (auftrags_id = :AUFTRAGSID or auftrags_id = :NUM) and erloesart in (' + #39+'10' + #39 +')');
ParamCheck := True;
with Params.Add do begin
Name := 'AUFTRAGSID';
end;
with Params.Add do begin
Name := 'NUM';
end;
Options := [doCalcDefaults];
end;
end;
procedure ThSummaryAuftrag.updateResults;
var
t : Integer;
begin
FqryAuftrag.refresh;
with FSummaryErloesart do
begin
T := FqryAuftrag.FieldByName('teile').asInteger;
if t = 0 then
sleep(1);
Teile := t;
Betrag := FqryAuftrag.FieldByName('betrag').asCurrency;
State := tsReady;
end;
end;
procedure ThSummaryAuftrag.Execute;
begin
while not Terminated do
Ich habe in einer Klasse einen Thread integriert der die Summe eines Tabellenfeldes ermittel.
Rufe ich den Thread einzel auf. Klappt es wunderbar. Rufe ich den Thread mehrmals "Parralell" auf ist mein Rückgabe wert 0.
Environment
Delphi 7
Datenbank Postgres SQl 7
ZEOSLIB Komponenten
Hat hier jemand eine Idee zu ?
------------- Klassendeklaration -----------
<PRE>
unit TSummaryAuftrag1;
interface
uses
{$Include uses.pas} Classes,sysutils,rbtypes,windows,forms;
type ESummaryErloesart = Class( Exception );
type TStateChangeEvent = Procedure( State : TThreadStatus ) of object;
type
TCustomSummaryErloesart = Class( Tobject )
private
FErloesarten : string;
FBetrag : Currency;
FTeile : Integer;
FGruppenName : string;
Fauftragsid : Integer;
FState : TThreadStatus;
FOnStateChange: TStateChangeEvent;
FAOwner : TComponent;
FTag : Integer;
protected
procedure SetState(const Value: TThreadStatus);
public
constructor Create( AOwner : Tcomponent; DbConnection : TZConnection );
published
property Erloesarten : string read FErloesarten Write FErloesarten;
property Betrag : Currency read FBetrag Write FBetrag;
property Teile : Integer read FTeile Write FTeile;
property GruppenName : string read FGruppenName Write FGruppenName;
property auftragsid : Integer read Fauftragsid Write Fauftragsid;
property State : TThreadStatus read FState Write SetState;
property Tag : Integer read Ftag Write Ftag;
property OnStateChange : TStateChangeEvent read FOnStateChange Write FOnStateChange;
end;
type
ThSummaryAuftrag = class(TThread)
public
constructor Create( AOwner : Tcomponent; DbConnection : TZConnection; SummaryErloesart : TCustomSummaryErloesart; TableName : string );
private
FqryAuftrag : TZReadOnlyQuery;
FSummaryErloesart : TCustomSummaryErloesart;
{ Private-Deklarationen }
protected
procedure Execute; override;
procedure updateResults;
end;
type
TSummaryErloesart = Class( TCustomSummaryErloesart)
private
FThread : ThSummaryAuftrag;
FTimeout : Integer;
procedure WaitFor;
protected
public
procedure execute;
constructor Create( AOwner : Tcomponent; dbConnection : TZConnection; TableName : string );
destructor destroy;
published
property Erloesarten ;
property Betrag ;
property Teile ;
property GruppenName ;
property auftragsid ;
property State ;
property OnStateChange ;
end;
implementation
constructor ThSummaryAuftrag.Create( AOwner : Tcomponent; DbConnection : TZConnection; SummaryErloesart : TCustomSummaryErloesart; TableName : string );
begin
inherited Create( True );
freeonTerminate := True;
FSummaryErloesart := SummaryErloesart;
FqryAuftrag := TZReadOnlyQuery.Create( Nil );
with FqryAuftrag do
begin
Name := 'FqryAuftrag';
Connection := dbConnection;
SQL.Add('select sum( preis1 ) as betrag , sum(menge) as teile from ' + TableName + ' where (auftrags_id = :AUFTRAGSID or auftrags_id = :NUM) and erloesart in (' + #39+'10' + #39 +')');
ParamCheck := True;
with Params.Add do begin
Name := 'AUFTRAGSID';
end;
with Params.Add do begin
Name := 'NUM';
end;
Options := [doCalcDefaults];
end;
end;
procedure ThSummaryAuftrag.updateResults;
var
t : Integer;
begin
FqryAuftrag.refresh;
with FSummaryErloesart do
begin
T := FqryAuftrag.FieldByName('teile').asInteger;
if t = 0 then
sleep(1);
Teile := t;
Betrag := FqryAuftrag.FieldByName('betrag').asCurrency;
State := tsReady;
end;
end;
procedure ThSummaryAuftrag.Execute;
begin
while not Terminated do