Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Thread and local variables
Tue, Sep 18 2018 3:56 PMPermanent Link

Ronald

Hi,
Just to be absolutely sure...
If I do this in a EWB module:

procedure TgdbaModule.EWBModuleExecute(Request: TEWBServerRequest);
var
UserNo                                      :string;
begin
UserNo:=Request.RequestParams.Values['userno'];
end;

Then the variable UserNo is unique for each call? The next call does not overwrite it?

Thanks,
Ronald
Wed, Sep 19 2018 1:23 AMPermanent Link

Michael Dreher

Ronald wrote:

  // Then the variable UserNo is unique for each call? The next call does not overwrite it?

Thread functions and any of the routines they call have their own local variables for
different thread invocations. So yes.

Michael Dreher
Wed, Sep 19 2018 3:00 AMPermanent Link

Ronald

Michael Dreher wrote:
<
Thread functions and any of the routines they call have their own local variables for
different thread invocations. So yes.
>
Thanks. Now I have 2 more questions:

1: If I would call a function by reference with that variable, would that still OK? Or can other threads mess this up?
Like this:

procedure AddSomething(var aUserNo:string);  
begin
aUserNo:=aUserNo+'x';
end;

I assume I can do this, because the variable has its own address in memory, local for the calling function.

2. But if aUserNo has not been initialized on beforehand in the calling function, would that be a problem?
Does it have an address in memory then? It is only declared in de the calling function, but not yet given a value.

Hope you understand what I mean.

Ronald
Wed, Sep 19 2018 6:35 AMPermanent Link

Matthew Jones

So long as it is not using a global variable, then it will be good. Be careful though as some functions (like date/time formatting) often use a global buffer to operate.

As for assigning to aUserNo if it hasn't been initialized, that's a problem regardless of threads. It probably won't crash, but it probably won't do what you want either.
Wed, Sep 19 2018 12:41 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Ronald,

<< Then the variable UserNo is unique for each call? The next call does not overwrite it? >>

I'm late getting here, but just to confirm, yes, that is correct.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Sep 20 2018 5:31 AMPermanent Link

Ronald

Thanks all!

Ronald
Image