Autor Beitrag
Michael Farlaub
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18


D6 PE, Indy 9
BeitragVerfasst: Mo 17.03.08 15:42 
Hallo,

ich benutze mehrer Threads um Sachen aus dem Netz zu laden.
Im Hauptthread habe ich eine kleine Funktion die Strings bearbeitet.
Wie kann ich sie denn aus den einzelnen Threads nutzen?
Muss ich das in die Thread dekleration igrndwie einbauen?
Meine schaut so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
TMyThreadA = class(TThread)
        private
        protected
        procedure execute; override;
        public
 end;

thx


Michael

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt

_________________
Was ist denn jetzt los?
PeterPain
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83



BeitragVerfasst: Mo 17.03.08 15:45 
Mir ist nicht ganz klar was du meinst, willst du die methode eines Threads in einem anderen nutzen? Willst du eine beliebige prozedur aus einer beliebigen Unit aus mehreren Threads aufrufen?

Ansich stellt man das genauso an, wie auch ohne Threads, man muss nur aufpassen, dass es keine Synchronisierungsprobleme gibt.


gruss
Michael Farlaub Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18


D6 PE, Indy 9
BeitragVerfasst: Mo 17.03.08 15:53 
im hauptthread hab ich folgende funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function SAR(sSrc, sLookFor, sReplaceWith: string ): string;
var
  nPos,
  nLenLookFor : integer;
begin
  nPos        := Pos( sLookFor, sSrc );
  nLenLookFor := Length( sLookFor );
  while(nPos > 0)do
  begin
    Delete( sSrc, nPos, nLenLookFor );
    Insert( sReplaceWith, sSrc, nPos );
    nPos := Pos( sLookFor, sSrc );
  end;
  Result := sSrc;
end;


und diese will ich jetzt aus einem anderen thread benutzen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TMyThreadB.execute;
str : string;
begin
.
.
.
str:= sar(str,' ',''); <- es kommt undefinierter Bezeicher.
.
.
.


thx

_________________
Was ist denn jetzt los?
PeterPain
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83



BeitragVerfasst: Mo 17.03.08 15:58 
Hi,

du hast die funktion nicht "im Hauptthread", sondern einfach in einer Unit (sonst würde vor der funktion der Typ des Thread stehen). Um diese nun aus anderen Units nutzen zu können, musst du sie im interface teil der Unit, in der sie auch implementiert ist, deklarieren.

gruss
Michael Farlaub Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18


D6 PE, Indy 9
BeitragVerfasst: Mo 17.03.08 16:07 
super, danke!

jetzt klappts!

_________________
Was ist denn jetzt los?
PeterPain
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83



BeitragVerfasst: Mo 17.03.08 16:09 
user profile iconMichael Farlaub hat folgendes geschrieben:
super, danke!



Rechnung folgt :P