Autor Beitrag
TheNeon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 408

Windows
VS2010 C#
BeitragVerfasst: Do 15.05.03 10:08 
ich habe nun einige Threads ans Laufen bekommen, doch folgendes will nicht funktionieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
function vorlesen(p:Pointer):Integer;
var  voice: OLEVariant;
begin 
  result := 0; 
  if vorlesen_running = TRUE then begin 
    EnterCriticalSection(cs); 
    try
      voice := CreateOLEObject('SAPI.SpVoice');
      voice.Speak(Form1.Memo1.text, 0);
    finally 
      LeaveCriticalSection(cs); 
    end; 
  end; 
  EndThread(0);
end;

procedure TForm1.Button9Click(Sender: TObject);
var vorlesen_wert:LongWord;
begin 
  vorlesen_wert:=1;
  if vorlesen_running=false then begin
    vorlesen_thread:=BeginThread(nil,0, addr(Vorlesen), nil,0,vorlesen_wert);
    if vorlesen_thread<>0 then vorlesen_running:=true;
  end
  else begin
        TerminateThread(vorlesen_thread,0);
  end;
  
end;


und zwar bekomme ich folgende Fehlermeldung, sobald ich den Button anklicke:
[...] raised OleException. CoInitialize wurde nicht aufgerufen. [...]

wie kann ich dieses Problem lösen?

DANKE


Zuletzt bearbeitet von TheNeon am Fr 16.05.03 00:56, insgesamt 1-mal bearbeitet
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 15.05.03 10:14 
Schau dir mal dieses Topic an.
TheNeon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 408

Windows
VS2010 C#
BeitragVerfasst: Do 15.05.03 10:18 
Tino hat folgendes geschrieben:
Schau dir mal dieses Topic an.


:oops: habs auch gerade entdeckt :roll:

allerdings hat der Kollege genau dasselbe Problem wie ich, aber noch keine Lösung :cry:
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 15.05.03 12:04 
wie wäre es, wenn du einfach das machst, was in der Fehlermeldung steht CoInitialize aufrufen? :roll:
TheNeon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 408

Windows
VS2010 C#
BeitragVerfasst: Do 15.05.03 12:51 
Luckie hat folgendes geschrieben:
wie wäre es, wenn du einfach das machst, was in der Fehlermeldung steht CoInitialize aufrufen? :roll:


:D hab ich ja, aber es bringt nix ...... oder vielleicht sollte ich erstmal fragen, wo ich es denn genau aufrufen soll ?! :roll: Ich habs nämlich bei
initialization und finalization aufgerufen gehabt :?
TheNeon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 408

Windows
VS2010 C#
BeitragVerfasst: Fr 16.05.03 00:38 
so, ich habs nun ....... etwas Glück und rumprobieren .....

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
function vorlesen(p:Pointer):Integer;
begin 
  result := 0; 
  CoInitialize(nil); 
    try
      Form1.Button9.Caption:='Abbruch';
      voice.Speak(Form1.Memo1.text, 0);
    finally
      Form1.Button9.Caption:='Vorlesen';
      vorlesen_running:=false;
      CoUnInitialize; 
    end; 
  EndThread(0);
end;

procedure TForm1.Button9Click(Sender: TObject);
var vorlesen_wert:LongWord;
begin 
  vorlesen_wert:=1;
  if vorlesen_running=false then begin
    voice := CreateOLEObject('SAPI.SpVoice');
    vorlesen_thread:=BeginThread(nil,0, addr(Vorlesen), nil,0,vorlesen_wert);
    if vorlesen_thread<>0 then vorlesen_running:=true;
  end
  else begin
    TerminateThread(vorlesen_thread,0);
    Button9.Caption:='Vorlesen';
    vorlesen_running:=false;
  end;
end;