So, hier mal der Source wie ichs gemeint habe:
Delphi-Quellcode:
type
TThreadWaitStruct = record
Finished : Boolean;
Critical : TCriticalSection;
ErrorMsg : String;
end;
PThreadWaitStruct = ^TThreadWaitStruct;
function GThreadFunc(Parameter: PThreadWaitStruct): Integer;
begin
//Critical Section jetzt schon entern damit die Schleife im Hauptthread
//beim Enter wartet und nicht 100% CPU auslastet
Parameter.Critical.Enter;
MessageBox(0, PChar(Parameter.ErrorMsg), 'Der Fehler', MB_OK or MB_ICONINFORMATION);
Parameter.Finished := True;
Parameter.Critical.Leave;
end;
procedure ShowError(AErrorMsg: String);
var
lThreadID : Cardinal;
lStruct : TThreadWaitStruct;
lFinished : Boolean;
begin
lStruct.Finished := False;
lStruct.Critical := TCriticalSection.Create;
lStruct.ErrorMsg := AErrorMsg;
BeginThread(nil, 0, @GThreadFunc, @lStruct, 0, lThreadID);
repeat
lStruct.Critical.Enter;
lFinished := lStruct.Finished;
lStruct.Critical.Leave;
until lFinished;
lStruct.Critical.Free;
end;
Man ruft also einfach "ShowError" auf und übergibt den anzuzeigenden Fehler.