//ein Doppelklick aufs Memo würde den Test starten
type
TForm1 =
class(TForm)
OracleSession1: TOracleSession;
//Verbindung im OI eingestellt und connected auf true; threadsafe auch auf True
Memo1: TMemo;
procedure OracleQueryThreadError(Sender: TOracleQuery;
ErrorCode: Integer;
const ErrorMessage:
String);
procedure OracleQueryThreadExecuted(Sender: TOracleQuery);
procedure OracleQueryThreadFinished(Sender: TOracleQuery);
procedure OracleQueryThreadRecord(Sender: TOracleQuery);
procedure Memo1DblClick(Sender: TObject);
private
{ Private-Deklarationen }
FRecorded:Integer;
procedure WMUser(
var Msg:TMessage);
message WM_User;
procedure StartQuery;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OracleQueryThreadError(Sender: TOracleQuery;
ErrorCode: Integer;
const ErrorMessage:
String);
begin
memo1.Lines.add('
Error: '+inttostr(ErrorCode)+'
'+ErrorMessage);
end;
procedure TForm1.OracleQueryThreadExecuted(Sender: TOracleQuery);
begin
memo1.lines.add('
Executed');
end;
procedure TForm1.OracleQueryThreadFinished(Sender: TOracleQuery);
begin
memo1.lines.add('
Finished - '+inttostr(FRecorded)+'
Records');
postmessage(
handle,WM_User,0,integer(Sender));
//start new
end;
procedure TForm1.OracleQueryThreadRecord(Sender: TOracleQuery);
begin
inc(FRecorded);
end;
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
StartQuery;
end;
procedure TForm1.WMUser(
var Msg: TMessage);
var OracleQuery:TOracleQuery;
begin
OracleQuery:=TOracleQuery(msg.LParam);
//while OracleQuery.ThreadIsRunning do sleep(1); //mit der Zeile passiert es deutlich seltener, aber das ist ja auch keine Lösung
OracleQuery.Free;
StartQuery;
end;
procedure TForm1.StartQuery;
var OracleQuery:TOracleQuery;
begin
FRecorded:=0;
OracleQuery:=TOracleQuery.Create(self);
OracleQuery.OnThreadExecuted:=self.OracleQueryThreadExecuted;
OracleQuery.OnThreadRecord:=self.OracleQueryThreadRecord;
OracleQuery.OnThreadFinished:=self.OracleQueryThreadFinished;
OracleQuery.OnThreadError:=self.OracleQueryThreadError;
OracleQuery.Threaded:=true;
OracleQuery.ThreadSynchronized:=true;
OracleQuery.Session:=OracleSession1;
ORacleQuery.SQLW:='
Select * from all_users';
OracleQuery.Execute;
end;
end.