SaLz
asked on
Multi Threading With options.
hi, I need to create a thread with options like a function.
String1,String2
it will pass that though the thread and return the results
Thread('String1','String2' );
Sal.
String1,String2
it will pass that though the thread and return the results
Thread('String1','String2'
Sal.
ASKER
hi, is there anyway of putting the results in another thread than in the same area that was called?
i am not sure what you mean, may be something like this
type
TYourThread = class(TThread)
private
s1, s2: String;
rs: PChar;
protected
procedure Execute; override;
end;
procedure TYourThread.Execute;
begin
StrPCopy(rs, s1+s2);
end;
procedure SomeProcedure;
var
forResult: array [0..200] of char;
begin
with TYourThread.Create(true) do begin
s1 := 'String1';
s2 := 'String2';
rs := forResult;
Suspended := false;
WaitFor;
ShowMessage(forResult);
Destroy;
end
end
type
TYourThread = class(TThread)
private
s1, s2: String;
rs: PChar;
protected
procedure Execute; override;
end;
procedure TYourThread.Execute;
begin
StrPCopy(rs, s1+s2);
end;
procedure SomeProcedure;
var
forResult: array [0..200] of char;
begin
with TYourThread.Create(true) do begin
s1 := 'String1';
s2 := 'String2';
rs := forResult;
Suspended := false;
WaitFor;
ShowMessage(forResult);
Destroy;
end
end
ASKER
lol you just posted the same comment lol, what I ment was.
we have a Function like
Thread('String1',String2')
now it will execute the code..
TYourThread.Execute;
and then it will use another one to display the code
TYourThread.Display;
so we start with a button1click..
procedure TForm1.Button1Click(Sender : TObject);
begin
Thread('String1',String2') ;
end;
it when then go to the execute..
procedure TYourThread.Execute;
begin
rs := s1+s2;
end;
to display it
procedure TYourThread.Display;
begin
form1.memo1.lines.add(rs);
end;
I have this thread but for some reason can't get it 2 work..
type
TThread = class(TThread)
private
fUrl, fAction, fRow,fItem : string;
procedure ShowPage;
protected
public
property Url : string read fUrl write fUrl;
property Item : string read fItem write fItem;
property Action : string read fAction write fAction;
property Row : string read fRow write fRow;
procedure Execute; override;
destructor Destroy; override;
end;
procedure TThread.Execute;
begin
inherited;
rs:=Http.Get(Url);
Synchronize(ShowPage);
end;
procedure TThread.ShowPage;
var
Thread1,Thread2 : TThread;
begin
form1.memo1.lines.add(rs);
end;
procedure TForm2.Button1Click(Sender : TObject);
var
Thread1,Thread2 : TThread;
begin
Thread1 := TThread.Create(True);
Thread1.Url := 'http://www.google.com/;
Thread1.Action:='add';
Thread1.Resume;
end;
if u understand what I mean? Run>>>Execute>>>Display, it needs to be multi threaded, so lots can be done at the same time.
we have a Function like
Thread('String1',String2')
now it will execute the code..
TYourThread.Execute;
and then it will use another one to display the code
TYourThread.Display;
so we start with a button1click..
procedure TForm1.Button1Click(Sender
begin
Thread('String1',String2')
end;
it when then go to the execute..
procedure TYourThread.Execute;
begin
rs := s1+s2;
end;
to display it
procedure TYourThread.Display;
begin
form1.memo1.lines.add(rs);
end;
I have this thread but for some reason can't get it 2 work..
type
TThread = class(TThread)
private
fUrl, fAction, fRow,fItem : string;
procedure ShowPage;
protected
public
property Url : string read fUrl write fUrl;
property Item : string read fItem write fItem;
property Action : string read fAction write fAction;
property Row : string read fRow write fRow;
procedure Execute; override;
destructor Destroy; override;
end;
procedure TThread.Execute;
begin
inherited;
rs:=Http.Get(Url);
Synchronize(ShowPage);
end;
procedure TThread.ShowPage;
var
Thread1,Thread2 : TThread;
begin
form1.memo1.lines.add(rs);
end;
procedure TForm2.Button1Click(Sender
var
Thread1,Thread2 : TThread;
begin
Thread1 := TThread.Create(True);
Thread1.Url := 'http://www.google.com/;
Thread1.Action:='add';
Thread1.Resume;
end;
if u understand what I mean? Run>>>Execute>>>Display, it needs to be multi threaded, so lots can be done at the same time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thxs :D
TYourThread = class(TThread)
private
s1, s2: String;
rs: String;
protected
procedure Execute; override;
end;
procedure TYourThread.Execute;
begin
rs := s1+s2;
end;
begin
with TYourThread.Create(true) do begin
s1 := 'String1';
s2 := 'String2';
Suspended := false;
WaitFor;
ShowMessage(rs);
Destroy;
end
end;