Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread Jean SUZINEAU via fpc-pascal
I just add a small program to illustrate the type cast between signed 
and unsigned:


var
   si: ShortInt;
begin
 si:= -127;
 WriteLn( 'si ', si);
 WriteLn( 'Byte(si) ', Byte(si));
 si:= -1;
 WriteLn( 'si ', si);
 WriteLn( 'Byte(si) ', Byte(si));
end.

gives

$ ./project1
si -127
Byte(si) 129
si -1
Byte(si) 255
$



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread Bart via fpc-pascal
On Wed, Jun 16, 2021 at 2:26 PM Jean SUZINEAU via fpc-pascal
 wrote:

> I think there is a way to do this with a single program.

Using Lazarus IDE I tried to set Execution level to
"requireAdministrator", but then the program simply would not run (it
would not ask for the admin password), so in the end I just used
something like:

uses
  WinUtils;

procedure CheckIsAdmin;
begin
  if not WinUtils.IsWindowsAdmin then
  begin
writeln('This program requires administrator priviliges.');
writeln;
Halt;
  end;
end;

Bart


-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread Jean SUZINEAU via fpc-pascal

Le 16/06/2021 à 00:31, James Richters via fpc-pascal a écrit :

In order to change the value I want to change, I need to run my program as 
administrator,  is there a way to change to administrator with a request from 
within the program?
I guess I could make just a small program that changes the key I want to change 
and launch that in administrator mode from the main program.. just curious is 
there was a way to do it with a single program.
I've never done this  but I think you dig about privilege elevation on 
Microsoft Developer Network website:

https://docs.microsoft.com/en-us/search/?terms=privilege%20elevation

I think there is a way to do this with a single program.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread Bart via fpc-pascal
On Wed, Jun 16, 2021 at 2:21 PM Jean SUZINEAU via fpc-pascal
 wrote:

> I guess that what was meaning Bart by hardcat is that you need to
> transtype the result this way:
> var dw: DWord;
> begin
>   dw:= DWord( Registry.ReadInteger(...)) ;

Indeed.
This is a lossless operation.

-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread Jean SUZINEAU via fpc-pascal

Le 16/06/2021 à 00:31, James Richters via fpc-pascal a écrit :

Thanks for the help, it's working fine using readinteger  I guess as long as I 
don't have any values large enough to need the most significant digit that 
would work...


I guess that what was meaning Bart by hardcat is that you need to 
transtype the result this way:

var dw: DWord;
begin
 dw:= DWord( Registry.ReadInteger(...)) ;

Integer and DWord have the same memory size (4 bytes) so this way you 
don't "lose" the most significant bit, you get your real DWord.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread Bart via fpc-pascal
On Wed, Jun 16, 2021 at 9:08 AM James Richters via fpc-pascal
 wrote:

>
> >You can have a look too at TRegDataType type, it seems there is nothing 
> >special for DWord.
>
>
>
> I got the list of functions you mentioned in Lazarus.. Here are all the ones 
> that can read:

As I said before, it is compatible with Delphi.
See: 
http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Win.Registry.TRegistry_Methods


-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread James Richters via fpc-pascal
>You can have a look too at TRegDataType type, it seems there is nothing
special for DWord.
 
I got the list of functions you mentioned in Lazarus.. Here are all the ones
that can read:
function ReadCurrency(const Name: UnicodeString): Currency;
function ReadCurrency(const Name: String): Currency;
function ReadBinaryData(const Name: UnicodeString; var Buffer; BufSize:
Integer): Integer;
function ReadBinaryData(const Name: String; var Buffer; BufSize:
Integer): Integer;
function ReadBool(const Name: UnicodeString): Boolean;
function ReadBool(const Name: String): Boolean;
function ReadDate(const Name: UnicodeString): TDateTime;
function ReadDate(const Name: String): TDateTime;
function ReadDateTime(const Name: UnicodeString): TDateTime;
function ReadDateTime(const Name: String): TDateTime;
function ReadFloat(const Name: UnicodeString): Double;
function ReadFloat(const Name: String): Double;
function ReadInteger(const Name: UnicodeString): Integer;
function ReadInteger(const Name: String): Integer;
function ReadInt64(const Name: UnicodeString): Int64;
function ReadInt64(const Name: String): Int64;
function ReadString(const Name: UnicodeString): UnicodeString;
function ReadString(const Name: String): string;
procedure ReadStringList(const Name: UnicodeString; AList: TStrings;
ForceUtf8: Boolean=False);
procedure ReadStringList(const Name: String; AList: TStrings);
function ReadStringArray(const Name: UnicodeString):
TUnicodeStringArray;
function ReadStringArray(const Name: String): TStringArray;
function ReadTime(const Name: UnicodeString): TDateTime;
function ReadTime(const Name: String): TDateTime;
 
as far as I can see I need to use something like ReadBinaryData ???  does
anyone have an example on how to do that? It looks like it's wanting a
buffer of some sort. or can I just pass it my Dword variable somehow?  It
seems over complicated
 
I still find it strange there is no ReadDword and ReadQword when those two
are an entire third of possible registry entries.. 
If you go to RegEdit,  there are only 6 kinds of registry entries:
String Value
Binary Value
DWord
Qword
Multi-String Value
Expandable String Value
 
Maybe all these other ones like Float and Int64 are for other versions of
windows?? As far as I can see it's impossible to define a float in the
windows registry, with windows 10 professional 64 bit anyway.  Are there
other kinds of 'Registries'  that all these functions would be useful for
other than THE Registry (referring to the windows registry)?
 
Am I missing something?  Does Linux have a registry or something? I thought
it was a windows thing. Why aren't there easy ways to read and write Dwords
and Qwords when there are so many of them in the windows registry?
 
Is all this for something other than the windows registry?  The fact that
the functions do not match what is possible with the windows registry is
making me think I have the wrong thing all together.  Are there functions to
use the windows registry in the Windows unit?
 
James
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-15 Thread James Richters via fpc-pascal
Thanks for the help, it's working fine using readinteger  I guess as long as I 
don't have any values large enough to need the most significant digit that 
would work...

In order to change the value I want to change, I need to run my program as 
administrator,  is there a way to change to administrator with a request from 
within the program?
I guess I could make just a small program that changes the key I want to change 
and launch that in administrator mode from the main program.. just curious is 
there was a way to do it with a single program.

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-15 Thread Bart via fpc-pascal
On Tue, Jun 15, 2021 at 2:44 PM Jean SUZINEAU via fpc-pascal
 wrote:

> I'm not sure which one will best match the DWord type.
You'll have to use the Integer / Int64 variant and hardcats it to DWord/QWord.

IIRC this is Delphi compatible.

Of course it is peanuts to implement Read/WriteD/QWord() yourself if
you subclass TRegistry (and call the subclass TRegistry).
I have a Windows only implementation of TRegistry which actually
implements this.
(My implementation of the registry does not support TRegIniFile b.t.w.)

-- 
Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-15 Thread James Richters via fpc-pascal
I'm not using Lazarus.
 
I guess I can try to make a sample program with it just to see what the
options are.
 
It seems like there should be a ReadDword, and ReadQword because there are
an awful lot of Dword and Qword types in the registry.
 
James
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TRegistry documentation

2021-06-15 Thread Jean SUZINEAU via fpc-pascal
In Lazarus , in your source code, you can can "Ctrl + Click" on 
Registry.ReadString and it will bring you to the declaration of 
TRegistry.ReadString in unit Registry. There you will find there are 
other methods like ReadInteger, ReadInt64, ReadBinaryData. I'm not sure 
which one will best match the DWord type.


You can have a look too at TRegDataType type, it seems there is nothing 
special for DWord.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] TRegistry documentation

2021-06-15 Thread James Richters via fpc-pascal
Is there documentation for TRegistry somewhere?  I've been searching for
information on it, and so far I've only been able to find:
 
https://wiki.freepascal.org/fcl-registry
and
http://docwiki.appmethod.com/appmethod/1.17/codeexamples/en/TRegistry_(Objec
t_Pascal)
 
They kind of get me started but I'm looking for a complete list of all
functions and how to use them. 
The main problem I am having is that my program is crashing with an error
217:
An unhandled exception occurred at $004124A4:
ERegistryException: Invalid registry data type: "Type"
 
I'm pretty sure it's because the registry key I am interested is not a
string, it's a Dword. but all the examples I find use 
Registry.WriteString() and Registry.ReadString()
 
I've been able to use Registry.GetValueNames() to get the names of all the
keys. and now that I have that, I'm thinking there should be a way to find
out what type of key they all are and more functions to read and write the
different types of keys.   
 
Anyone know where I can find this information?
 
James
 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal