TLoadingThread =
class(TThread)
private
FQueryCallback: TProc<TUniQuery>;
FThreadQuery: TUniQuery;
FThreadFilter, FThreadStation:
String;
FThreadConn: TUniConnection;
procedure Reset;
protected
procedure Execute;
override;
public
constructor Create(
const AQueryCallback: TProc<TUniQuery>);
property Filter:
String read FThreadFilter
write FThreadFilter;
property Station:
String read FThreadStation
write FThreadStation;
procedure DoSync;
end;
implementation
procedure TLoadingThread.Execute;
var
SQLFormula:
string;
begin
inherited;
Reset;
FThreadConn := TUniConnection.Create(
nil);
try
FThreadConn.ProviderName := '
SQL Server';
FThreadConn.Server := MSSQLHost;
FThreadConn.Username := MSSQLUser;
FThreadConn.Password := MSSQLPass;
FThreadConn.Database := MSSQLDB;
try
SQLFormula := '
if Object_ID(''
MOBILE_Kunden_' + FThreadStation + #39 + '
) is not null Drop Table MOBILE_Kunden_' +
FThreadStation;
SQLExec(FThreadConn, SQLFormula);
SQLFormula := '
Select distinct Kunden_Nr as kdn, Sortierfeld as Sortierfeld_Vorschau, Name1 as Name1_Vorschau, Strasse as Strasse_Vorschau, PLZ as PLZ_Vorschau, Ort as Ort_Vorschau, 1 as Selected into MOBILE_Kunden_'
+ FThreadStation + '
from Kundenst where ' + FThreadFilter;
SQLExec(FThreadConn, SQLFormula);
SQLFormula := '
Select name1_Vorschau as Name1, kdn, Sortierfeld_Vorschau as sortierfeld, Strasse_Vorschau as strasse, PLZ_Vorschau as plz, Ort_Vorschau as ort, selected from Mobile_Kunden_'
+ FThreadStation + '
order by Sortierfeld';
FThreadQuery := GetQuery(FThreadConn, SQLFormula);
DoSync;
except
on E:
Exception do
begin
// das ist eigentlich nicht so schön, zum Entwicklen reicht's aber!
ShowMessage(E.ClassName + '
error raised, with message : ' + E.
Message);
end;
end;
finally
Reset;
end;
end;
constructor TLoadingThread.Create(
const AQueryCallback: TProc<TUniQuery>);
begin
inherited Create(False);
FQueryCallback := AQueryCallback;
end;
procedure TLoadingThread.DoSync;
begin
if Assigned(FQueryCallback)
then
Synchronize(FQueryCallback(FThreadQuery));
end;
procedure TLoadingThread.Reset;
begin
if Assigned(FThreadQuery)
then
begin
FThreadQuery.Free;
FThreadQuery :=
nil;
end;
if Assigned(FThreadConn)
then
begin
FThreadConn.Free;
FThreadConn :=
nil;
end;
end;
procedure TFrmKundenwahl.OnQueryCallback(AQuery: TUniQuery);
begin
// Diese Callback hier musste dann per TLoadingThread.Create(Self.OnQueryCallback); übergeben
Self.L_Treffer.Text := IntToStr(AQuery.RecordCount) + '
Treffer';
AQuery.AfterScroll := Self.QueryAfterScroll;
Self.BS_Vorschau.DataSet.Assign(AQuery);
Self.BS_Vorschau.DataSet.Open;
end;