Solved

global variable

Posted on 1998-08-21
11
317 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using FastMM4... should I enable MMX option? 9 76
Delphi TcxGrid group footer summary 3 210
Strange behavior when a form is closed 6 51
Firemonkey webbrowser scrollbars ? 1 29
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now