Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 8 Jahren, 5 Monaten
Letzter Beitrag:
vor 8 Jahren, 5 Monaten
Beteiligte Autoren:
GWhiting, Fabrice Harari

WinDev: Variables scoped within a thread only (but not local)

Startbeitrag von GWhiting am 08.02.2010 20:50


Having used a variety of other development environments, I'm struggling to find the right scope for variables that I want to be specific to each thread (in a client/server socket app).

I can obviously setup local variables within a procedure, but I want scope within the thread. If I create globals, they are shared across all other threads.

In other environments I'd create an object class with instance variables and have an instance of the object within each thread.

The closest thing I can find to this is the "class" type, although these don't appear to have variables so I guess I need to setup properties for each of my variables... and keep some of them private?

Can anyone please confirm if the above is the "preferred" approach, or if I'm far wide of the desired approach in WinDev?

Many thanks,

Graeme Whiting


Hi Graeme...

I'm not sure I'm following...

You are saying:
In other environments I'd create an object class with instance variables and have an instance of the object within each thread.

What prevents you to do the same thing here?
- Create a class
- at the beginning of the thread instantiate a dynamic object of that class

If I understood what you want,that should do it...

Best regards

von Fabrice Harari - am 08.02.2010 22:32
Hi Fabrice,

That's the validation I was looking for - basically that I'm following the correct route. When I declare the dynamic object, can this be in the global declarations, and then in the method that runs when the thread is created, I can create a new instance of the object?

In the WinDev help is suggests using:

to declare the object: is object

to instantiate the object: = allocate

So, in my global variables I have:

gcLogtofile is object Logtofile dynamic

...and in the first method of my thread I have:

gcLogtofile=allocate Logtofile

However, Windev tells me I've got a "Syntax error on Logtofile" (underlined above)

In one of the Windev examples it shows using = new , which doesn't show a syntax error... but does it work?

Many thanks,


von GWhiting - am 09.02.2010 08:40

I don't know why you would want to declare the object in a totally separate place than where you instantiate it. It wouldn't be usable without being instantiated anyway, so why complicate things?

Now about the 'allocate' keyword, I don't know, I've always use the 'new' keyword so it may be a help file error

Best regards

von Fabrice Harari - am 09.02.2010 13:35
Hi Fabrice,

My approach solved the problem, basically I declare the object in the global declarations of my group of procedures, but then only instantiate it at the start of the procedure that handles comms to a single socket.

This means that I can refer to the global variable, but it relates to a specific instance of the object just within my single socket handling procedure - i.e. other threads running the same procedure all refer to their own instance of the object. Each instance can therefore have properties that are specific to it.

An example of this is where I'm writing out a log file per thread - it means that each thread can create it's unique file and retain a file pointer without having to pass the pointer around to all procedures that might want to perform some logging. In the case of the file pointer, I'm actually using a member within the class.

Hope this makes sense, and it provides a more true OOP approach than just using procedures/groups of procedures that have no concept of separate instances.

Another example is where I've written my own XML procedures for WinDev Mobile and I have several threads that need to use them, without corrupting each other's variables that are used for parsing the XML. By converting this to a class with members/properties I can have multiple instances of the XML procedures, all doing their own thing. By the way, this is all to remove the massive footprint of the in-built XML dll on Windows Mobile that means our app won't run on several devices.

So, the reason for declaring the object globally is to give it scope, and the reason for instantiating it within a local procedure is to give it a distinct instance.

Many thanks,


von GWhiting - am 09.02.2010 20:18
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.