Solved

global variable

Posted on 1998-08-21
11
318 Views
Last Modified: 2010-08-05
How can i under D3 in WIN95/WIN NT4.0 define a global variable ?
I have several exe-files. The first one will create the global variable and set to an integer.
When the next exe-file is started it will ask the global variable and depending on its value do something.
 
0
Comment
Question by:titz
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1337417
You can't make a variable global between different programs.

I suggest you write
1. the variable out to a file (e.g. an INI file), database
or
2. pass the value on the command line (given to the 2nd program when you run it)
or
3.  Wait until 2nd program starts, then 1st program talked to it via DDE, OLE or another protocol.

#2 is probably best for you - quickest and easiest
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337418
As Answers2000 mentioned that's a solution and maybe the one that doesn't need much coding..., but if you want it to be without any files this can be done only using pointers...At least that's what I think so..Crrect me if I'm wrong =)

/Viktor
0
 
LVL 1

Expert Comment

by:pjdb
ID: 1337419
Not really pointer since the memory is not shared between instances. However, you can also share memory by mapping files in memory.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Expert Comment

by:rickpet
ID: 1337420
Why not just send a custom message back and forth???simplier than memory mapped file...cleaner than registry/ini file

Rick
0
 
LVL 1

Author Comment

by:titz
ID: 1337421
i want not to write to a file, because this can make problems.  e.b. if the pc is turned off (without shut down), or loss of voltage.
The 2nd program will not run parallel to the first, perhaps after the first. Therefore i was looking for such a thing like a global variable in memory.

0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1337422
I really suggest this solution
2. pass the value on the command line (given to the 2nd program when you run it)

If you really want to share a variable between programs you need to use some form of IPC (interprocess communication), which includes DDE, OLE, Pipes etc.  The other option is to use some form of shared memory, but you will have synchronozation problems(what happens if one program changes the value while the other program accesses it), and this involves a fair amount of code.


0
 
LVL 1

Expert Comment

by:Greedy
ID: 1337423
Check out the WIN32 help file on Global Atom Table
I really don't have a clue what they would be used for as I have never used one...but it might get you into what you need ??

The Windows global atom table, which can contain up to 37 entries, is available to all applications. When an application places a string in the global atom table, the system generates an atom that is unique throughout the system. Any application that has the atom can obtain the string it identifies by querying the global atom table.

An application that defines a private clipboard-data format or DDE-data format for sharing data with other applications should place the format name in the global atom table. This technique prevents conflicts with the names of formats defined by the system or by other applications, and makes the identifiers (atoms) for the messages or formats available to the other applications.
0
 
LVL 5

Expert Comment

by:knowlton
ID: 1337424
How often will this GLOBAL variable be "created"...once at the beginning of execution or at the user's request, or what?  I think writing the file out to an .INI is your best bet, here.  The file I/O should be almost instantaneous...so power outages would be your least concern...the timing on that would have to be near perfect.
0
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
ID: 1337425
The idea in this case is to use some predefined memory block for storing shared variables between two apps. Here is a component that eases the task (a good example included):

http://bes.trendline.co.il/torry/vcl/system/sharedmm.zip 

Also you can write the value in the registry. Here is a simple component:

http://bes.trendline.co.il/torry/vcl/system/arregvar.zip

--Matvey
0
 
LVL 1

Author Comment

by:titz
ID: 1337426
i will try .
but i think that rickpet's comment shows the best way.
But i do not know how i can give him points ??
thanks for all who thought  about this problem
titz

0
 
LVL 3

Expert Comment

by:Matvey
ID: 1337427
If you wanted to give te points to someonme else, you should have rejected my answere and not award the points to me.

I was hoping I at least understood the question right: you need a way to store shared variables between two apps. My answere does answere this question, but if you wanted something else, or some other solution - my apologies...

c u, Matvey
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question