Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Communicate between different programs


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 11 - Last Post: Apr 5, 2018 12:35 AM Last Post By: Robert Triest
Lex Dean

Posts: 132
Registered: 3/26/07
Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2018 11:32 PM
a) I have a program that you may run more than one copy at the same time
b) It may run on Linix and windows
c) The program simulates as if it has communication between 2 or more MCU's. Gives visual representation of data in the MCU's

If I was in windows I would communicate between programs with the use of the registry (simple)

When you have a database (OBDC) you communicate with the support of Internet sockets so many programs uses the one database system
I do not want special set up requiring access to a database and the problems of Windows/Linux compatibility with the OBDC

How can use the same system that is Windows/Linux compatible?
Is their any quick solution?
Lex Dean
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 12:41 AM   in response to: Lex Dean in response to: Lex Dean
If I was in windows I would communicate between programs with the use of the registry (simple)
Use JSON file for the Data storage (Delphi has JSON parsers included)
For the communication I would try TCP or UDP Send/Recieve
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 1:24 AM   in response to: Robert Triest in response to: Robert Triest
Robert Triest wrote:
Use JSON file for the Data storage (Delphi has JSON parsers included)
For the communication I would try TCP or UDP Send/Recieve

Never used JSON so I have a little reading thanks
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 1:42 AM   in response to: Lex Dean in response to: Lex Dean
data-interchange formats - XML or YAML or JSON
These are my options I gess
JSON depends on Java
a) XML or YAML are Windows supported I guess, but no Linux support - is that correct
b) What level of java do I need to support a JSON data interchange process
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 2:10 AM   in response to: Lex Dean in response to: Lex Dean
JSON depends on Java
No.

a) XML or YAML are Windows supported I guess, but no Linux support - is that correct
No, JSON is just a file format (Plain Text) , like XML. Delphi has parsers (read/write) to work with JSON.
Some years ago people used XML to store data but now JSON is much more used.

Some JSON parsers can just convert (Serialize) Delphi Objects into a JSON format.
https://community.embarcadero.com/blogs/entry/how-to-convert-an-object-to-json-and-back-with-a-single-line-of-code-497

b) What level of java do I need to support a JSON data interchange process
None.

http://chapmanworld.com/2015/01/18/json-with-radstudio-delphi-or-c-builder/
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 2:58 AM   in response to: Robert Triest in response to: Robert Triest
JSON is run from behind XML so its lighter weight - That is good
Delphi simplifies the access to JSON for you

So I create a JSON - foo containing data in my code

Dose the program just request for foo and if not there make up foo for the next program to seek
What happens?
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 4:20 AM   in response to: Lex Dean in response to: Lex Dean
Dose the program just request for foo and if not there make up foo for the next program to seek
What happens?

JSON file on disk --> Program A Read JSON --> Do something with the data (objects) --> Make new JSON --> Save on Disk --> Sent JSON via TCP/UDP --> Program B receive JSON --> Display

In both programs you have to program your special JSON reader/writer (using the same units/objets of course) and the communication (TCP/UDP) betwwen the two programs..
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 2:47 AM   in response to: Lex Dean in response to: Lex Dean
Normally you want to make a JSON string from a list of objects..
Here some code I found:

http://www.danieleteti.it/how-to-serialize-a-tlist-of-objects-with-delphi/

I believe the Mormot system has a good JSON system included based on TCollection..

Ah..
http://wiki.freepascal.org/Streaming_JSON

Edited by: Robert Triest on Apr 4, 2018 11:50 AM
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 3:19 AM   in response to: Robert Triest in response to: Robert Triest
Thanks for your time Robert Triest
this is clearly the solution I need

I got a few trials to get this up and running but it looks relatively simple for my task
I do not have XE, Just Delphi 7
so I will try http://wiki.freepascal.org/Streaming_JSON

Thanks
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 6:05 AM   in response to: Lex Dean in response to: Lex Dean
I do not have XE, Just Delphi 7
Pitty, because the latest version has a Linux compiler and
I think your program could be done using these JSON and TCP/UDP components
so it runs also on (non GUI) Linux.
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2018 6:04 PM   in response to: Robert Triest in response to: Robert Triest
Can I ask a question

Why has no one made a JSON DLL that works something similar to Windows - Registry Editor
Windows, Linux, Android versions that are inter comparable and used the same
The ODBC interface suppose to be like this but windows made changes so this does not get owned by Windows so it can be used by all OS's
Yes all versions get the data stored in a File.

Key's
Strings,
Int64,
TimeStamp,
Boolean.
lazy storage system to file (delayed) so the program can get on using the processor for other immediate things first

What do you think?

I personally think Delphi should have a version that identifies windows and Linux and automatically adapts its self to call the OS appropriately
And tools that meet in the middle would help this to happen and set a standard just like PC compatible was a standard.
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Communicate between different programs  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 5, 2018 12:35 AM   in response to: Lex Dean in response to: Lex Dean
Why has no one made a JSON DLL that works something similar to Windows - Registry Editor
A Windows DLL is also a compiled program only usable in... Windows.
There is no way you compile a program for one OS and use it on another OS,
only if there is also a runtime program running in the background acting like an interpreter.
That is how JAVA is working.

You can try to write such "registry" like tool but what is the difference? To change a field in JSON is like:

JO := TJSONObject.ParseJSONValue(TFile.ReadAllText(JsonFilename)) as TJSONObject;
JoX := JO.GetValue<Integer>('AllCategories.Category[0].subCategory[0].products[0].colors.color[0].views.view[0].x');
WriteLn('The old value of "x" is ', JoX);
WriteLn('Changing value of "x" to "123"');
JoPair := JO.GetValue<TJSONObject>('AllCategories.Category[0].subCategory[0].products[0].colors.color[0].views.view[0]').Get('x');
JoPair.JsonValue.Free;
JoPair.JsonValue := TJSONNumber.Create(123);
WriteLn('The new value of "x" is ', JoPair.JsonValue.Value);


and in Registry:

RegistryEntry:= TRegistry.Create(KEY_READ);
RegistryEntry.RootKey:= HKEY_LOCAL_MACHINE;
RegistryEntry.Access:= KEY_WRITE;
RegistryEntry.OpenKey('Software\MyCompanyName\MyName\',True);
RegistryEntry.CloseKey();
RegistryEntry.Free;


Remember, JSON (like XML) can nest fields with many levels, like records of a database table,
as you see above AllCategories.Category[0].subCategory[0] while Registry is just plain Key=Value

I personally think Delphi should have a version that identifies windows and Linux and automatically adapts its self to call the OS appropriately

Delphi has now a few special compilers for IOS, Android, Windows and MACOS.
When you compile a Windows program in Delphi it will use the Windows libraries to
create the program using all visual and non visual code from the Windows OS.
(Buttons, Listboxes, Communication)
When you run this program on a MAC of course it will not work because all these
parts are different implemented on the MAC OS. You need access to the OS
to compile against it.

For IOS and Android it is even harder because they run on another chipset (ARM)

To "solve" this problem Delphi went on the route to create different compilers
and for the graphical part (all visual parts, like buttons and listboxes) they
created FireMonkey where the visual parts are just drawn on the screen by
a OpenGL engine. (available on all OS'ses)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02