Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-06 Thread Salvatore Coppola via lazarus
I suppose is an hidden file in home or in .config
Salvatore

⁣Ottieni BlueMail per Android ​

Il giorno 4 Mag 2020, 00:41, alle ore 00:41, Bo Berglund via lazarus 
 ha scritto:
>I am porting a Windows service application to Linux ARM (RPi4).
>The Windows version is a service and as such its config data resides
>in the Registry below HKLM.
>The Linux version will be a Daemon and I would like as much of the
>code stay unaltered to avoid conversion bugs.
>
>Now I have read that the FPC TRegistry class is able to use the
>original commands for reading/writing the data by instead using some
>form of ini- or xml-file store on UNIX.
>
>The existing system written in Delphi2007 uses the following key
>structure:
>HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
>HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)
>
>But how does this work and where/how are the data actually stored in a
>Linux file system?
>
>I have tried to google this but my search skills are not good enough
>so I came up empty-handed
>
>Any insight on this very much appreciated.
>
>--
>Bo Berglund
>Developer in Sweden
>
>--
>___
>lazarus mailing list
>lazarus@lists.lazarus-ide.org
>https://lists.lazarus-ide.org/listinfo/lazarus
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Tony Whyman via lazarus


On 04/05/2020 11:05, Bo Berglund via lazarus wrote:

On Mon, 4 May 2020 10:25:42 +0100, Tony Whyman via lazarus
 wrote:


As to the filename issue: the xml file location is determined from the
Vendor Name and application name and relative to $HOME/.config - is that
really a problem?

First off:
I would NOT use the Registry ever for my new applications...

Instead I would use conf files in ini file format so I can read/write
them using the TIniFile or TMemIniFile classes.
If you are thinking of a new Linux app then I would agree. You only use 
TRegistry if its cross-platform and you need to use the registry under 
Windows.


But my task now is to port a Windows service program which is
controlling the scheduling of external equipment operations.

It is a Windows service and thus non-gui but it implements a socket
communications channel whereby existing Windows (Delphi) applications
can control it by writing config data and look for results etc.

We can no longer use the service application on Windows going forward
because of Microsoft changes to drivers we rely on etc.
So the idea is to convert the service application to FPC/Lazarus and
then port it over to Linux.

So, being a service the server uses the Registry for all of its config
and task data on Windows and it would be simpler to port if I can
continue using that part of the system.
At first look TRegistry seems to handle this.

But there is a problem:

On Windows HKLM is a *global* hive and by what I hear here the
TRegistry implementation for Linux uses xml files instead and that is
no problem, provided that there is one only such file in use.
But if they are application specific then it will not work.
We use different applications to manage the server via the Registry
and this would not work then.


The model is like Windows in that you have both system wide and per user 
hives. If you want a group of applications under the same user to access 
the same registry XML file then you need to make sure that they are 
using the same AppConfigDir. You can ensure this by adding Vendor Name 
and Application Name callbacks so that your applications all use the 
same AppConfigDir.


The issue that you may find is when one process makes a change to the 
XML file that needs to be picked up by the others. Then you may need 
some IPC signalling to make that happen. There may even be a need for a 
lockfile to avoid race conditions - but then you would have the same 
problem with .conf files.




For example we have a local server configuration utility apart from
the TCP/IP socket connection and if I understand it right this
application would operate on a *different* xml file altogether so
whatever changes it makes to the "registry" will not be available to
the service application...

If this is so I need to reconsider the use of TRegistry and dig down
into changing to conf files (which can be global)...
Much more code to convert in that case.


--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Luca Olivetti via lazarus

El 4/5/20 a les 11:25, Tony Whyman via lazarus ha escrit:

TRegistry is a very useful way of saving dynamic configuration data 
(e.g. mainform co-ordinates) in order to preserve them from one program 
session to another - and to do so in a cross-platform manner. IMHO. it 
would be a significant loss if it was to be deprecated. I use it all the 
time.


I use TIniPropStorage for that (and more).
There's also TXMLPropStorage and TJSonPropStorage but I never used those.

Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Bo Berglund via lazarus
On Mon, 4 May 2020 10:25:42 +0100, Tony Whyman via lazarus
 wrote:

>As to the filename issue: the xml file location is determined from the 
>Vendor Name and application name and relative to $HOME/.config - is that 
>really a problem?

First off:
I would NOT use the Registry ever for my new applications...

Instead I would use conf files in ini file format so I can read/write
them using the TIniFile or TMemIniFile classes.

But my task now is to port a Windows service program which is
controlling the scheduling of external equipment operations.

It is a Windows service and thus non-gui but it implements a socket
communications channel whereby existing Windows (Delphi) applications
can control it by writing config data and look for results etc.

We can no longer use the service application on Windows going forward
because of Microsoft changes to drivers we rely on etc.
So the idea is to convert the service application to FPC/Lazarus and
then port it over to Linux.

So, being a service the server uses the Registry for all of its config
and task data on Windows and it would be simpler to port if I can
continue using that part of the system.
At first look TRegistry seems to handle this.

But there is a problem:

On Windows HKLM is a *global* hive and by what I hear here the
TRegistry implementation for Linux uses xml files instead and that is
no problem, provided that there is one only such file in use.
But if they are application specific then it will not work.
We use different applications to manage the server via the Registry
and this would not work then.

For example we have a local server configuration utility apart from
the TCP/IP socket connection and if I understand it right this
application would operate on a *different* xml file altogether so
whatever changes it makes to the "registry" will not be available to
the service application...

If this is so I need to reconsider the use of TRegistry and dig down
into changing to conf files (which can be global)...
Much more code to convert in that case.

-- 
Bo Berglund
Developer in Sweden

-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Tony Whyman via lazarus
I often use TRegistry for cross-platform configuration data and you 
should be able to use it and avoid having to maintain different Linux 
and Windows versions.


Under Linux, you are using TXMLRegistry and this saves registry data in 
an application specific XML file. There can be both a common XML file 
(HKEY_LOCAL_MACHINE) and a per user XML file (HKEY_CURRENT_USER). The 
file's location is always relative to the path returned by 
Sysutils.GetAppConfigDir. I create separate TRegistry instances for 
HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER.


In the per user case, the filename is $HOME/.config/name>//xml.reg, where the vendor and application names 
are set by the callbacks OnGetVendorName (default '') and 
OnGetApplicationName (default exe file name) in Sysutils.


Note that the HKEY_LOCAL_MACHINE xml file is probably in a read only 
location unless you are root.


Otherwise, you just keep the same keynames and values as in Windows 
registry. As reported elsewhere, if you insist on having more than one 
instance of TRegistry (for the same root key) at any one time, you 
cannot assume that the keyname is preserved when switching between 
TRegistry instances, and must (for now) always set the keyname before 
accessing a value.


On 03/05/2020 23:40, Bo Berglund via lazarus wrote:

I am porting a Windows service application to Linux ARM (RPi4).
The Windows version is a service and as such its config data resides
in the Registry below HKLM.
The Linux version will be a Daemon and I would like as much of the
code stay unaltered to avoid conversion bugs.

Now I have read that the FPC TRegistry class is able to use the
original commands for reading/writing the data by instead using some
form of ini- or xml-file store on UNIX.

The existing system written in Delphi2007 uses the following key
structure:
HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)

But how does this work and where/how are the data actually stored in a
Linux file system?

I have tried to google this but my search skills are not good enough
so I came up empty-handed

Any insight on this very much appreciated.


--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Michael Van Canneyt via lazarus



On Mon, 4 May 2020, Bart via lazarus wrote:


On Mon, May 4, 2020 at 12:41 AM Bo Berglund via lazarus
 wrote:

structure:



HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)


The *nix way is to use .conf files (basically ini-files) for that.
IIRC you have no control over where the xml file (with the registry
keys) is placed.
There are some issues with the xml implementation of the registry.
Most important: TRegIniFile is completely broken and as of 3.2
deprecated on non-windows platforms.
Also, when you have 2 keys opened at the same time, reading/writing
may go to/from the wrong key:
https://bugs.freepascal.org/view.php?id=36842

For a cross-platform application I wouldn't use TRegistry myself.


Me neither. They're completely windows centric.

That said, I don't even use them on windows.

I use .ini files everywhere for the simple reason they can be edited with any
editor and easily copy & pasted. You can comment out things. 
Basically, they're much easier to use & maintain than the registry.


Michael.
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Tony Whyman via lazarus
Firstly, the question is about TRegistry and not TRegIniFile. On a *nix 
platform TRegistry is implemented using TXMLRegistry and not TRegIniFile.


You should only have a single instance of a TXMLRegistry in any one 
program no matter how many times you create a TRegistry object - they 
all point to the same instance. From a quick check of the code, it looks 
like the problem identified in the bug report  is fairly obvious - the 
current key state is held in TXMLRegistry rather than TRegistry. The fix 
should be to hold the current key state in TRegistry and call 
TXMLRegistry.SetKey before every get or put call on TXMLRegistry (from 
TRegistry).


TRegistry is a very useful way of saving dynamic configuration data 
(e.g. mainform co-ordinates) in order to preserve them from one program 
session to another - and to do so in a cross-platform manner. IMHO. it 
would be a significant loss if it was to be deprecated. I use it all the 
time.


As to the filename issue: the xml file location is determined from the 
Vendor Name and application name and relative to $HOME/.config - is that 
really a problem?


TXMLRegistry writes are normally flushed to disk after every write. Two 
program instances using the same registry keys can get in each other's 
way with one over-writing the other's updates - but then that is also 
true of .conf and .ini files - and even the Windows registry.


On 04/05/2020 08:29, Bart via lazarus wrote:

On Mon, May 4, 2020 at 12:41 AM Bo Berglund via lazarus
 wrote:

structure:
HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)

The *nix way is to use .conf files (basically ini-files) for that.
IIRC you have no control over where the xml file (with the registry
keys) is placed.
There are some issues with the xml implementation of the registry.
Most important: TRegIniFile is completely broken and as of 3.2
deprecated on non-windows platforms.
Also, when you have 2 keys opened at the same time, reading/writing
may go to/from the wrong key:
https://bugs.freepascal.org/view.php?id=36842

For a cross-platform application I wouldn't use TRegistry myself.

Bart

--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Bart via lazarus
On Mon, May 4, 2020 at 12:41 AM Bo Berglund via lazarus
 wrote:
> structure:

> HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
> HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)

The *nix way is to use .conf files (basically ini-files) for that.
IIRC you have no control over where the xml file (with the registry
keys) is placed.
There are some issues with the xml implementation of the registry.
Most important: TRegIniFile is completely broken and as of 3.2
deprecated on non-windows platforms.
Also, when you have 2 keys opened at the same time, reading/writing
may go to/from the wrong key:
https://bugs.freepascal.org/view.php?id=36842

For a cross-platform application I wouldn't use TRegistry myself.

Bart
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Cross-platform using TRegistry - how to?

2020-05-04 Thread Rolf Wetjen via lazarus

Hi Bo,

looking into xregreg.inc:

procedure TRegistry.SysRegCreate;
var s : string;
begin
  s:=includetrailingpathdelimiter(GetAppConfigDir(GlobalXMLFile));
  ForceDirectories(s);
  FSysData:=TXMLRegistryInstance.GetXMLRegistry(s+XFileName);
  TXmlRegistry(FSysData).AutoFlush:=False;
end;

It's stored in a xml file.

Rolf


--
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


[Lazarus] Cross-platform using TRegistry - how to?

2020-05-03 Thread Bo Berglund via lazarus
I am porting a Windows service application to Linux ARM (RPi4).
The Windows version is a service and as such its config data resides
in the Registry below HKLM.
The Linux version will be a Daemon and I would like as much of the
code stay unaltered to avoid conversion bugs.

Now I have read that the FPC TRegistry class is able to use the
original commands for reading/writing the data by instead using some
form of ini- or xml-file store on UNIX.

The existing system written in Delphi2007 uses the following key
structure:
HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)

But how does this work and where/how are the data actually stored in a
Linux file system?

I have tried to google this but my search skills are not good enough
so I came up empty-handed

Any insight on this very much appreciated.

-- 
Bo Berglund
Developer in Sweden

-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus