Re: [fpc-pascal] PPCJVM Android target and bass library function call issue

2019-08-12 Thread Jean SUZINEAU

Le 11/08/2019 à 11:43, Mgr. Janusz Chmiel a écrit :
Thank you very much for yours patience. The reason why I want to use 
my own little Internet radio player is The fact, that GUI is simple, 
many other radio apps are full of functions and of many buttons. I 
want to simple pause, play or stop.
I were wondering if a Raspberry Pi could be useful for you. Sure, the 
hardware part would be more difficult for you, and you may need an 
external battery, but it's easier to program than Android. Freepascal 
and Lazarus  can run  directly on it. I think that you can even make 
buttons with a single wire, it's called something like capacitive 
sensor. I made an electronic bagpipe with an arduino with split pins 
(attaches parisiennes) as keys. Each split pin is connected to the 
arduino through a single wire. when you touch the split pin, it changes 
its capacitance, and this can be detected by program.

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


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-14 Thread Jean SUZINEAU

Le 14/08/2019 à 01:41, James Richters a écrit :

Anyone have any thoughts on all this?


I'm busy for now, but I'll have a look as soon as possible.

Did you try to change your driver with Zadig (https://zadig.akeo.ie/) 
for your device 10CE:EB93 ?


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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-02 Thread Jean SUZINEAU

  
  
It seems that you can just remove
  {$LINKLIB c} in libusb.pas.



The libusb from libusb.info cannot be
  used because the functions it provides are different, and if you
  try to recompile a version before 1.0 like 0.9.4, it fails because
  Windows target was not yet supported by the library.
But on 
  https://sourceforge.net/projects/libusb-win32/  you find a port to
  Windows of libusb-0.1 to Windows.
I downloaded
  libusb-win32-bin-1.2.6.0.zip and extracted it. From the
  subdirectory libusb-win32-bin-1.2.6.0\bin\amd64 I copied
  libusb0.dll to the directory of TestFirmware.pas.
In LibUSB.pas I changed {$LINKLIB usb}
  to {$LINKLIB libusb0.dll}.
I got a few errors on compilation
  because of some changes in libusb.
The variables usb_error_errno and
  usb_error_type doesn't exist anymore in the library, for now I
  just comment them out:


  usb_error_errno : LongInt; //cvar; external; { from libusb }
usb_error_type  : LongInt; //cvar; external; { from libusb }

Two functions are not available any more, I commented them too:
 //Function usb_get_driver_np  (dev:PUSBDevHandle; TheInterface:Longint; Var name; namelen:LongInt) : Longint; cdecl; external;
 //Function usb_detach_kernel_driver_np(dev:PUSBDevHandle; TheInterface:Longint) : LongInt; cdecl; external;

This breaks in USB.pas the function USBGetDriver and the method TUSBInterface.Claim. For now I just made a small modification to comment the calls.
I join the diffs for libusb.pas and usb.pas .

With this modifications, I could compile successfully TestFirmware.pas. On execution I got this error:
E:\03_travail\libusb\test>TestFirmware.exe
Couldn't connect to device: Couldn't find firmware file "firmware.ihx" in search path ".:~/.testfirmware:(my path variable here):/etc/testfirmware". You might try to set the environment variable "TESTFIRMWAREFIRMWAREPATH".
which is normal because I don't have any test case with a firmware file for now.


  

 src/libusb.pas | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/libusb.pas b/src/libusb.pas
index 537f249..45331de 100644
--- a/src/libusb.pas
+++ b/src/libusb.pas
@@ -2,8 +2,9 @@ unit LibUSB;
 
 Interface
 
-{$LINKLIB c}
-{$LINKLIB usb}
+//{$LINKLIB c}
+//{$LINKLIB usb}
+{$LINKLIB libusb0.dll}
 
 {
   Automatically converted by H2Pas 0.99.15 from usb.h
@@ -265,8 +266,8 @@ Const
USB_ERROR_BEGIN = 50;
 
 Var (* errno : LongInt; cvar; external; { from libc } *)
-usb_error_errno : LongInt; cvar; external; { from libusb }
-usb_error_type  : LongInt; cvar; external; { from libusb }
+usb_error_errno : LongInt; //cvar; external; { from libusb }
+usb_error_type  : LongInt; //cvar; external; { from libusb }
 usb_error_str   : PChar;   cvar; external; { from libusb }
 
 Type PUSBBus = ^USBBus;
@@ -346,9 +347,9 @@ Function usb_device(Dev:PUSBDevHandle):PUSBDevice; cdecl; external;
 
 Function usb_get_busses : PUSBBus; cdecl; external;
 
-Function usb_get_driver_np  (dev:PUSBDevHandle; TheInterface:Longint; Var name; namelen:LongInt) : Longint; cdecl; external;
+//Function usb_get_driver_np  (dev:PUSBDevHandle; TheInterface:Longint; Var name; namelen:LongInt) : Longint; cdecl; external;
 
-Function usb_detach_kernel_driver_np(dev:PUSBDevHandle; TheInterface:Longint) : LongInt; cdecl; external;
+//Function usb_detach_kernel_driver_np(dev:PUSBDevHandle; TheInterface:Longint) : LongInt; cdecl; external;
 
 Implementation
 
 src/usb.pas | 23 +--
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/usb.pas b/src/usb.pas
index 62d2db3..8aa2e6e 100644
--- a/src/usb.pas
+++ b/src/usb.pas
@@ -28,7 +28,9 @@ Unit USB;
 Interface
 
 Uses
-  Classes, SysUtils, Baseunix, LibUSB;
+  Classes, SysUtils,
+  //Baseunix,
+  LibUSB;
 
 (*)
 (**  Procedural Interface  ***)
@@ -241,6 +243,8 @@ Uses PasLibUsbUtils,Math;
 Type TUSBExceptionType = Class of Exception;
 
 Function USBException(Proc:String;Ret:LongInt) : Exception;
+//duplicated from errno.inc included in unit BaseUnix
+const ESysETIMEDOUT= 110;
 Var Ex : TUSBExceptionType;
 Begin
   Case -Ret of
@@ -515,6 +519,7 @@ Begin
 End;
 
 Function USB_Send(Hnd:PUSBDevHandle;EP:LongInt;Const Buf;Length,Timeout:LongInt):LongInt;
+const ESysEAGAIN=11;
 Var Loops  : Integer;
 Sent   : LongInt;
 ToSend : LongInt;
@@ -540,7 +545,8 @@ WriteLn('Problem with usb_bulk_write: Result = ',Result,', usb_error_errno = ',u
 if (Loops > 0) and (usb_error_errno = ESysEAGAIN) then
   Begin
 Again := True;
-fpSelect(0,Nil,Nil,Nil,100);
+//fpSelect(0,Nil,Nil,Nil,100);
+Sleep(100);
   End;
   End
 else
@@ -573,11 +579,14 @@ Begin
 End;
 
 Function 

Re: [fpc-pascal] USB Human Interface Devices

2019-08-03 Thread Jean SUZINEAU

  
  
I've made another (unsuccessful) test, using libusb-compat (
  https://github.com/libusb/libusb-compat-0.1/wiki ). 

It's a compatibility layer which allows to use the new libusb
  1.xx through the old API of libusb 0.1
I get nearly the same results as with libusb-win32 (just "Bus:
  001" instead "Bus: bus-0"), maybe there's an error in my code.
If you want to test, I've put temporarily a zip of my test
  directory at http://mars42.com/test_libusb-compat.zip
  .
I got the dlls  through msys2 in this way:
You can download MSYS2 (http://www.msys2.org/ ) by
  http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20190524.exe

After complete installation, to install libusb type on the
  command line:
   pacman -S mingw64/mingw-w64-x86_64-libusb
and to install libusb-compat type :

 pacman -S mingw64/mingw-w64-x86_64-libusb-compat-git
  
  In subdirectory mingw64\bin of your installation you get:
     libusb-1.0.dll    the libusb dll from https://libusb.info/
     libusb-0-1-4.dll  the libusb-compat dll with version 0.1
  functions names, and which call libusb-1.0.dll

I'm not sure of the value of PATH_MAX to define in libusb.pas
  because  in the dll PATH_MAX is taken from limits.h (
  mingw64\x86_64-w64-mingw32\include\limits.h) where it's first
  defined to PATH_MAX=260 but if _POSIX_ is defined then it's
  redefined to 512. Of course this can create havoc in the
  definition of USBDevice if the pointer "bus : PUSBBus;" isn't
  defined at the right place in memory...
  
  For getting limits.h in subdirectory
  mingw64\x86_64-w64-mingw32\include , type :
   pacman -S mingw-w64-x86_64-headers-git

  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-03 Thread Jean SUZINEAU
I've forgotten to give the command line to compile (change 
"C:\lazarus\fpc\3.0.4\bin\x86_64-win64" to your fpc installation):


C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MObjFPC -Scghi -O1 -g -gl 
-l -vewnhibq -Filib\x86_64-win64 -Fu..\pas-libusb\src -Fu. 
-FUlib\x86_64-win64 -FE. -olsusb.exe lsusb.lpr



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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-03 Thread Jean SUZINEAU

  
  
With libusb-win32 I tried to make a small program to list the usb
  devices. 
  I discovered that the constant PATH_MAX had changed from 4096 in
  pas-libusb to 512 in libusb-win32-bin-1.2.6.0\include\lusb0_usb.h
  line 21 . This was causing an exception.
Now the program works but just output "Bus: bus-0" with no
  devices.
  libusb-win32 comes with two test programs testlibusb-win.exe and
  testlibusb.exe but don't find any devices too. I think that for
  some reason libusb-win32 doesn't work with recent Windows (I'm
  testing on Windows 10).
If you want to test, I've put temporarily a zip of my test
  directory at http://mars42.com/test_libusb-win32.zip .
I've seen https://sourceforge.net/p/libusb-win32/wiki/Home/ that
  they advice to migrate to the libusb-1.0 form
  http://libusb.info.


  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-03 Thread Jean SUZINEAU

  
  
I tried to make an import for libusb-1.0.22.7z from
  https://libusb.info/ .
  The import unit is very buggy but I could make a small program to
  list the usb devices.
  On my machine, it gives the same results that the example program
  libusb-1.0.22\examples\bin64\testlibusb.exe
  
  I've published this program and the import at
https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/lsusb
  You can get the corresponding binaries in this release
https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_08_03_lsusb
  .
I used lazarus to generate and compile the console app, but I
  verified, you can compile it from the command line, you'll just
  have to change the path to you freepascal installation.
I converted the libusb.h to libusb.pas with h2pas from the
  lazarus plugin H2Paswizard (
  https://wiki.freepascal.org/H2Paswizard ). 

You'll find the project for H2Paswizard at
https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/lsusb/include/libusb-1.0/project1.h2p
It's a very quick an dirty conversion. In h2paswizard I added  a
  rename from LIBUSB_CALL to WINAPI.
I got some problems with var parameters in
functions for example I needed to change
   function libusb_open(dev: Plibusb_device; var
  dev_handle:Plibusb_device_handle):longint;cdecl;external name
  'libusb_open';
  into
      function libusb_open(dev: Plibusb_device; dev_handle:PPlibusb_device_handle):longint;cdecl;external
  name 'libusb_open'; 

I think this can be fixed by tuning some details of the import.


  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-04 Thread Jean SUZINEAU

  
  
Zadig

I found a way to make  my test with libusb-win32 work. You just need to install a specific driver for the usb device you want to see.
This can be done using Zadig ( https://zadig.akeo.ie/ ). If you change the driver to "libusbK" or "libusb-win32" for a certain device with Zadig, it will appear with lsusb_libusb-win32\lsusb.exe .
But it doesn't change anything for the version with libusb-compat, lsusb_libusb-compat-msys2_mingw64\lsusb.exe wich shows nothing.
And it doesn't change anything either to the version with libusb, https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_08_03_lsusb which continue to show all the usb devices.
 
I have also tried libusbK ( http://libusbk.sourceforge.net/UsbK3/index.html ).
You can download it at  https://sourceforge.net/projects/libusbk/

There are delphi examples in the subdirectory bindings\examples_delphi .

They can be compiled easily with freepascal, you just need to compile in delphi mode.
For "bindings\examples_delphi\enumerate.dpr" you can use this command line ( from a cmd in the directory examples_delphi)
   C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MDelphi -Scghi -O1 -g -gl -l -vewnhibq -Filib\x86_64-win64 -Fu. -FUlib\x86_64-win64 -FE. -oenumerate.exe enumerate.dpr

For "bindings\examples_delphi\opendevice.dpr" it didn't found unit UExampleHelpers. I didn't investigated further but it seems you can find the unit at :
https://github.com/SimaWB/libusbkDelphi/blob/master/UExampleHelpers.pas
  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-04 Thread Jean SUZINEAU

  
  
Hi Hansi,

Le 04/08/2019 à 14:05, Johann Glaser a
  écrit :


  Thanks for your effort and please excuse my late reply, I was busy the
last few days.

With pleasure.
test1library.pas from branch
  "libusb-1.0" worked nearly out of the box.
  
  I nearly just needed to redefine extdecl from stdcall to cdecl as
  in Linux. 
  
  I copied (libusb-1.0.22)\MinGW64\dll\libusb-1.0.dll of 274 Ko to
  (pas-libusb branch libusb-1.0)\src\examples.
  In libusb.pas I removed {$LINKLIB c} and changed {$LINKLIB
  usb-1.0} to {$LINKLIB libusb-1.0.dll}
  I join my diff files. Lazarus made a few changes to
  test1library.lpi but I don't think they are important.
  I verified, test1library can be build with this command line:
C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe
  -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\x86_64-win64 -Fu..
  -Fu. -FUlib\x86_64-win64 -FE. -otest1library.exe test1library.pas

(eventually you need to create
  subdirectory lib\x86_64-win64 by hand)
Upon execution, I got this results:
:\03_travail\libusb\pas-libusb\src\examples>test1library.exe
Using libusb(x) v1.0.22.11312
Found 13 devices:
  Bus   1 Device  15: ID 10C4:EA60,  port:  14, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device  12: ID 28DE:2101,  port:   7, port path from HCD: 0->11->11, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   0: ID 8086:A2AF,  port:   0, Speed: Unknown
  Bus   1 Device  10: ID 0BB4:2C87,  port:   5, port path from HCD: 0->5->5, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   9: ID 0BB4:2C87,  port:   2, port path from HCD: 0->0->0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   4: ID 1C4F:0002,  port:   7, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   1 Device   2: ID 046D:C077,  port:   8, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   1 Device   8: ID 28DE:2000,  port:   1, port path from HCD: 0->1->1, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   7: ID 0BB4:0306,  port:   2, port path from HCD: 0->33, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device  11: ID 28DE:2101,  port:   6, port path from HCD: 0->128->128, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   5: ID 07CA:A110,  port:   5, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   6: ID 0BB4:2134,  port:   1, port path from HCD: 0->0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   1: ID 0BB4:2210,  port:  11, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)

E:\03_travail\libusb\pas-libusb\src\examples>

  

 src/libusboop.pas | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libusboop.pas b/src/libusboop.pas
index 6171c22..f8ab4ea 100644
--- a/src/libusboop.pas
+++ b/src/libusboop.pas
@@ -19,7 +19,8 @@ Unit LibUsbOop;
 
 {$macro on}
 {$ifdef windows}
-  {$define extdecl:=stdcall}
+  //{$define extdecl:=stdcall}
+  {$define extdecl:=cdecl}
 {$else}
   {$define extdecl:=cdecl}
 {$endif}
 src/libusb.pas | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/libusb.pas b/src/libusb.pas
index 3210331..f1fa053 100644
--- a/src/libusb.pas
+++ b/src/libusb.pas
@@ -43,7 +43,8 @@ Unit LibUsb;
 
 {$macro on}
 {$ifdef windows}
-  {$define extdecl:=stdcall}
+  //{$define extdecl:=stdcall}
+  {$define extdecl:=cdecl}
 {$else}
   {$define extdecl:=cdecl}
 {$endif}
@@ -52,8 +53,8 @@ Interface
 
 Uses CTypes;
 
-{$LINKLIB c}
-{$LINKLIB usb-1.0}
+//{$LINKLIB c}
+{$LINKLIB libusb-1.0.dll}
 
 (*
   Automatically converted by H2Pas 1.0.0 from libusb.h
 src/examples/test1library.lpi | 86 +--
 1 file changed, 41 insertions(+), 45 deletions(-)

diff --git a/src/examples/test1library.lpi b/src/examples/test1library.lpi
index 8de3135..95eb0b3 100644
--- a/src/examples/test1library.lpi
+++ b/src/examples/test1library.lpi
@@ -1,7 +1,7 @@
-
+
 
   
-
+
 
   
 
@@ -10,39 +10,35 @@
   
   
   
-  
-  
 
 
   
 
-
-  
-
 
   
 
 
   
-  
-  
 
 
   
-
 
   
+  
+  
+
+  
+
+  
+
+  
 
 
   
 
 
 
-
-
-
-
-
+
 
 
   
@@ -50,55 +46,53 @@
 
 
 
-
-
-
+
 
 
   
   
 
 
+
 
-
-
-
+
+
 
 
   
 
-
+
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 

Re: [fpc-pascal] USB Human Interface Devices

2019-08-04 Thread Jean SUZINEAU

  
  
Le 04/08/2019 à 14:07, Johann Glaser a écrit :

  Hi James!

Am Donnerstag, den 01.08.2019, 22:45 -0400 schrieb James Richters:

  
I understand it better now, but I've been out of town and haven't
been able to work on it.   I'm not sure what is meant by installing
development packages though.. I see libusb at https://libusb.info/ I
see where to download that.. but I don't know about development
packages?  As for LibC,   I'm not really sure where to find the
proper package for that.  I found
http://gnuwin32.sourceforge.net/packages/libc.htm.bak but I'm not
sure that is right, and again not sure about development package for
that.  I would really appreciate links to the exact packages I will
need to use for Windows.

  
  
I'm sorry that I can't help you here with these Windows-specific
questions.

Could somebody else please help out here?




  When you link to the dll, you can
remove the {$LINKLIB c}.
  But for now I haven't been able to make it work with a static
  link.


I added to project library search path in lazarus:
E:\03_travail\libusb\libusb-1.0.22\MinGW64\static\ wich contains
libusb-1.0.a
Then I changed {$LINKLIB usb-1.0} to {$LINKLIB libusb-1.0}, and
removed {$LINKLIB c}
(I join the diff files)
In this way, libusb-1.0.a is found by the compiler, but the
  dependencies  of libusb-1.0.a on C runtime and several Windows
  system function are not fullfilled and you get these errors (I
  join them in file Compiler_output.txt)
Some of them like WaitForSingleObject are provided by
  Kernel32.dll but I don't know which lib from MinGW64 to use to
  provide __imp_WaitForSingleObject.  
  Some others like atoi seem to be from the c runtime, but I haven't
  found  yet where are its libs (interesting link:
https://stackoverflow.com/questions/52376724/mingw-w64-c-versions-support
  )








  


  

 src/examples/test1library.lpi | 122 +-
 1 file changed, 74 insertions(+), 48 deletions(-)

diff --git a/src/examples/test1library.lpi b/src/examples/test1library.lpi
index 8de3135..42278b8 100644
--- a/src/examples/test1library.lpi
+++ b/src/examples/test1library.lpi
@@ -1,7 +1,7 @@
-
+
 
   
-
+
 
   
 
@@ -10,95 +10,110 @@
   
   
   
-  
-  
 
 
   
 
-
-  
-
 
   
 
 
   
-  
-  
 
 
   
-
 
   
+  
+  
+
+  
+
+  
+
+  
 
-
+
   
 
 
 
-
-
-
-
-
-
+
+
 
   
   
 
 
-
-
-
-
+
+
 
 
   
   
 
 
+
 
-
-
-
+
+
 
 
   
+  
+
+
+
+
+
+  
+  
+
+
+
+
+
+  
+  
+
+
+
+
+
+  
 
-
+
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
@@ -106,27 +121,27 @@
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
-
+
   
   
 
@@ -138,7 +153,7 @@
   
   
 
-
+
   
   
 
@@ -170,26 +185,37 @@
   
   
 
-
+
   
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  
 
   
   
-
+
 
   
 
 
   
+  
   
   
 
-
-  
-
-  
-  
-
   
   
 
 src/libusboop.pas | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libusboop.pas b/src/libusboop.pas
index 6171c22..f8ab4ea 100644
--- a/src/libusboop.pas
+++ b/src/libusboop.pas
@@ -19,7 +19,8 @@ Unit LibUsbOop;
 
 {$macro on}
 {$ifdef windows}
-  {$define extdecl:=stdcall}
+  //{$define extdecl:=stdcall}
+  {$define extdecl:=cdecl}
 {$else}
   {$define extdecl:=cdecl}
 {$endif}
 src/libusb.pas | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/libusb.pas b/src/libusb.pas

Re: [fpc-pascal] USB Human Interface Devices

2019-08-02 Thread Jean SUZINEAU

  
  

  Here are a few links about msvcrt:
  https://support.microsoft.com/en-us/help/154753/description-of-the-default-c-and-c-libraries-that-a-program-will-link
https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019
https://docs.microsoft.com/en-us/cpp/windows/redistributing-visual-cpp-files?view=vs-2019
https://www.microsoft.com/en-us/download/details.aspx?id=48145
  
  

I've tried to link to ucrt.lib from
  Windows 10 SDK but I got this error


  libusb.pas(359,0) Error: Invalid DLL C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x64\ucrt.lib, Dos Header invalid

From
  https://github.com/zeromq/libzmq/issues/2320 

it seems that static libraries produced
  by Microsoft tools cannot be used by the freepascal linker, 

so you need a static library produced
  by mingw.






  

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


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-16 Thread Jean SUZINEAU

Le 16/08/2019 à 12:23, James Richters a écrit :

Can you tell me where to get libusb_1.0_X86.dll  ?I had the x64 version 
from the sample Jean sent me, but I would like to make my program work on 32bit 
machines as well.
I think you can get it at 
https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z, 
subdirectory MinGW32/dll in the archive

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


Re: [fpc-pascal] += property bug?

2019-08-14 Thread Jean SUZINEAU

Le 14/08/2019 à 23:18, Martin a écrit :

inc(CALL_LVL [ LOCAL_CALL ],1)

Yes, "inc" does not work for properties. But neither does +=.


I agree and in the case of a property I think it would be cleaner to 
code an Inc method directly in the class, or eventually in a class 
helper, to write something like:


CALL_LVL [ LOCAL_CALL ].Inc(1)

In case of property, it's likely that you'll even be able to optimize 
the code, trimming some lines of the getter and the setter in you Inc 
method.


This said, I like to use += when I code in C++ for Arduino

I also think to the worse case, in Java, when you need to type something 
like a.SetX( a.GetX()+1) ...
And to Python, where in the code of the methods I need to prefix all 
accesses to methods and attributes of the object with "self." I have 
some code self. self. self. everywhere ...

Variant in Javascript: this. this. this.
Variant in PHP: $this. $this. $this.

Yes, I keep my FreePascal   ;-)


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


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-16 Thread Jean SUZINEAU

Le 16/08/2019 à 17:11, James Richters a écrit :

Can I even do threads in a console program?


Yes, you can.  I have in production some console code (worse: in a dll 
called by a console program written in 4gl (4js Genero www.4js.com)) 
with threads which compile unmodified  under Linux and Windows.


By writing a descendant of TThread it's relatively easy to write a 
thread in FreePascal ( 
https://wiki.freepascal.org/Multithreaded_Application_Tutorial ).
From your (non main) thread you can execute a procedure in the main 
thread by calling TThread.Synchronize.


From what I remember, the main problem in console is that you need to 
call regularly CheckSynchronize() ( from unit Classes ) from your 
program which run the main thread.
That will be simpler for you, in my case, I had  to export from my dll a 
pascal function calling CheckSynchronize() and call it regularly from 
the 4gl program with a timer ...


As far as I remember, it works just with a queue, when you call 
Synchronize you add a function call to the queue, and CheckSynchronize() 
read the queue and do the actual call of your function.






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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-17 Thread Jean SUZINEAU

  
  
Le 17/08/2019 à 15:00, James Richters a
  écrit :


  
  
  
  
Function
TLibUsbInterface.FindEndpoint(MatchFunc :
TLibUsbEndpointMatchMethod) : Plibusb_endpoint_descriptor;
MatchFunc(ED) is where the access
  violation occurs, but I can’t trace any further because I
  can’t find the function MatchFunc()   I just don’t understand
  where the actual function is. 

MatchFunc is a parameter (its type
is TLibUsbEndpointMatchMethod) of
  TLibUsbInterface.FindEndpoint.
To
  find which function is actually called, you should trace back
  where TLibUsbInterface.FindEndpoint
is called and what function is provided as parameter
MatchFunc.
It's likely you'll have to "climb
up" through several calls, may be that TLibUsbInterface.FindEndpoint
  has itself a parameter MatchFunc
If you use the debugger,
the callstack and a breakpoint just before the
offending call to MatchFunc
should help you to find from where comes your
MatchFunc.
I wouldn't be surprised
that it resolves somewhere to an overridden method
Match of an instance of a class derived from
TLibUsbDeviceMatchClass, likely
TLibUsbDeviceMatchVidPid.Match,
TLibUsbDeviceMatchVidPidSerial.Match or
TLibUsbInterfaceMatchNumAlt.Match from unit
libusbutil.pas
This can sound difficult 
for you at the beginning if you're not too much
accustomed with variables of type procedure and
inheritance, but after a few practice it's not that
complicated.
  
  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-17 Thread Jean SUZINEAU

Le 17/08/2019 à 17:10, Stefan V. Pantazi a écrit :
The obvious first thing to make sure is that the calling convention 
matches the library for the platform. I see that in 
https://github.com/Zaaphod/pas-libusb/blob/Hack/src/libusb.pas 9line 46)
the calling convention on Windows is cdecl (the stdcall is commented 
out). In libusbxhid, if I remember correctly, the calling convention 
for windows dlls is set to stdcall.

Yes it's curious.

Usually with Microsoft dlls from the Windows API, you use stdcall. Here 
with stdcall I get an error "Import library not found  for  libusb-1.0".


So I commented out the stcall changed it to cdecl.

This allows to compile without errors and test1library.pas works without 
error, it seems cdecl is the right calling convention for libusb-1.0.


One other thing is that debugging is much more tedious without an 
integrated debugger that allows you to step through each line before 
you can see which function call blows up with a segfault.
James works on the command line but fp.exe seems to integrate gdb.exe 
the same way that lazarus does, you nearly have the same shortcuts keys 
for debugging between Turbo Pascal 5.5, fp.exe and lazarus ...

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


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-17 Thread Jean SUZINEAU

Le 17/08/2019 à 19:39, James Richters a écrit :

I think maybe it is the calling convention...  First I tried to change 
libusboop.pas (libusb.pas is the old unit, libusboop.pas is the one it uses) to 
stdcall,  I was unable to compile it, I get an error
libusboop.pas(1456,28) Error: Incompatible types: got "" expected ""
libusboop.pas(1726) Fatal: There were 1 errors compiling module, stopping


Yes , this is because extdecl is defined a first time in libusb.pas line 
45 and a second time in libusboop.pas line 21.
If you change it in libusboop, you need to change it accordingly in 
libusb.pas.


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


Re: [fpc-pascal] Tests results of several pascal based JSON parsers

2019-08-30 Thread Jean SUZINEAU

Hello,
Le 30/08/2019 à 10:18, Anthony Walter a écrit :
I've posted a new page that tests the speed and correctness of several 
pascal based JSON parsers.


https://www.getlazarus.org/json/tests/



it seems you made a typo in your html,
JsonTools points to https://sourceforge.net/projects/lkjson/
and LkJSON points to https://github.com/sysrpl/JsonTools

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-28 Thread Jean SUZINEAU

Hello,

It seems you didn't initialized you critical section using 
InitCriticalSection.

The documentation of EnterCriticalSection :
https://www.freepascal.org/docs-html/rtl/system/entercriticalsection.html
The one of InitCriticalSection:
https://www.freepascal.org/docs-html/rtl/system/initcriticalsection.html

At the end, you need to call DoneCriticalSection  to release the 
associated system resources ( 
https://www.freepascal.org/docs-html/rtl/system/donecriticalsection.html).


Note: these is related to freepascal implementation of critical 
sections, in windows API, the function names are slightly different, 
InitializeCriticalSection/EnterCriticalSection/DeleteCriticalSection 
(https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-entercriticalsection)



Le 28/08/2019 à 01:50, James Richters a écrit :

One thing I wasn't able to duplicate however was the use of  
EnterCriticalsection(criticalSection);  and  
LeaveCriticalsection(criticalSection);  when writing to shared variables.  If I 
try to ever use EnterCriticalsection(criticalSection); in the read thread, My 
program just instantly locks up and I can't even break out of it.If I try 
to use it in the main program I instantly get
EAccessViolation: Access violation
   $7FFF18A2DF23
   $7FFF189E9BBC
   $7FFF189E9AD0
   $0001DCDA
   $0001D54B
   $0001218B  PROCESS_USB_DATA,  line 475 of WHB04B-4_test.pas
   $00012B37  SIMPLETERMINAL,  line 641 of WHB04B-4_test.pas
   $00012DDD  USE_MPG_DEVICE,  line 675 of WHB04B-4_test.pas
   $00012F93  main,  line 699 of WHB04B-4_test.pas
   $00012FE6
   $000100011350
   $00011980
   $7FFF17B47E94
   $7FFF18A4A251
Line 475 isEnterCriticalsection(criticalSection);
I left where I had the criticalsection stuff in the program but commented out.  
 It does seem to work fine without it though.. since the read, I am curious 
what I'm doing wrong, or if I need to do something else because I'm on Windows.


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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-28 Thread Jean SUZINEAU

Le 28/08/2019 à 13:26, James Richters a écrit :

Thanks for figuring out the critical section needs to be initialized.  Stefan's 
example did not do this:
https://github.com/svpantazi/libusbxhid/blob/master/libusbhid_test_with_thread.pp

maybe it's something you can get away with on Linux...
Maybe, it seems EnterCriticalSection is defined by the current thread 
manager. But if your variable is uninitialized, you can have anything in 
it, I think EnterCriticalSection cannot do anything reliable with it.

I'll put in the init and done.   Should I enter critical section only for 
writing to shared variables, or also when reading them?


You don't need to enter the Critical section to read the variable.

The critical section is essentially used to prevent the case where your 
main thread and your read  thread write two different values to the same 
variable at the same time. In this case without a critical section, you 
cannot predict the value of the variable. If the variable is always 
written by the same thread, you don't need the critical section.



I'm also wondering if there is some way to tell if a thread is currently 
running or not... I don't want to try to start it again if it's already 
running.  I can make some flag that the threat sets when it starts and clears 
when it exits, but I am wondering if there already something in place to check 
to see if a thread exists.


You can find whether your thread is running or not with the 
readThread.Suspended property,


but in your program, your thread is always running, it's nether 
suspended. It's just blocked in a call (to libusbhid_interrupt_read I guess)



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


Re: [fpc-pascal] USB Human Interface Devices

2019-07-30 Thread Jean SUZINEAU

  
  
Le 30/07/2019 à 19:52, James Richters a
  écrit :

libusb.pas(1350)
  Warning: Library c.dll not found, Linking may fail ! ■ 
As stated in https://github.com/hansiglaser/pas-libusb/issues/4
it's very likely you'll have to change

{$LINKLIB c}

into

  {$linklib msvcrt}
(and you'll need to have a msvcrt.dll in your path, there are different versions of msvcrt, like msvcrt20.dll, I don't know exactly which one you will need)

Under linux, when the compiler finds {$LINKLIB c}, it will look for something like "libc.so" (the runtime dll) and "libc.a" (file with infos for compilation and link).


Le 30/07/2019 à 19:52, James Richters a
  écrit :

libusb.pas(1350)
  Warning: Library usb-1.0 not found, Linking may fail !
 Did you install the windows version of libusb ?
It seems to be at https://libusb.info/
I think you'll have to change  

{$LINKLIB usb-1.0}
into something like
{$LINKLIB libusb-1.0}
and libusb-1.0.dll and libusb-1.0.lib should be accessible on your path.

Some unix libraries are available through distributions such MinGW (http://www.mingw.org/)
It seems libusb is available under windows (libusb-1.0.22.7z) with four different compilations:
-MinGW 32 bits (I imagine it uses the libc from mingw, the glibc I suppose)
-MinGW 64 bits
-MS32 I think it's compiled with Microsoft Visual Studio/ Microsoft Visual C++ and use the MSVCRT dll
-MS64 the same in 64 bits architecture.

  

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


Re: [fpc-pascal] FP.exe error in x86_64-Win64

2019-08-07 Thread Jean SUZINEAU

  
  
Hello, I reproduced the problem.
I run fpcupdeluxe x86_64-win64-win32, this is the log of what I've done:

button Setup+, Options Override, FPC options -gw, then click OK, then click FPC Only
After recompilation by fpcupdeluxe:
Open cmd, cd to fpcupdeluxe\fpc\bin\x86_64-win64
 gdb.exe fp.exe
 set new-console
 run
Open a program and try to compile it.

Screenshot of gdb:

(gdb) set win32 new-console on
No symbol "win32" in current context.
(gdb) set new-console on
(gdb) run
Starting program: E:\fpcupdeluxe\fpc\bin\x86_64-win64/fp.exe
[New Thread 24056.0x4d64]
[New Thread 24056.0x12c0]
[New Thread 24056.0x632c]
[New Thread 24056.0x6344]
[New Thread 24056.0x59c]
[New Thread 24056.0x3ca8]

Program received signal SIGSEGV, Segmentation fault.
fpc_shortstr_to_shortstr (RES=..., highRES=255, SSTR=Cannot access memory at address 0x3e2110
) at ../inc/generic.inc:867
867   slen:=length(sstr);
(gdb) bt
#0  fpc_shortstr_to_shortstr (RES=..., highRES=255, SSTR=Cannot access memory at address 0x3e2110
) at ../inc/generic.inc:867
#1  0x006dfc10 in ?? ()
#2  0x in ?? ()
(gdb)

  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-02 Thread Jean SUZINEAU
@Johann: Is the Readme.rst at https://github.com/hansiglaser/pas-libusb 
up to date ?
It states that only the legacy version 0.1 of libusb is supported, but 
the binary package for Windows on libusb.info is in version 1.0.22.
You can get source code for old versions of libusb on github but it 
seems at first glance that there are no release of windows version 
before 1.0.20 (14 sep 2015) ( 
https://github.com/libusb/libusb/releases?after=v1.0.21-rc4 ).


I tried to compile TestFirmware.pas on windows, I made a few 
modifications. I join the diff files.
In ezusb.pas I replaced the dependency to Errors unit by a quick and 
dirty rewrite of StrError function, just to allow compilation.
In paslibusbutils.pas I replace the call to fpGetTimeOfDay by a call to 
DateTimeToUnix(Now),  I'm not sure may be the result of DateTimeToUnix 
is truncated to seconds where fpGetTimeOfDay gives a result in microseconds.
In usb.pas I duplicated some constant definitions from errno.inc 
included in unit BaseUnix: ESysETIMEDOUT, ESysEAGAIN...
I also replaced the call to fpSelect(0,Nil,Nil,Nil,100) by Sleep(100) 
which should do the same thing, waiting for 100 milliseconds.


@James: Now, I just get the two final errors "Import library not found 
for c" and "Import library not found for usb".

For now I haven't found which library to use for c.
I'm preparing another mail for this.

 src/ezusb.pas | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/ezusb.pas b/src/ezusb.pas
index cf515fa..79947c0 100644
--- a/src/ezusb.pas
+++ b/src/ezusb.pas
@@ -43,7 +43,9 @@ Const ANCHOR_LOAD_INTERNAL = $A0; { Vendor specific request code for Anchor
   CPUCS_8051RESET  = $01; { 1: reset 8051, 0: run }
 
 Implementation
-Uses SysUtils,Errors;
+Uses
+  //Errors,
+  SysUtils;
 
 Const
   EZUSBUnconfiguredConfiguration = 1;
@@ -94,6 +96,10 @@ Begin
 End;
 
 Function TUSBDeviceEZUSB.LoadMem(HexRecord:PIntelHexRecord):LongInt;
+  function StrError(err:integer): String;
+  begin
+   Result:= 'Error #'+IntToStr(err);
+  end;
 Begin
   While (HexRecord <> Nil) and (HexRecord^.TheType = 0) do
 Begin
 src/paslibusbutils.pas | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/paslibusbutils.pas b/src/paslibusbutils.pas
index 743746e..206eada 100644
--- a/src/paslibusbutils.pas
+++ b/src/paslibusbutils.pas
@@ -2,7 +2,14 @@
 Unit PasLibUsbUtils;
 
 Interface
-Uses SysUtils,StrUtils,Classes,BaseUnix,Unix;
+Uses
+SysUtils,
+//BaseUnix,
+//Unix,
+{$IFDEF MSWINDOWS}
+dateutils,
+{$ENDIF}
+StrUtils,Classes;
 
 Const HexChars = '0123456789ABCDEF';
 
@@ -25,10 +32,16 @@ Begin
 End;
 
 Function GetUSec : UInt64;
+{$IFDEF MSWINDOWS}
+begin
+ Result:= DateTimeToUnix( Now);
+end;
+{$ELSE}
 Var TZ : TimeVal;
 Begin
   fpGetTimeOfDay(@TZ,Nil);
   Result := TZ.tv_usec + TZ.tv_sec*100;
 End;
+{$ENDIF}
 
 End.
 src/usb.pas | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/usb.pas b/src/usb.pas
index 62d2db3..1a81f6d 100644
--- a/src/usb.pas
+++ b/src/usb.pas
@@ -28,7 +28,9 @@ Unit USB;
 Interface
 
 Uses
-  Classes, SysUtils, Baseunix, LibUSB;
+  Classes, SysUtils,
+  //Baseunix,
+  LibUSB;
 
 (*)
 (**  Procedural Interface  ***)
@@ -241,6 +243,8 @@ Uses PasLibUsbUtils,Math;
 Type TUSBExceptionType = Class of Exception;
 
 Function USBException(Proc:String;Ret:LongInt) : Exception;
+//duplicated from errno.inc included in unit BaseUnix
+const ESysETIMEDOUT= 110;
 Var Ex : TUSBExceptionType;
 Begin
   Case -Ret of
@@ -515,6 +519,7 @@ Begin
 End;
 
 Function USB_Send(Hnd:PUSBDevHandle;EP:LongInt;Const Buf;Length,Timeout:LongInt):LongInt;
+const ESysEAGAIN=11;
 Var Loops  : Integer;
 Sent   : LongInt;
 ToSend : LongInt;
@@ -540,7 +545,8 @@ WriteLn('Problem with usb_bulk_write: Result = ',Result,', usb_error_errno = ',u
 if (Loops > 0) and (usb_error_errno = ESysEAGAIN) then
   Begin
 Again := True;
-fpSelect(0,Nil,Nil,Nil,100);
+//fpSelect(0,Nil,Nil,Nil,100);
+Sleep(100);
   End;
   End
 else
@@ -573,6 +579,7 @@ Begin
 End;
 
 Function USBGetDriver(Handle:PUSBDevHandle;Intf:Integer):String;
+const ESysENODATA= 61;
 Var R : Integer;
 Const MaxLen = 100;
 Begin
@@ -656,6 +663,7 @@ Begin
   usb_close(Handle);
 End;
 
+const ESysEBUSY=16;
 Procedure TUSBDevice.Open;
 Var R  : Integer;
 I  : Integer;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] USB Human Interface Devices

2019-08-05 Thread Jean SUZINEAU

  
  
Hi James,


Le 05/08/2019 à 04:40, James Richters a écrit :

  
  
  
  
Hi Jean, 
Thank you very much for your help getting this to work. I’ve
been out of town on a business trip but I’m finally back
now, and trying to follow all this.  I’ve been trying to
follow along the conversation with Email but I did not have
a very reliable internet connection. I did see a zip file
you posted, but then it seems you made more changes since
then, I’m not sure how to apply .diff files.  
 
Would it be
possible to get an update zip file of the current files?  
  


I put a zip of my working directory of
  pas-libusb as a pseudo "convenience" release on my github
  repository :

https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/pas-libusb_convenience_release
You should find every thing needed in
  it, you can even see my modifications with Tortoise Git, the .git
  subdirectory is included.
Let me know if I forgot something or if
  you get a problem.




  

 
I’m afraid a
lot of this is just way over my head, I did not expect it to
be anywhere near this complicated to get this to work, they
python code I am trying to duplicate in my FPC application
is so simple, but without access to the packages it uses,
it’s turning out to be very complicated indeed..
 ironically,  the unit I am trying to get to work is called
EasyHID, but it seem to be anything but easy.
 
Here is the
python code that I am trying to implement in my FPC program:
https://github.com/wolfmanjm/kivy-smoothie-host/blob/master/modules/hb04.py
  

I'm busy today, I had a quick look at hb04.py, I haven't yet
  tried to open a device with pas-usb but I don't think it would be
  too much difficult.

  

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


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-06 Thread Jean SUZINEAU

  
  
Le 06/08/2019 à 17:18, James Richters a
  écrit :


  
  
  
  I used this command line:
I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.exe
  -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\i386-win32\
  -Fu.. -Fu. -FUlib\i386-win32\ -FE. -otest1library.exe
  test1library.pas
  

Usually, if lazarus is installed, you just need to locate and double
click on
I:\Programming\pas-libusb_test_dll\src\examples\test1library.lpi in
Windows Explorer, and when the project is open, just press Ctr F9 to
compile or F9 to execute, just as in the good old Turbo Pascal 5.5
from 1989 ...
  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-06 Thread Jean SUZINEAU

  
  


Le 06/08/2019 à 17:18, James Richters a
  écrit :


  
  
  
  
Any ideas?  Is this just from using
  i386-win32? Maybe the DLL is only for 64bit? Maybe some
  completely unrelated issue?  If 64bit is needed, what’s the
  best way to install FPC3.0.4 for x86_64-win64?  It seems like
  I tried to do that before and it wasn’t really very easy to
  try to learn how to compile it.
  

I'm going to have a look at that. Actually, it seems there's no
  package for fpc windows 64 bits.

The short answer would be to advise you to download and install
  lazarus ( https://www.lazarus-ide.org/ ) from
https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%202.0.4/lazarus-2.0.4-fpc-3.0.4-win64.exe/download
If you install it in C:\lazarus\, you'll end up with a 64 bits
  fpc in C:\lazarus\fpc\3.0.4\bin\x86_64-win64 . You can run it from
  command line as usual.
You can also try to replace the libusb-1.0.dll with the one from
  libusb-1.0.22\MinGW32\dll from
https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z
  .




  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-05 Thread Jean SUZINEAU

  
  
Hello
I haven't had time yet to read
  everything but I join below a few more tests.

Le 05/08/2019 à 21:38, Johann Glaser a
  écrit :


  
  Yay! That looks great!
  
  
  As a next step you can try test2controlsync.pas
which uses control transfers to query the device descriptors.
Just change the constants DevVID
and DevPID at the top to
the values of a device connected to your PC. I'd recommend to
use a device you don't depend on during testing, i.e., don't use
your primary keyboard and mouse.  There shouldn't be a problem, but better safe than
sorry. And I hope that Windows doesn't cross your plans and
already has allocated that device to a certain driver.
  
  
  You can also try test3controlasync.pas,
which does a very similar test, just using the asynchronous
interface to libusb (and it is less verbose and estensive).
  
  

I tested successfully test2controlsync and test3controlasync on
  Windows 10 and Ubuntu 19.04 with a Seeeduino lotus (recognized as
  manufacturer Silicon Labs, Product CP2102N USB to UART Bridge
  Controller).
I've zipped the code in a new "convenience release" at :

https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/pas-libusb_convenience_release_2
This is the output on Windows:
E:\03_travail\libusb\pas-libusb_test_dll\src\examples>test2controlsync.exe
Bus 001 Device 010: ID 10C4:EA60
Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   2.00
  bDeviceClass0
  bDeviceSubClass 0
  bDeviceProtocol 0
  bMaxPacketSize064
  idVendor$10C4
  idProduct   $EA60
  bcdDevice1.00
  iManufacturer   1 Silicon Labs
  iProduct2 CP2102N USB to UART Bridge Controller
  iSerialNumber   3 0001
  bNumConfigurations  1
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   32
bNumInterfaces  1
bConfigurationValue 1
iConfiguration  0
bmAttributes  $80
MaxPower  100mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   2
  bInterfaceClass   255
  bInterfaceSubClass  0
  bInterfaceProtocol  0
  iInterface  0
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress  $02  EP 2 OUT
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize  $0040  1x 64 bytes
bInterval   0
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress  $82  EP 2 IN
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize  $0040  1x 64 bytes
bInterval   0

E:\03_travail\libusb\pas-libusb_test_dll\src\examples>test3controlasync.exe
Submitting control transfer
Finished Transfer, Data = "" Status = 0, ActualLength = 18
Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   2.00
  bDeviceClass0
  bDeviceSubClass 0
  bDeviceProtocol 0
  bMaxPacketSize064
  idVendor$10C4
  idProduct   $EA60
  bcdDevice1.00
  iManufacturer   1
  iProduct2
  iSerialNumber   3
  bNumConfigurations  1
Done.

E:\03_travail\libusb\pas-libusb_test_dll\src\examples>
  

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


Re: [fpc-pascal] *** SPAM *** Re: USB Human Interface Devices

2019-08-05 Thread Jean SUZINEAU

  
  
Hi James,

Le 05/08/2019 à 13:00, James Richters a
  écrit :


  
  
  
  
Hi Jean, 
 
Thank you
very much for posting the zip, I’ll download it and see if I
can figure it out.  Also thank you very much for your
efforts and help with this.   It is VERY much appreciated!
 

  James

  

With pleasure. It's  a good occasion for me to learn a bit more on
USB.
  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-08 Thread Jean SUZINEAU

Ooops, sorry. Of course I meant dynamic linking ...
Le 08/08/2019 à 23:32, Johann Glaser a écrit :

Am Donnerstag, den 08.08.2019, 13:14 +0200 schrieb Jean SUZINEAU:

It seems that right out of the box pas-libusb uses static linking for
me.

I think you meant to write "dynamic linking" here. :-) When I use the
Makefile, it also uses dynamic linking. Actually, I've never tried to
do static linking with libusb, because dynamic linking works so
flawlessly on Linux.

Bye
   Hansi


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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-09 Thread Jean SUZINEAU

  
  
Le 09/08/2019 à 06:33, Jean SUZINEAU a
  écrit :


  
  Very often in Windows system functions you have to deal with
  records with declared with a length of 1 and the real length
  stored a few bytes before in the record.
  

Oops, not with records, with  arrays, like "Array[0..0] of
libusb_endpoint_descriptor;" line 409 of libusb.pas
  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-08 Thread Jean SUZINEAU

  
  
Hi James,


Le 09/08/2019 à 02:19, James Richters a
  écrit :


  so this was strange... it was working before

line 81For J := 1 to Length(PortPath)-1 do
line 82  Write('->',PortPath[I]);

Line 82 is using variable I but it's in a loop that uses J, I didn't think that made a lot of sense.. so without really analyzing how any of this was supposed to work.. I just changed the I to a J and then I got this:


I think it's a typo. 

I think we didn't saw it before because Range type checking was
  disabled ( {$RANGECHECKS
OFF} or {$R-} ).  

It seems it's the default value for the compiler:
  https://www.freepascal.org/docs-html/prog/progsu65.html . Very
  often in Windows system functions you have to deal with records
  with declared with a length of 1 and the real length stored a few
  bytes before in the record. This could not work with {$R+} 
But it's seems that for some reason it's enabled for your
  compiler (may be a different default value when your recompiled
  with fpcupdeluxe, or more likely a different default value in your
  settings for fp.exe ?).
I'm not an expert in memory allocation, but I think that while a
  certain amount of memory is allocated after the memory pointed to
  by PortPath and you're in {$R-} mode, you can happily read several
  bytes after the actual end of PortPath without any segmentation
  fault or memory access exception.






  

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


Re: [fpc-pascal] FP.exe error in x86_64-Win64

2019-08-09 Thread Jean SUZINEAU

  
  
Le 09/08/2019 à 14:19, James Richters a
  écrit :


  
  
  
  
Now I have a
new problem.  I am able to successfully compile and run my
project with the text IDE if I use the trunk version of FPC,
and I can run the resulting exe just fine on the computer I
compiled it on,  but when I run it on one of my other
computers, one that I was always able to run the win32
version of my program on just fine,  the x64 version now
comes up with 
 
‘The code
execution cannot proceed because MSVCR110.dll was not found.
Reinstalling the program may fix this problem’
 
I do not
understand this at all, I never needed anything like that
dll before, and I have no idea what it is or why the 64bit
version would need it, and I also don’t know why  this works
fine on my development computer without it and why I need it
on my other computers that I have been running the 32bit
version of the exact same program on for years.
 
Any thoughts
on this?
 
  

Yes , it just seems that libusb relies on MSVCR110.dll. Very
  likely you have another version on this machine. 

I googled for MSVCR110.dll, it pointed to me to the MSVCR fro
  VisualStudio 2012:
https://www.microsoft.com/en-us/download/details.aspx?id=30679
It happens to me frequently when installing a  product on a
  customer's computer. Depending on the product you can have to
  install a different version of the redistributable. On some
  computers the dll is already there, sometimes not. As far as I
  know Microsoft now forbids you to include the dll directly in your
  distribution, you need to use their install program which installs
  it reliably (I think in C:\Windows\System32) and maybe some other
  stuff around and in the registry.

  

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


Re: [fpc-pascal] FP.exe error in x86_64-Win64

2019-08-09 Thread Jean SUZINEAU

  
  
Le 09/08/2019 à 15:39, James Richters a
  écrit :


  
  
  
  
I am not
using libusb in my project yet…  all that is still just in
separate test programs.  This is the original version of my
project, just compiled for 64bits…  I had to make some other
changes to it.   I have never needed to install anything
else to get my program to run.   I re-compiled it back to
win32 and it runs fine again.
 
I think what
your are saying is that I probably have something that has a
dependency on it, and somehow I already end up having the
win32 version of the DLL but I don’t have the 64 bit version
  

Sorry, I didn't understood correctly, I thought you were trying
  with one  of pas-libusb examples.
May be you can try to list the dll dependencies of your compiled
  program. I searched for ldd equivalents for Windows, Google points
  to http://dependencywalker.com/
May be that in 32 bits your executable uses another (older)
  version of msvcr.dll which is already installed on your test
  machine.

  

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


Re: [fpc-pascal] unit GUi creation also usable for visually impaired developers with no sight at all

2019-08-09 Thread Jean SUZINEAU

Le 09/08/2019 à 12:22, Mgr. Janusz Chmiel a écrit :
Does somebody of you know about Lazarus compatible Unit, which is able 
to create Windows GUi with no need to specify object position values 
in points or in Pixels?
Something similar like VCL units have for commercial BOrland Delphi. 
Or unfortunately, there is no such unit available for Free Pascal 
compiler and Lazarus?
Visually impaired programmer can not correctly determine object 
position values. So only units, which try to automatically calculate 
objects positions are usable for visually impaired developers.

Thank you very much for yours answers.


May be you should have a look at pas2js ? And the mailing list for 
freepascal pas2js ( https://www.freepascal.org/maillist.html )


Michael Van Canneyt has recently published on it a proof of concept 
which seems to go exactly in this direction.


https://lists.freepascal.org/pipermail/pas2js/2019-August/88.html

https://www.freepascal.org/~michael/designdemo/designdemo.html


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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-08 Thread Jean SUZINEAU

  
  
Static linking :


Le 05/08/2019 à 21:38, Johann Glaser a
  écrit :


  
  Referring to your EMail to James, it seems that Vitaly even
got it working with static linking. Especially "$LINKLIB msvcrt"
and "$LINKLIB usb-1.0.dll.a" look promising. Hmm, OTOH he writes
of dynamically linked, I don't know.
  
  
  Could you please also have a look at his comments in that
Github issue?

For now I couldn't achieve static linking.
I couldn't find a reliable way to find the dependencies of
  libusb-1.0 on other libraries, may be I would have to dig into the
  makefile and autoconf files of libusb sources, but it seems
  difficult.

I used MSYS2 (https://www.msys2.org/) in which I installed the
  following packages:

 pacman -S mingw64/mingw-w64-x86_64-libusb
 pacman -S mingw-w64-x86_64-headers-git
 pacman -S mingw-w64-x86_64-crt-git
 pacman -S mingw-w64-x86_64-gcc

In LibUsb.pas I changed the $LINKLIBs to (the errors removed by a particular $LINKLIB are after //Error: ) :  
{$LINKLIB usb-1.0}
{$ifdef windows}
  {$LINKLIB mingwex} //Error: Undefined symbol: __mingw_vsnprintf, __mingw_vsprintf, __mingw_vsscanf
  //{$LINKLIB mingw32} //doesn't improve anything
  {$LINKLIB kernel32} // Error: Undefined symbol: __imp_TlsGetValue,  __imp_EnterCriticalSection, __imp_LeaveCriticalSection, ... +41 others
  {$LINKLIB advapi32}   // Error: Undefined symbol: __imp_OpenSCManagerA, __imp_OpenServiceA, __imp_CloseServiceHandle
  //{$LINKLIB winpthread} //doesn't improve anything
  //{$LINKLIB stdc++} //doesn't improve anything
  {$LINKLIB gcc} //Error: Undefined symbol: ___chkstk_ms
  {$LINKLIB crtdll} //Error: malloc, memcpy, ... + 37 others
  //{$LINKLIB msvcrt} //same as crtdll, Error: malloc, memcpy, ... + 37 others{$else}
  {$LINKLIB c}
{$endif}

Here are the errors of the compilation, it's the minimu I could obtain:

Hint: (11030) Start of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Hint: (11031) End of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Free Pascal Compiler version 3.0.4 [2019/02/03] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
(1002) Target OS: Win64 for x64
(3104) Compiling test1library.pas
(9015) Linking E:\03_travail\libusb\pas-libusb\src\examples\test1library.exe
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_default_context
Error: Multiple defined symbol .refptr.INVALID_WINFD
Error: Multiple defined symbol .refptr.pCancelIoEx
Error: Multiple defined symbol .refptr.__tens_D2A
Error: Multiple defined symbol .refptr.__hexdig_D2A
Error: Undefined symbol: atexit
Fatal: (10026) There were 8 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\lazarus\fpc\3.0.4\bin\x86_64-win64\ppcx64.exe returned an error exitcode


  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-08-08 Thread Jean SUZINEAU

  
  
Le 08/08/2019 à 12:07, James Richters a
  écrit :


  
  
  
  
Is the
static linking issue just with Windows, and it works on
Linux, or it isn’t working with FPC at all on either?
 

  James

  

It seems that right out of the box pas-libusb uses static linking
  for me.
  It works right out of the box on Ubuntu 64 bits / Lazarus 2.0.0
  x86_64-linux fpc 3.0.4 with 

{$LINKLIB c}
  {$LINKLIB usb-1.0}

In a terminal:

git clone https://github.com/hansiglaser/pas-libusb.git
git checkout libusb-1.0
git pull
startlazarus , open test1library.lpi, Compile
  launch in terminal:

jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ ./test1library 
Using libusb(x) v1.0.22.11312
Found 12 devices:
  Bus   4 Device   3: ID 0480:0200,  port:   2, port path from HCD: 0, Speed: unknown (4)
  Bus   4 Device   2: ID 0781:5581,  port:   1, port path from HCD: 0, Speed: unknown (4)
  Bus   4 Device   1: ID 1D6B:0003,  port:   0, Speed: unknown (4)
  Bus   3 Device   2: ID 2109:0811,  port:   1, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   3 Device   1: ID 1D6B:0002,  port:   0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   1: ID 1D6B:0002,  port:   0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device   4: ID 04A9:2220,  port:   4, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   6: ID 046D:C077,  port:   4, port path from HCD: 0->4->4, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   2 Device   5: ID 0566:3002,  port:   1, port path from HCD: 0->33->33, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   2 Device   3: ID 05E3:0606,  port:   4, port path from HCD: 0->128, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   2: ID 0451:2046,  port:   1, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   1: ID 1D6B:0001,  port:   0, Speed: 12 Mbit/s (USB FullSpeed)
jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ 

Test dependencies:
jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ ldd ./test1library 
    linux-vdso.so.1 (0x7fffe2b8a000)
    libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x7fae647d1000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x7fae645e6000)
    libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x7fae645c)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x7fae6459f000)
    /lib64/ld-linux-x86-64.so.2 (0x7fae64a51000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x7fae64594000)


jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ objdump -p ./test1library | grep NEEDED 
  NEEDED   libusb-1.0.so.0
  NEEDED   libc.so.6
jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ 







  

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


Re: [fpc-pascal] Developing a mini ERP / web based development

2019-07-25 Thread Jean SUZINEAU

Hello,

I have a big bunch of freepascal code under lgpl, with little 
documentation and a lot of identifiers in French, I hesitated a long 
time before sending this message,  ;-) , but may be it could be useful 
for you.
From 2002 to 2017 I've been developing functionalities for printing 
documents in an ERP for the building industry. The code was first 
written in Delphi 7 and around 2011 I proposed to my boss to translate 
the code to freepascal for free and in exchange move under LGPL the code 
that is not specific to the ERP (the main part of the ERP is written 
under 4js Genero https://4js.com/ with servers running linux most of the 
time).
It's mainly an ORM, lines of database tables are read through a TDataset 
and placed in objects. You get an object for each line of table. And 
I've written the equivalent components of data controls such as TDBEdit 
that connect directly to this line  object (TChamp_Edit from unit 
ucChamp_Edit, package OD_DelphiReportEngine_Controls in that case).
For printing, after using QuickReport, Rave Reports in Delphi, I choosed 
around 2004 to write my own reporting engine to generate Open Office 
documents. The first versions were using OpenOffice through COM bridge, 
but current version generates directly OpenDocument odt files from 
template ott files.
I use the same design pattern for each database table involved, so very 
quickly I wrote a source code generator based on templates, at first as 
plugin for ModelMaker under Delphi, then moved to plugin for Star UML, 
and currently it's a standalone program which uses a TDataset to get the 
list of fields of a database table and the type of each field. Most of 
the time I use it to generate pascal files for my ORM, but you can 
generate whatever kind of file you need (SQL, C#, PHP, Angular...) for 
your own design pattern.


For the user interface, at first it was a classic Windows program using 
Delphi forms running on the client computer, but around 2014 I needed to 
move my code to the server in web development paradigm. I'm dreaming of 
a Lazarus able to compile forms to webasm.
For now I use Google Angular ( https://angular.io/ ), the typescript 
language it's based upon has been cocreated by Anders Hejlsberg, father 
of Turbo Pascal and Delphi.
Currently I scratch my head, deep meditation, to write for pas2js the 
equivalent of my TChamp_xxx components, using Pas2JS_Widget from 
heliosroots. It shoudn't be too much complicated.


My repository is at :
https://github.com/jsuzineau/pascal_o_r_mapping
the most current code is on branch TjsDataContexte (I keep the master 
branch for compatibility with the ERP, a slightly older code).

Most recent release of the code generator:
https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_03_30_Generateur_de_code
corresponding source code in 
https://github.com/jsuzineau/pascal_o_r_mapping/tree/master/tools/Generateur


My unit testing project is in subdirectory fpcunit/fuPASCAL_O_R_MAPPING, 
mainly used to test OpenDocument generation.
My main example is the project jsWorks in subdirectory jsWorks. I use it 
to record and log my working sessions, it serves as a basis for billing 
my hours of work.
It's a desktop application that I compile and use under linux and 
Windows. It's also accessible from a browser through http with a small 
frontend coded in Angular (button Http on the main form of the desktop 
application). The biggest part of the frontend is a skeleton created by 
the code generator, with a small customized part to test html input with 
TinyMCE (a few html tags can be translated into OpenDocument stuff).

The most recent release of jsWorks:
https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_04_24_jsWorks






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


Re: [fpc-pascal] USB Human Interface Devices

2019-07-26 Thread Jean SUZINEAU

  
  
I'm not an expert, but a few years ago
  I made small project to read data from an Arduino through USB
  port. The project was running on Raspberry Pi, on Windows it can
  be more tricky( I'm not sure, but I think a device driver is
  needed):
https://github.com/jsuzineau/pascal_o_r_mapping/tree/master/electronic/Arduino/HeartRate
  ,  see Arduino_Special_Raspberry_Pi.lpi
  It seems I used TLazSerial component.


Le 26/07/2019 à 00:04, James Richters a
  écrit :


  
  
  
  
Does Freepascal have support for USB Human
  Interface devices?   I am attempting to interface to an
  WHB04B-4 https://www.amazon.com/gp/product/B07M5ZY1P2
  
I have an example of how to do it that was
  written in Python, so I’m trying to figure out how to get it
  to work with my FPC console application.   Figuring out how to
  interface with the device at all is what is holding me up, I
  don’t have any experience with direct interfacing to any USB
  devices.
 
Any suggestions?
 
 
James
  


  

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


Re: [fpc-pascal] USB Human Interface Devices

2019-07-26 Thread Jean SUZINEAU
You can compile console projects with Lazarus, and even use non visual 
components and datamodules. I've coded a dll (several hundred thousand 
lines of code too) which is used by console programs on web servers. I 
compile the dll with the same lazarus project in Lazarus for Windows  
and in Lazarus for Linux. The dll include datamodules with dataset 
components.


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


Re: [fpc-pascal] Calculating Pixels to represent 3D coordinates

2019-09-20 Thread Jean SUZINEAU
Tip: if you need Sin(A) and Cos(A), it can be faster to make a single 
call to SinCos instead of two separated calls to Sin and Cos:


https://www.freepascal.org/docs-html/rtl/math/sincos.html

It was efficient 20 years ago when I was developing a sky map software, 
may be the gain is negligible today.


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


Re: [fpc-pascal] [Pas2js] It's alive !

2019-09-21 Thread Jean SUZINEAU

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


Re: [fpc-pascal] FPC RGB+W LEDs

2019-11-04 Thread Jean SUZINEAU

  
  
It's possible but I've done it many
  years ago, I don't remember all the details .


In think you'll have to use H2PAS ( https://wiki.lazarus.freepascal.org/Creating_bindings_for_C_libraries
  ).


From what I see from main.c, I think
  you'll have to convert the following headers:

  #include "clk.h"
#include "gpio.h"
#include "dma.h"
#include "pwm.h"
#include "version.h"
#include "ws2811.h"


And I guess you'll have to add
  something like {$linklib libws2811.a}  (after looking at https://github.com/rpi-ws281x/rpi-ws281x-python/blob/master/library/Makefile
  )


May be too if you have object files *.o
  you can link them with something like {$L ws2811.o}


A tutorial showing how to use
  object-code and libraries created in C (I found it from
  https://wiki.lazarus.freepascal.org/Creating_bindings_for_C_libraries
  )

https://github.com/williamhunter/pascal-bindings-for-c/blob/master/docs/Creating%20Pascal%20bindings%20for%20C%20(v1.0).pdf



Le 31/10/2019 à 20:32, James Richters a
  écrit :


  
  
  
  
I got my Raspberry pi working with the user
  space library written in C: at  https://github.com/jgarff/rpi_ws281x
  with python and got my LED strip to light up with the
  examples.  I also have FPC 3.0.4 installed on the pi.   I
  would really like to be able to use the C library with FPC. 
   I have some other C libraries that I’ve managed to use with
  FPC, but those were .dlls, but this doesn’t have .dlls.  Would
  accessing this from FPC even be possible?  And if so does
  anyone have an example of some C library that doesn’t have
  .dlls being accessed from FPC?  
  
  


  

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


Re: [fpc-pascal] FPC RGB+W LEDs

2019-10-24 Thread Jean SUZINEAU

  
  
May be it's not exactly what you are search for, but two years ago I
used an Arduino with an Ethernet shield to control this kind of LED
Strip.
I join below the content of the main file, just 111 lines.  It's
  very easy to control the led strip from arduino. Contrary to the
  comments , it seems I modified the code to use Adafruit DotStar
  library instead of NeoPixel library. I made the arduino part and
  the system was used for a show through the software Madmapper on
  Apple, connected to the arduino through the Artnet protocol other
  Ethernet. I took my last version of the code, I'm relatively
  confident it's the good one.



#include 

/*
This example will receive multiple universes via Artnet and control a strip of ws2811 leds via
Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/

#include 
#include 
#include 
#include 

// Neopixel settings
const int numLeds = 60; // change for your setup
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
#define DATAPIN4
#define CLOCKPIN   5
Adafruit_DotStar leds = Adafruit_DotStar(numLeds, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

// Artnet settings
Artnet artnet;
const int startUniverse = 1; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.

// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;

// Change ip and mac address for your setup
byte ip[] = {192, 168, 1, 57};
byte mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
byte broadcast[] = {10, 0, 1, 255};
void setup()
{
  //Serial.begin(115200);
  artnet.begin(mac, ip);
  leds.begin();
  artnet.setBroadcast(broadcast);
  initTest();

  // this will be called for each packet received
  artnet.setArtDmxCallback(onDmxFrame);
}

void loop()
{
  // we call the read function inside the loop
  artnet.read();
}

void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
{
  sendFrame = 1;
  // set brightness of the whole strip
  if (universe == 15)
  {
leds.setBrightness(data[0]);
leds.show();
  }

  // Store which universe has got in
  if ((universe - startUniverse) < maxUniverses)
universesReceived[universe - startUniverse] = 1;

  for (int i = 0 ; i < maxUniverses ; i++)
  {
if (universesReceived[i] == 0)
{
  //Serial.println("Broke");
  sendFrame = 0;
  break;
}
  }

  // read universe and put into the right part of the display buffer
  for (int i = 0; i < length / 3; i++)
  {
int led = i + (universe - startUniverse) * (previousDataLength / 3);
if (led < numLeds)
  leds.setPixelColor(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  }
  previousDataLength = length;

  if (sendFrame)
  {
leds.show();
// Reset universeReceived to 0
memset(universesReceived, 0, maxUniverses);
  }
}

void initTest()
{
  for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 127, 0, 0);
  leds.show();
  delay(500);
  for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 0, 127, 0);
  leds.show();
  delay(500);
  for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 0, 0, 127);
  leds.show();
  delay(500);
  for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 0, 0, 0);
  leds.show();
}

  

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


Re: [fpc-pascal] Database migration

2020-06-21 Thread Jean SUZINEAU

Le 21/06/2020 à 00:30, Michael Van Canneyt a écrit :
FPC contains this as well since many years, you can drop the 
components on a form, but they
are exposed in the lazarus database desktop as well. 


Very interesting, I didn't know this existed. I will have look at it.

In fact I developed my code around 2004 for Delphi 7 and migrated it to 
fpc/lazarus around 2013 to be able to run it on linux server.


Unfortunately my code is progressively abandoned now.

--
Trader en karma

J'adore me regarder penser... ;-)

http://jean.suzineau.pagesperso-orange.fr/ : mes pages perso

http://www.mars42.com :  mes pages professionnelles, astronomie & informatique

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


Re: [fpc-pascal] Database migration

2020-06-21 Thread Jean SUZINEAU

  
  
Le 21/06/2020 à 09:55, Michael Van
  Canneyt a écrit :


  I use the functionality in the database desktop actively.
  
  The generated code even runs in Delphi.
  
  
  If you look at it and find ways to improve it, I'm all ears :-)
  

I got a quick look at it (Lazarus 2.0.6, FPC 3.0.4).
  I saw there is a distinct generator for each case:
fpcsrc/3.0.4/packages/fcl-db/src/codegen/fpcgdbcoll.pp
  fpcsrc/3.0.4/packages/fcl-db/src/codegen/fpcgcreatedbf.pp
  fpcsrc/3.0.4/packages/fcl-db/src/codegen/fpcgtiopf.pp

In my case, there is a single generator which is  based on
  StringReplace with key/values stored in a StringList.
  My first versions back to 2004 where coded as a plug-in for
  ModelMaker (UML modeling tool) . 
  A few years later, I transformed it in a StarUML plug-in, and
  finally as a standalone freepascal program.
  
  At the beginning the composition of lists of fields or lists of
  tables was hard coded for example to make a list of labels for
  each field of table on a form's dfm: 
  ( https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/03_Data/Automatic/Code_Generation/JoinPoint/02_Pascal/ujpPascal_LabelsDFM.pas
  )
the key value in the template is :  Cle:= '    object lNomChamp:
  TLabel';
  and a part of the generated value could be:

...
    object lNPROJECT: TLabel
    Caption = 'nProject'    
    Left = 16   
    Top = 26  
    Height = 13   
      end 
      object lBEGINNING: TLabel
    Caption = 'Beginning'    
    Left = 16   
    Top = 48  
    Height = 13   
      end 
      object lEND: TLabel
    Caption = 'End'    
    Left = 16   
    Top = 70  
    Height = 13   
      end 
  ...
In the case of the dfm, I cannot use a comment for the key value
  so I put a Tlabel named lNomChamp in the template dfm, and add a
  '    object lNomChamp: TLabel' at the end of the generated value
  to avoid breaking the dfm.

I ended up with a huge number of different kinds of hard coded
  lists for each situation in Pascal , C# and PHP.
A few years ago , while testing Google Angular 4, to avoid to
  have to modify the generator for each new kind of list,  I added
  the possibility to define a list with 4 files:

  listname.01_key.* for definition of the key for list listname
  listname.02_begin.* for definition of the header of  list
listname
  listname.03_element.* for definition of the body of each
element of  list listname
  listname.04_separateur.* for definition of the separator
between each element of  list listname
  listname.05_end.* for definition of the footer of  list
listname

For example in Angular:


  file Angular_TypeScript_RouterLinks.01_key.html contains
""
  file Angular_TypeScript_RouterLinks.02_begin.html is empty
  file Angular_TypeScript_RouterLinks.03_element.html contains " 
Classe.Nom_de_la_classes"
  file Angular_TypeScript_RouterLinks.04_separateur.html contains
a newline
  file Angular_TypeScript_RouterLinks.05_end.html is empty. 
  

(you can find these files at https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/jsWorks/Generateur_de_code/01_Listes/Tables
  )
Theses files are used in unit https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/03_Data/Automatic/Code_Generation/JoinPoint/ujpFile.pas
  .

I used the term "JoinPoint" with Aspect Oriented Programming in
  mind, though it's not strictly aspect oriented programming.
  

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


Re: [fpc-pascal] Database migration

2020-06-20 Thread Jean SUZINEAU

  
  
Hello,

Le 19/06/2020 à 13:55, Darius Blaszyk
  via fpc-pascal a écrit :


  
   Schema::create('flights', function (Blueprint $table) {
  

  $table->id();
$table->string('name');
$table->string('airline');
$table->timestamps();
});

  

I have something that looks a bit like this, a kind of ORM
  (sorry, part of my identifiers are in French, "champ" means
  "field")

... in the class declaration

  //champs persistants
  public
nUser: Integer;
nProject: Integer;
Beginning: TDateTime; cBeginning: TChamp;
End_ : TDateTime; cEnd  : TChamp;
Description: String;

... in the implementation of the constructor :
 Champs.ChampDefinitions.NomTable:= 'Work';

 //champs persistants
 Integer_from_ ( nUser  , 'nUser'  );
 Integer_from_ ( nProject   , 'nProject'   );

 cBeginning:= DateTime_from_( Beginning  , 'Beginning'  );
 cBeginning.Definition.Format_DateTime:= '/mm/dd" "hh:nn';

 cEnd:= DateTime_from_( End_   , 'End');
 cEnd.Definition.Format_DateTime:= '/mm/dd" "hh:nn';

(this is extracted from class TblWork from https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/jsWorks/Elements/Work/ublWork.pas
  )
This class is for a row of the table "Work", most of the time,
  the instance is initialized by reading a row of dataset, but I've
  started some code to read from some other source, like android
  database or JSON data.

I've made a source code generator which can query the structure
  of a database, and generate source codes from templates.
  Particularly it can create the skeleton of unit ublWork.pas which
  contains class TblWork

My last release of source code generator is at : https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_03_30_Generateur_de_code

All the source is released under LGPL at
  https://github.com/jsuzineau/pascal_o_r_mapping/ , feel free to
  pick up code from it if you need.

-- 
Trader en karma

J'adore me regarder penser... ;-)

http://jean.suzineau.pagesperso-orange.fr/ : mes pages perso

http://www.mars42.com :  mes pages professionnelles, astronomie & informatique

  

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


Re: [fpc-pascal] Using built-in serial instead of synaser and the like for Linux console app?

2020-09-01 Thread Jean SUZINEAU via fpc-pascal

Le 01/09/2020 à 10:49, Bo Berglund via fpc-pascal a écrit :

Is there no way to declare a property to have a default non-zero

value?


I'm not sure but I think the syntax is for this something like

property ReadPacketSize: integer read FPacketSize write FPacketSize default 10;

Reference: https://www.freepascal.org/docs-html/ref/refse27.html

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


Re: [fpc-pascal] Using built-in serial instead of synaser and the like for Linux console app?

2020-09-01 Thread Jean SUZINEAU via fpc-pascal
Ooops, wrong url, I just learn know that property could belong to a 
global block... ;-)


For classes:

https://www.freepascal.org/docs-html/ref/refsu33.html#x86-1080006.7.1

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


Re: [fpc-pascal] Help with TList example

2020-09-08 Thread Jean SUZINEAU via fpc-pascal

Another way is to declare TMyRec as class instead of record.

In this case, you don't need the  dereference operator ^ .

No need of new and dispose, just Create and Free, as for TMyRecList.

I don't know if there is a better performance when you use a record,
but as far as I know, record/object/new/dispose is just the old syntax 
for the first object oriented programming born with Turbo Pascal 5.5 
around 1989.


The new syntax with class / constructor Create / destructor Free is born 
Delphi 1 around 1995.


Below is your code modified with TMyRec=class

==

program Project1;
{$mode objfpc}{$H+}

uses
  SysUtils, Classes;

type
  TMyRec=class
    Value: Integer;
    AByte: Byte;
  end;

  TMyRecList=class(TList)
  private
    function Get(Index: Integer): TMyRec;
  public
    destructor Destroy; override;
    function Add(Value: TMyRec): Integer;
    property Items[Index: Integer]: TMyRec read Get; default;
  end;

{ TMyRecList }

function TMyRecList.Add(Value: TMyRec): Integer;
begin
  Result := inherited Add(Value);
end;

destructor TMyRecList.Destroy;
var
  i: Integer;
begin
  for i := 0 to Count - 1 do
    Items[i].Free;
  inherited;
end;

function TMyRecList.Get(Index: Integer): TMyRec;
begin
  Result := TMyRec(inherited Get(Index));
end;

var
  MyRecList: TMyRecList;
  MyRec: TMyRec;
  tmp: Integer;
begin
  MyRecList := TMyRecList.Create;
  for tmp := 0 to 9 do
  begin
    MyRec:= TMyRec.Create;
    MyRec.Value := tmp;
    MyRec.AByte := Byte(tmp);
    MyRecList.Add(MyRec);
  end;

  for tmp := 0 to MyRecList.Count - 1 do
    Writeln('Value: ', MyRecList[tmp].Value, ' AByte: ', 
MyRecList[tmp].AByte);

  WriteLn('  Press Enter to free the list');
  ReadLn;
  MyRecList.Free;
end.

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


Re: [fpc-pascal] Adding file to string to the RTL

2020-10-05 Thread Jean SUZINEAU via fpc-pascal

  
  
In my own code I use BlockRead/BlockWrite, but I'm wondering if
  I've not seen this somewhere in RTL.

https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas
function String_from_File( _FileName: String): String;
var
   F: File;
   Longueur: Integer;
begin
 Result:= '';
 if not FileExists( _FileName) then exit;

 AssignFile( F, _FileName);
 try
    Reset( F, 1);
    Longueur:= FileSize( F);
    if 0 = Longueur then exit;
    SetLength( Result, Longueur);
    BlockRead( F, Result[1], Longueur);
 finally
    CloseFile( F);
    end;
end;

procedure String_to_File( _FileName: String; _S: String);
var
   F: File;
begin
 if '' = _S then exit;

 AssignFile( F, _FileName);
 try
    ReWrite( F, 1);
    BlockWrite( F, _S[1], Length( _S));
 finally
    CloseFile( F);
    end;
end;





  

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


Re: [fpc-pascal] Adding file to string to the RTL

2020-10-09 Thread Jean SUZINEAU via fpc-pascal


Le 09/10/2020 à 10:15, Santiago A. via fpc-pascal a écrit :

Just nitpicking.
Shouldn't "try" be after the "reset" and after the "rewrite"?
Why don't you allow to write an empty string?


Yes, you're right, the Reset/Rewrite should be after the try.
I admit this code is not general, just tailored to my own needs.
In my use-cases, writing a file of size 0 as placeholder is not useful.

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


Re: [fpc-pascal] basic question on begin, end;

2020-09-24 Thread Jean SUZINEAU via fpc-pascal

Personnally I go even further ;-)

if something
then
begin
some multi-line code here
end
else
begin
some multi-line code here
end;

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


Re: [fpc-pascal] Reading Serial Hex Data

2020-12-27 Thread Jean SUZINEAU via fpc-pascal

May be using TBlockSerial from unit synaser from Ararat Synapse ?
( doc: http://synapse.ararat.cz/doc/help/synaser.TBlockSerial.html , 
download: http://synapse.ararat.cz/doku.php/download ).


Given a variable (SynSer: TBlockSerial;), you can test if data is 
available with SynSer.CanReadEx(0) and then use 
SynSer.RecvPacket(Timeout) to get your data.


I think it should work, I haven't used directly TBlockSerial this way, 
but through TLazSerial component for reading data from an Arduino in a 
program running on Windows, Linux x86, or Raspberry.


I think TBlockSerial can work in your console program  context. May be 
TLazSerial can be more tricky to use in your context, you'll need to use 
events/callbacks and FCL.



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


Re: [fpc-pascal] Selecting Records with a variable

2020-12-19 Thread Jean SUZINEAU via fpc-pascal

I know you don't like objects, but maybe something like :



unit uAxisRecord;

{$mode objfpc}{$H+}

interface

uses
 Classes, SysUtils;

type

 { TAxisRecord }

 TAxisRecord
 =
  object
    X,Y,Z,A,B,C: Double;
    function Value_from_Letter( _Axisletter:Char): double;
    procedure ShowAxis( _Axisletter:Char);
  end;

implementation

{ TAxisRecord }

function TAxisRecord.Value_from_Letter(_Axisletter: Char): double;
begin
 case _Axisletter
 of
   'X': Result:= X;
   'Y': Result:= Y;
   'Z': Result:= Z;
   'A': Result:= A;
   'B': Result:= B;
   'C': Result:= C;
   else Result:= X;//or throw an exception
   end;
end;

procedure TAxisRecord.ShowAxis(_Axisletter: Char);
begin
 WriteLn( Value_from_Letter( _Axisletter));
end;

end.

==

And then where you need it:

...
uses uAxisRecord
...

Var
  AxisValue : TAxisRecord;

...

Procedure ShowAxis(Axisletter:Char);
Begin
   Writeln(AxisValue.Value_from_Letter( Axisletter);
End;

or just:

AxisValue.ShowAxis('X');

"object" works as "record", no need to allocate or call a constructor, 
but you can define methods on it.


(I didn't test but it should work)

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


Re: [fpc-pascal] Selecting Records with a variable

2020-12-20 Thread Jean SUZINEAU via fpc-pascal

Le 20/12/2020 à 16:02, James Richters via fpc-pascal a écrit :

If I need a bunch of case statements, it's atcually worse than if I just have 
separate procedures.


No, in fact the case statement is written only once, in the 
implementation of TAxisRecord, and in procedure 
Move_It(Axis_Letter:Char); , you just use:


DoSomething(Variable1.Value_from_Letter(Axis_Letter));

This said, I think that Lucas and Stefan ideas with "AxisName = 
(X,Y,Z,A,B,C);" are better than mine,


because compilation will fail on a bad axis name, for example a typo 
with Axis[U].


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


Re: [fpc-pascal] Reading Serial Hex Data

2020-12-28 Thread Jean SUZINEAU via fpc-pascal

Le 28/12/2020 à 13:16, Bo Berglund via fpc-pascal a écrit :

 Synchronize(CallEvent); //Supply received data in FBuffer to
caller


You are using TThread.Synchronize.

In a console app, it's likely that somewhere else in your main thread 
you'll need to call regularly Classes.CheckSynchronize to allow the 
actual execution of CallEvent.


In my case, linux server dll called by a 4js 4GL console program (no GUI 
on linux server), I need to call regurlarly Classes.CheckSynchronize 
froml 4gl through function exported by the pascal code.

If I don't do this, the CallEvent is nether called.

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


Re: [fpc-pascal] TurboVision is reborn as FOSS (again)

2020-12-25 Thread Jean SUZINEAU via fpc-pascal

Amazing !

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


Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-31 Thread Jean SUZINEAU via fpc-pascal

Le 01/01/2021 à 00:48, James Richters via fpc-pascal a écrit :


I’m not too familiar with PChars, but is there a way to set it to zero 
length?


I set it to #0 and it works ok with the #0 in there with Notepadd++ 
but I think it’s technically not correct.


For me, it's correct. C strings are just terminated with a null 
character, no notion of length, the length is not recorded in the string 
as in Pascal.
___
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 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 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] Remove last character from pchar

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

I think you could just manage the end of your string with a #0 char.

Just allocate enough space for the maximum size of your string plus the 
terminal #0 char.


For example

program Project1;
{$mode objfpc}{$H+}
uses
  SysUtils, Classes;
var
   s: array[0..30] of char;
   p: PChar;
begin
 p:= @s;
 StrPLCopy( p, 'Test', 30);
 Writeln( p);
 s[3]:= #0;
 Writeln( p);
end.

produces

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


Re: [fpc-pascal] Remove last character from pchar

2021-06-10 Thread Jean SUZINEAU via fpc-pascal
Note: if your string is UTF8 encoded, the last "character" can be 
encoded, can span over 1 to 4 "Char", you need to know the length of 
your character.


For example:

program Project1;
{$mode objfpc}{$H+}

uses
  SysUtils, Classes;
var
   s: array[0..30] of char;
   p: PChar;
   i: Integer;
begin
 p:= @s;
 StrPLCopy( p, 'Test€a', 30);
 Writeln( p);
 for i:= 0 to 7
 do
   Write( ord(s[i]),':',s[i],' ');
 Writeln;
 s[5]:= #0;
 Writeln( p);
 for i:= 0 to 7
 do
   Write( ord(s[i]),':',s[i],' ');
 Writeln;
end.

gives

$ ./project1
Test€a
84:T 101:e 115:s 116:t 226:� 130:� 172:� 97:a
Test�
84:T 101:e 115:s 116:t 226:� 0: 172:� 97:a
$

(the € character which spans over 3 chars is broken and so the end of 
the string becomes unreadable)


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


Re: [fpc-pascal] Will the size of an executable depend on the uses clause

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

Le 19/06/2021 à 15:40, Bo Berglund via fpc-pascal a écrit :

function _2d( _i: Integer): String;

Strange name of a function, though, is that needed?
No, it's not needed, it's just my odd way of naming ... ;-)  (the closer 
to %.2d ).

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


Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

2021-06-19 Thread Jean SUZINEAU via fpc-pascal
It's curious, I'm not completely sure we are reasoning about the same 
function and record.


You mention TFileName but for me in FPC 3.2.0:

-  TFileName is declared as "TFileName= type string;" in sysutilh.inc.

- OPENFILENAMEA is declared as record in CommDlg.pp line 94
  and TOPENFILENAMEA=OPENFILENAMEA;
  and POPENFILENAMEA=^OPENFILENAMEA;

-function GetSaveFileNameA is imported from Comdlg32.dll in CommDlg.pp 
line 595
  function GetSaveFileNameA(_para1:LPOPENFILENAME):WINBOOL; stdcall; 
external 'comdlg32' name 'GetSaveFileNameA';


Le 19/06/2021 à 02:51, James Richters via fpc-pascal a écrit :
This got me thinking… my default filename is just a recommended 
default… but TFileName.lpstrFileis also what returns the filename to 
use, and the user could use the save-as dialog to add a directory, and 
change the name of the file to something else..etc… so the file name 
could be significantly larger than the default…

Yes


So I think I’m best off setting TFileName.nMaxFile:= Max_Path;then 
TFileName.lpstrFile will always be able to hold anything the operating 
system can support.


The nMaxFile value include the terminal null character, so it should be 
Max_Path+1, and it must be the size of the buffer lpstrFile is pointing to.


You shouldn't use "TFileName.lpstrFile:=Pchar(DefaultFileName);" because 
in this case lpstrFile will point to a buffer of size 
Length(DefaultFileName)+1 .


And to get the value back from the function, given a variable s: string, 
you should do something like s:= StrPas( TFileName.lpstrFile);


From Microsoft documentation:

nMaxFile
The size, in characters, of the buffer pointed to by lpstrFile. The 
buffer must be large enough to store the path and file name string or 
strings, including the terminating NULL character. The GetOpenFileName 
 
and GetSaveFileName 
 
functions return FALSE if the buffer is too small to contain the file 
information. The buffer should be at least 256 characters long.



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


Re: [fpc-pascal] How to check if a network is available?

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

Ping uses ICMP protocol.
I don't have currently Indy installed on my machines, but I think you 
can find pascal components for ICMP client and even ICMP server.

I think that this way you can do a single "ping", a single ICMP request.
It seems that Synapse has ping  support too:
https://wiki.freepascal.org/Networking_libraries

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


Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

2021-06-19 Thread Jean SUZINEAU via fpc-pascal
I think you should have a look at this documentation on strings, 
particularly for PChar :

https://www.freepascal.org/docs-html/ref/refsu9.html

Le 20/06/2021 à 02:09, James Richters a écrit :

DefaultFileName: AnsiString = '' ;

So Length(DefaultFileName) = 0

TFileName.nMaxFile:=Max_Path+1;

This says that lpstrFile points to a buffer of size Max_Path+1.


TFileName.lpstrFile:=Pchar('');

But here you make it point to a buffer of size 1 (a constant with just a 
null char)


TFileName.Flags:= OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY;


I think OFN_FILEMUSTEXIST forbid to create new file.


TFileName.lpstrFile:=Pchar(DefaultFileName);


New assignment of lpstrFile, make it point to DefaultFileName, which 
seems to be of length 0, so a buffer of size 1 (a constant with just a 
null char at the end).


I think you should at least add the begining of your code : SetLength( 
DefaultFileName, Max_Path);


It seems TFileName is already defined and I am re-defining 
it…TFileName was not my idea.. that is not how I name my variables…


The name is a bit misleading, but as soon as it's a variable of type 
TOpenFileNameA, it's fine.



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


Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

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


Le 21/06/2021 à 03:04, James Richters a écrit :

Var
    ...
DefaulSaveAsFileName: Ansistring;

SaveAsFileNameBuffer: array[0..Max_Path+1] of char;

   ...

Begin

DefaulSaveAsFileName := 'X:\Something with a really really really long 
long long long file name to see if there is still a bug with really 
long filenames.tap';


...
SaveAsFileNameBuffer:=Pchar(DefaulSaveAsFileName);
...

This sounds a bit odd to me but it seems to work.
I would prefer to use

  StrPLCopy( SaveAsFileNameBuffer, DefaulSaveAsFileName, 
SizeOf(SaveAsFileNameBuffer));


instead of
SaveAsFileNameBuffer:=Pchar(DefaulSaveAsFileName);


___
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


Re: [fpc-pascal] Will the size of an executable depend on the uses clause

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

My best score is 67 kb after strip -s with the code below ... ;-)

Of course it will not work on every  version of Windows.

program uptime;

function GetTickCount64: QWord; stdcall; external 'kernel32.dll';

function _2d( _i: Integer): String;
begin
 Str( _i, Result);
 if Length(Result) < 2 then Result:= '0'+Result;

end;

function FormatUpTime( _tc: QWord): String;
var
   t, d, h, m, s: Integer;
   sd: String;
begin
 t:= _tc div 1000;
 s:= t mod 60;
 m:= (t div 60) mod 60;
 h:= (t div 3600) mod 24;
 d:= (t div 86400);

 Result:= _2d(h)+':'+_2d( m)+':'+_2d( s);
 if 0 = d then exit;

 Str( d, sd);
 Result:= sd+' '+Result;
end;

begin
 WriteLn( FormatUpTime( GetTickCount64));
end.


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


Re: [fpc-pascal] How to check if a network is available?

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

May be you can get some information with the "route" command .

If you run "route print" in cmd command prompt, you can get information 
on the different networks available.


https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/route_ws2008

(I couldn't find the doc for Windows 10, but "route print" works on 
Windows 10 Pro)


May be you can run the command "route print 0.0.0.0 " with TProcess and 
parse the output ?


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


Re: [fpc-pascal] How to check if a network is available?

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

Le 18/06/2021 à 17:07, Bo Berglund via fpc-pascal a écrit :

I will need to check this in my connector class, the address to look for has to
be a config item in my application so it can be modified if need be without
rebuilding the app.
Have to figure out how to:
- Retrieve the output of the TProcess execution

There are many ways to cook TProcess ...
I think you'll find what you need at :

https://wiki.freepascal.org/Executing_External_Programs


- Parse the output for the expected network address.
My idea would be to store the output in a Stringlist as shown in the 
examples,  then with IndexOf you can locate the position of  lines like 
"IPv4 Route Table" and "Persistent Routes:" and make a more detailed 
parsing between the two.

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


Re: [fpc-pascal] How to check if a network is available?

2021-06-18 Thread Jean SUZINEAU via fpc-pascal
I've never used open vpn, may be the 10.117 is defined in your 
configuration file ?


For the vpns I've used, the ip adressed were fixed.

( for route, you can type too something like "route print 10.117.*" )


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


Re: [fpc-pascal] Will the size of an executable depend on the uses clause

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

Ooops... little overflow bug
My computer has reached 33 days of uptime today and with

var
    t, d, h, m, s: Integer;

you switch to the negative side ...
I got a display like : -8:-4:-52

Replacing with QWord solved the problem (I imagine DWord would just 
allow for something like 66 days)

var
   t, d, h, m, s: QWord;

I found this bug because incidentally I had the idea to have a look at 
the Ubuntu version of uptime which is installed on my system with 
Windows Subsystem for Linux.
This uptime doesn't match the value of GetTickCount64, you just get the 
uptime since you clicked on the Ubuntu icon in Windows ...


Here is the modified code :

program uptime;

function GetTickCount64: QWord; stdcall; external 'kernel32.dll';

function _2d( _i: Integer): String;
begin
 Str( _i, _2d);
 if Length(_2d) < 2 then _2d:= '0'+_2d;

end;

function FormatUpTime( _tc: QWord): String;
var
   t, d, h, m, s: QWord;
   sd: String;
begin
 t:= _tc div 1000;
 s:= t mod 60;
 m:= (t div 60) mod 60;
 h:= (t div 3600) mod 24;
 d:= (t div 86400);

 FormatUpTime:= _2d(h)+':'+_2d( m)+':'+_2d( s);
 if 0 = d then exit;

 Str( d, sd);
 FormatUpTime:= sd+' '+FormatUpTime;
end;

begin
 WriteLn( FormatUpTime( GetTickCount64));
end.


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


Re: [fpc-pascal] Will the size of an executable depend on the uses clause

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

10 kb of Powerbasic ... you're cheating, it's pascal here ;-)
You can do this with just 1kb of PowerShell ...
( may be Pascal script could even be shorter ...)

File uptime.ps1 :

$MethodDefinition = @"
[DllImport("kernel32")] public extern static UInt64 GetTickCount64();
"@

$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 
'Kernel32' -Namespace 'Win32' -PassThru


#milliseconds
$tc= $Kernel32::GetTickCount64()

# seconds
$t= ($tc-$tc % 1000)/1000
$s= $t%60

# minutes
$tm=($t-$s)/60
$m= $tm % 60

#hours
$th=($tm-$m)/60
$h=$th % 24

#days
$d=($th-$h)/24

$Result="{0:d2}:{1:d2}:{2:d2}" -f $h,$m,$s
if ($d -ne 0)
  {
  $Result= "{0} {1}" -f $d,$Result
  }
Write-Host $Result

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


Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

2021-06-18 Thread Jean SUZINEAU via fpc-pascal
I'm not familiar with GetSaveFileNameA, but usually for the size of a 
FileName  buffer I use the constant MAX_PATH which is defined in unit 
SysUtils.


MAX_PATH itself seems to be an alias from system unit where it is 
defined accordingly to the operating system (260 on windows, 4096 on 
Linux, 1024 on BSD, Solaris and Darwin).


Did you have a look at Microsoft's documentation for GetSaveFileNameA 
and the OPENFILENAMEA structure it takes as parameter ?

https://docs.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-getsavefilenamea

https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamea

Particularly, you need to put in |nMaxFile |the size of the buffer 
pointed to by lpstrFile.


The folowing code works with a 120 characters long filename :

program test_GetSaveFileName;
uses
    SysUtils, CommDlg;
const DefaultFilename= 'Test';
var
   Buffer: array[0..MAX_PATH] of Char; //size MAX_PATH + 1 for 
terminating null char

   ofn: TOPENFILENAMEA;
begin
 StrPLCopy( Buffer, DefaultFilename, MAX_PATH);
 ofn.lStructSize:= sizeof(ofn);
 ofn.hInstance:= 0;
 ofn.lpstrFilter:= nil;
 ofn.lpstrCustomFilter:= nil;
 ofn.nMaxCustFilter:= 0;
 ofn.nFilterIndex:= 0;
 ofn.lpstrFile:= Buffer;
 ofn.nMaxFile:= Sizeof( Buffer);
 ofn.lpstrFileTitle:= nil;
 ofn.nMaxFileTitle:= 0;
 ofn.lpstrInitialDir:= nil;
 ofn.lpstrTitle:= 'test GetSaveFileNameA';
 ofn.Flags:= 0;
 ofn.nFileOffset:= 0;
 ofn.nFileExtension:= 0;
 ofn.lpstrDefExt:= nil;
 ofn.lCustData:= 0;
 ofn.lpfnHook:= nil;
 ofn.lpTemplateName:= nil;
 ofn.pvReserved:= nil;
 ofn.dwReserved:= 0;
 ofn.FlagsEx:= 0;
 if GetSaveFileNameA( @ofn)
 then
 WriteLn( ofn.lpstrFile);
end.

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


Re: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

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

I haven't seen your reply.
Le 18/06/2021 à 23:50, James Richters via fpc-pascal a écrit :

So now I have:

TFileName.nMaxFile:= Length(DefaultFileName)+1;

TFileName.lpstrFile:=Pchar(DefaultFileName);

I need the +1 for the #0 at the end of the Pchar, and now it works 
fine, and I can have strings as long as they need to be.


I think that this way you tell GetSaveFileNameA that it can write 
Length(DefaultFileName)+1 chars in Pchar(DefaultFileName),
but you have only allocated Length(DefaultFileName) chars to 
DefaultFileName .


It's unlikely, but this way you can end up with the corruption of the 
byte right  after the memory block DefaultFileName is pointing to ...



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


Re: [fpc-pascal] Directory Tree

2021-05-13 Thread Jean SUZINEAU via fpc-pascal

Le 04/05/2021 à 01:55, James Richters via fpc-pascal a écrit :


I’ve been noticing odd behavior in Lazarus.. if I stop the program and 
modify the form, then hit the green arrow… none of my for 
modifications are shown.. it’s still using the old form.. but if I use 
the pull down menus to build the project, then I get my new form.Is 
this normal or do I have some setting messed up in Lazarus?



Very difficult to reproduce for me.
May be you tried to open the lfm file in the editor and tried to modify 
it by hand ? It's the only way I could get that.
In Delphi 7, when you choose to open the dfm in the text editor, Delphi 
7 asked you to close the pas file before and  the visual designers.


I copied all the relevant files to another computer to see how they 
would run… and I noticed that after I run the program, it creates and 
etc directory, and inside it there is a file called _Configuration.ini 
which contains one section: [Options] and one entry under that: 
Chemin_Global=


I have split the unit uEXE_INI (subdirectory pascal_o_r_mapping/02_Units 
) and moved the code causing the creation of this entry in a new unit 
uEXE_INI_Global.


Subdirectory etc is where I usually stores the configuration files. 
Maybe I will move Configuration.ini to etc/INIPropStorage.ini


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


Re: [fpc-pascal] Dependency of OpenSSL 1.0.2 still in FPC 3.2.0 on some platforms?

2021-05-12 Thread Jean SUZINEAU via fpc-pascal

My code uses others units from this directories:
https://github.com/jsuzineau/pascal_o_r_mapping/tree/master/pascal_o_r_mapping/2_Units
https://github.com/jsuzineau/pascal_o_r_mapping/tree/master/pascal_o_r_mapping/3_Data
Particularly, Formate_Liste from 
https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/pascal_o_r_mapping/2_Units/uuStrings.pas

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


Re: [fpc-pascal] Dependency of OpenSSL 1.0.2 still in FPC 3.2.0 on some platforms?

2021-05-12 Thread Jean SUZINEAU via fpc-pascal
I do not guarantee anything, I didn't use this recently, but I have a 
function for sending mail with attachments using Synapse.


It's the function MailTo_SMTP in this unit :
https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/pascal_o_r_mapping/3_Data/uMailTo.pas
(my code is under LGPL, you can extract and reuse freely)

Normally the version of Synapse used in this code is here :
https://github.com/jsuzineau/pascal_o_r_mapping/tree/master/pascal_o_r_mapping/7_sources_externes/synapse

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


Re: [fpc-pascal] Directory Tree

2021-05-01 Thread Jean SUZINEAU via fpc-pascal

Sorry, I didn' had time this week to have a look to your last additions.

Le 01/05/2021 à 15:27, James Richters via fpc-pascal a écrit :
Any ideas how to save and restore the column widths for 
VirtualStrinTrees in the ini file?


I imagine it can be done through the events of the IniProperty Storage.

If it doesn't work, in last resort, you can do that using TINIFile to 
access directly the ini file.


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


Re: [fpc-pascal] Directory Tree

2021-05-01 Thread Jean SUZINEAU via fpc-pascal

Le 01/05/2021 à 15:27, James Richters via fpc-pascal a écrit :
Any ideas how to save and restore the column widths for 
VirtualStrinTrees in the ini file?

Done with the events and methods of TIniPropStorage.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Directory Tree

2021-05-03 Thread Jean SUZINEAU via fpc-pascal

Le 02/05/2021 à 23:42, James Richters via fpc-pascal a écrit :
But I’m thinking I didn’t really define the variable the way it would 
normally be done with Lazarus.
Just for notice: classes and objects are not particular to Lazarus, it's 
plain Object Pascal, understood by Freepascal and Delphi whatever the 
context( console, graphic/Lazarus or javascript/pas2js)

Is there a better way I should have defined this variable?

Defining it in public in TText_to_PDF is a good idea.
(Sorry, I've renamed a lot of things)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Directory Tree

2021-04-21 Thread Jean SUZINEAU via fpc-pascal

Le 18/04/2021 à 17:22, James Richters via fpc-pascal a écrit :

RE: [fpc-pascal] Directory Tree
I figured out how to make a pdf file, but I don’t know how to 
implement it… if we can just have a button to print result.txt… then I 
could just change the printer to Microsoft Print to PDF which is 
included with Widows 10….
There is a Freepascal utility for converting a text file to pdf. 
Supposing your lazarus is installed  at c:\lazarus, it 'll be at

C:\lazarus\fpc\3.2.0\source\packages\fcl-report\demos\txt2pdf.lpi
It doesn't display the correct chars if you compile and execute it 
directly on Result.txt on the command line.


But I've included the source code from this project and modified the 
code to produce the pdf.
I've had trouble with the fonts but it seems to works reasonably well 
with DejaVuSans.
It's not the ideal font, but box characters are displayed relatively 
correctly.

I'm not 100% sure it will work for you.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Directory Tree

2021-04-21 Thread Jean SUZINEAU via fpc-pascal

Another way of seeing is to generate and odt file with the generated text.

You get a slightly better rendering because I could define Courier New 
as default font in the new template: FileVirtualTree_txt_to_odt.odt


From the OpenOffice "File" menu, you can generate a pdf file.

There is a way too, to execute LibreOffice/OpenOffice from command line 
to convert directly the odt to pdf.


I have some code for this at 
https://github.com/jsuzineau/pascal_o_r_mapping/blob/master/OOo/uOD.pas, 
in methods

- function TOD.Executable_soffice: String;
- function TOD.Format_Sortie_from_(_Nom_ODT: String): String;
-function TOD.PDF_from_(_Nom_ODT: String): String;

but it can't be used as is for the current case.

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


Re: [fpc-pascal] Directory Tree

2021-04-23 Thread Jean SUZINEAU via fpc-pascal

Le 23/04/2021 à 11:08, James Richters via fpc-pascal a écrit :

RE: [fpc-pascal] Directory Tree

Now if I type new text in the ODT document, it’s Consolas, but the 
actual text in the document is still Liberation Serif… and it doesn’t 
align, if I select all the text and change it to Consolas it’s fine.. 
I tried making a new template with Word I get a warning that some 
things won’tbe saved in ODT format.. and then it comes up with 
Calibri.Maybe it’s an issue with Word.Maybe I’ll have to install open 
office to make the template.


I found out my error was happening because I didn’t close the template 
in Word.


May be toot that a handle stays open when I copy the template to a new 
file in the temp directory. I'm not sure.



The PDF Files have Consolas in them now, but I’m still getting too 
much space between the lines. I fiddled around with the settings under 
//Actual line but nothing I change seems to control the line spacing, 
it’s like it’s 1-1/2 line spaced, instead of just single spaced.


Instead of page breaks,how about just two separate PDF files?One with 
the tree and one with the file list?


I’ve been trying to clear the old file when Load from file is pressed 
with a new file.I tried added slFiles.Clear and vst.Clear in 
ThVirtualStringTree.Load.fromFile, but I get an exception External 
Sigsegv I think it has to do with an index that is set to the old data 
size, but I’m not sure how to re-set everything.


I’ve also been trying to save the last used INI file in Configuration.ini


I've added this.


and just load that when the program starts.Is there a way to make it 
run load from file as soon as the program is open, but after the 
screen is up so I can still see the load bar?


I’ve also been trying to combine Get Checked Items with get selected 
items.. so one button gets all items that are either checked or 
selected, but doesn’t create duplicate entries.


I tried to make a pull request of what I’ve been trying to do with 
configuration.ini and the combined get checked and selected, but I 
don’t know if it can be merged because there are a few files I had to 
commit that had the same name, but the cases were different… I had to 
commit them with one name and then commit them again with the other 
name to get past that or I couldn’t do anything with it.



I've added a checked or selected function.

The items are not duplicated and you can click the button Get Checked 
twice, memory is properly re-initialized.



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


Re: [fpc-pascal] Directory Tree

2021-04-24 Thread Jean SUZINEAU via fpc-pascal

Le 23/04/2021 à 19:56, James Richters via fpc-pascal a écrit :

RE: [fpc-pascal] Directory Tree

Get Checked or Selected works great, but if I push it twice, the 
second time I get:


Unable to open file

C:\Users\James\AppData\Local\Temp\FiC152.odt

But I did make sure to close word and the PDF file before pushing it a 
second time.


Yes, it's a very interesting bug that I'm currently investigating. May 
be I don't use the temp directory correctly.
When making the output, I start by copying the template file to another 
filename/filepath.
When I use my code to generate the new filename in the temp directory 
(Nom:= OD_Temporaire.Nouveau_ODT(Prefixe);),
on the second time, the system doesn't find the source file for the copy 
('FileVirtualTree_txt_to_odt.odt') and the copy fails.
But the source file isn't deleted, it continues to be visible in File 
Explorer, you can open it in LibreOffice.
And this happens either if , instead of using the CopyFile from 
lazutils/FileUtils.pas,  I use a home made "MyCopyFile" function coded 
with BlockRead/BlockWrite or even using command line cmd.exe / xcopy to 
do the job.


But if I copy the template to a file in the exe directory (just Nom:= 
'temp_'+IntToStr(temp)+'.odt'; Inc(temp);), it works ...


I tried to change formatDateTime to include Days, because many 
selections go well over 24 hours and it was just leaving the days 
off... so instead of showing 2days, 3:14:54 it’s just showing 3:14:54


So I changed format date to d:h:m:s but for some reason the totals of 
the branches are coming up with 30 days even though the totals are 
nowhere near even one day.I don’t see where the 30 days could possibly 
be coming from.


I didn't had time to work on this for now. I think it's a bit too much 
complicated for FormatDateTime, it would be safer to decode the datetime 
value in a special function (something like days:= int(datetime); 
hours:= frac(datetime)*24; minutes:= frac(hours)*60 ... )
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Directory Tree

2021-04-25 Thread Jean SUZINEAU via fpc-pascal

Le 25/04/2021 à 21:30, James Richters via fpc-pascal a écrit :

   >I added LoadFromFile in this event.
That was the first thing I tried, but the problem is, this happens before 
anything is put on the screen.. so when I run the program with an Ini file with 
4000 entries in it, there is a good 30 second delay, and then the screen is 
shown with everything loaded.

So I tried putting it in various places in the form, but then it runs 
additionally when I don’t want it to.

The problem I’m having is understanding the sequence of things (if there even 
is one)  with my console programs, I specifically determine the exact order I 
want things to run, but this is more just a collection of things that all run 
at the same time.. well they don’t run at the same time, it’s an illusion, 
computers only do one thing at a time.. but I don’t understand how this 
illusion is controlled…how can I order it to show form1, show the buttons, show 
the load bar graph… get everything on the screen, THEN load the last used file? 
 I can’t really use config.ini, because in order to get everything on the 
screen in the proper size and position, the configuration would have had to be 
read in already.. so before anything is displayed.. I want the load to happen 
after everything is displayed.  I supposed I can maybe launch a timer to wait 1 
second to get everything on the screen then load the files, but I don’t even 
know where to put the timer.


I'm not an expert of that, but let's say that since the good old time of 
Windows 3.1, your Windows app is based on a so-called "message loop".
The main part of your app just register a callback for processing a 
message. There are hundreds of different kind of messages ( from the 
Windows emulator in linux: 
https://wiki.winehq.org/List_Of_Windows_Messages )


Windows kernel is running the loop and sometimes calls your callback to 
repaint a window, set the focus, notify you of a mouse move 
You can still make your own callback ( 
https://docs.microsoft.com/en-us/windows/win32/winmsg/using-window-procedures 
).
But it's so complex that in practice we uses base classes like 
TApplication and TForm to do all the basic code of the windows app.
In the times of Windows 3.1 made for single task  processors, I think 
there were a single message loop for all the system, shared by all the 
apps. If you took too much time processing one of your messages you 
could hang up the system. It was non-preemptive multitasking.
With Windows 95 and 32 bits it began to use the multitasking capability 
of the processor, it began to be preemptive multitasking, you couldn't 
lock the system with an infinite loop, just your program.
With the advent of multicore processors, I think that now you can have 
really several assembler instructions running in parallel 
(https://en.wikipedia.org/wiki/Multi-core_processor).
In some cases you can accelerate your program by running several threads 
in parallel with the TThread class for example.


Most of your components (TEdit, TButton) are child windows hosted in the 
form parent window and they receive their own messages for painting, 
mouse, ...


I have moved the LoadFromFile to a Timer event just fired on creation of 
the Form with 10ms. When the message of the timer arrives,  usually all 
the loading an painting is already done, their messages have been posted 
before in the message queue.



I'm not getting the page break in word either.
May be the template is not up to date ? I think that after type 
Ctrl+Enter in the template Libre Office adds a parameter for allowing 
soft page breaks.

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


Re: [fpc-pascal] Directory Tree

2021-04-25 Thread Jean SUZINEAU via fpc-pascal

Le 25/04/2021 à 02:54, James Richters via fpc-pascal a écrit :

RE: [fpc-pascal] Directory Tree

I’ve been trying make “Load from file”happen automatically when the 
program starts.. I would like it to happen after configuration.ini 
restores the file name and also after the form is on the screen so I 
can see the load bargraph.


I tried putting it in Panel1 OnEnter but the form doesn’t have the 
buttons on it yet when it does the load.. and it is also doing the 
load when I push a button.. which is not what I want to happen.Any 
idea how to do the load once automatically after the screen is up so I 
can see the load progress bar and after all the buttons are on the form?


The persistence of configuration is managed by the ips:TIniPropStorage 
component. Digging a bit , I found that TIniPropStorage has an event 
OnRestoreProperties which fired after the configuration is restored 
(Ctrl+Click on TIniPropStorage, then on  OnRestoreProperties, which 
leads you do TCustomPropertyStorage, where you'll find with a search on 
FOnRestoringProperties that FOnRestoringProperties is called in 
procedure TCustomPropertyStorage.Restore after restoring properties).


I added LoadFromFile in this event.

I have extracted the pdf generation to a unit uText_to_PDF with a class 
TText_to_PDF to make a pdf from a string. You can even use it in a 
console app.

3 pdf are generated now: List, Tree, List+Tree.

I added a page break between list and tree in the odt.


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


Re: [fpc-pascal] Directory Tree

2021-04-25 Thread Jean SUZINEAU via fpc-pascal

Le 25/04/2021 à 15:24, James Richters via fpc-pascal a écrit :

RE: [fpc-pascal] Directory Tree

I fixed the time totals to show days correctly with this:


I didn't use your pull request because I don't know yet how to handle it.

I have delete some files which differed only by case. After committing 
from linux, the pull on windows deleted all the files but I could revert 
them on next commit from windows to get them back in correct case. It 
seems to be stable now.


I used your code for days to make a function Duration_from_DateTime( 
_DateTime: TDateTime): String;

I added on main form a button "Test" with a few test cases.
Let me know if it's ok for you.

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


Re: [fpc-pascal] Directory Tree

2021-05-03 Thread Jean SUZINEAU via fpc-pascal

Le 03/05/2021 à 13:55, James Richters via fpc-pascal a écrit :

>Defining it in public in TText_to_PDF is a good idea.

I tried putting it under the destructor in public… above the private 
variables, but it wouldn’t compile thereI thought it would have to be 
above all the functions and procedures… and there is no Var for 
variables and there are two public and two private definitions, I 
don’t really understand what’s going on…Can I just mix up variables 
with functions and procedures since there is no Var declaration?Or is 
there an order that must be followed?


Yes, the destructor is a special procedure, so it doesn't work. (it's 
the same for constructor which is a special function).


You can put any number of public/private /protected sections.
Usually for each specific aspect of my class, I add:
- at first level a comment with the aspect.
- Then right below a  "private" section for the internal stuff of the 
aspect, not useful from outside the class
- eventually a "protected" section ( like private but can be accessed 
from child classes)

- a "public" section for stuff useful from outside the class.
- you can have a "published" section, kind of "super public", mainly for 
components in the ide palette , rtti, and when you need to discover 
properties of an object at run time.
 (this works for classes defined with "class end", for old style, kind 
of record with methods defined with "object end", "published" doesn't work).



>(Sorry, I've renamed a lot of things)

Thanks, I’m still trying to pick up the naming conventions.For some 
reason all my form changes got reset.I merged them back in and pushed 
it.I made the background of the information boxes white, not invisible 
that’s why I set them to ‘‘ at the beginning.. so the white boxes 
would be visible.I also padded the text in the boxes with spaces so 
the white background would make a border around the text.I also 
re-arranged a lot of things, added horizontal scroll bars and shut off 
word wrap on the results panel.. removed extra buttons we don’t need 
now with the menu, etc..Let me know what you think of my form design.


It's nice. I keep my original design mainly because my "main"screen on 
linux has a lower resolution.


Any idea how I change the format of M.Text=’[Date]’; in 
uText_To_PDF.pas ?It shows up 2021-05-03(Which I actually like better 
because it sorts properly)but here in the USA 05-03-2021 is 
customary.I don’t see where [Date] gets filled in with the date or how 
to define the format of it.I think I could make my own date format, 
but I don’t want to over-complicate things.


'[Date]' is decoded in unit fpreport TFPReportCustomMemo.ParseText; and 
expanded in TFPReportCustomMemo.ExpandExpressions; using method 
TFPReportElement.ExpressionResultToString wich uses virtual function 
TFPReportElement.GetDateTimeFormat for getting the datetime format.
You just need to declare a subclass of TFPReportMemo which overrides 
GetDateTimeFormat. I 've adde a  "TfprmText_to_PDF = class( 
TFPReportMemo)" in uText_to_PDF for this.


In the unit test I've added a generation of a 1 lines inifile for 
testing. This lead me to change some things to improve the loading speed.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Formatting Question

2021-04-04 Thread Jean SUZINEAU via fpc-pascal

Le 04/04/2021 à 02:41, James Richters a écrit :
That looks almost perfect.. can I suppress the trailing zeros with the 
format command without losing the alignment? 


As far as I know, no ...

Not  with just the RTL.
Anyway I have personal code for this, you can extract and customize it 
to yours needs, it's released under LGPL :


program Format_Example;
uses
    sysutils,uReal_Formatter,uuStrings;
procedure FF( _d: double);
var
   S: String;
begin
 S:= Fixe_MinE( Format_Float(_d, True, 3), 7);
 WriteLn( S);
end;

begin
 FF(0.5);
 FF(2.53);
 FF(12.5);
end.

--- Output -

  0.5
  2.53
 12.5

You can find  the used units there:

https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uReal_Formatter.pas

https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas 
(just extract functions  Fixe_MinE / Fixe_Min0 or you will have to use a 
bunch of other units from the same directory 
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/)


https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/u_sys_.pas

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


Re: [fpc-pascal] Formatting Question

2021-04-03 Thread Jean SUZINEAU via fpc-pascal
Normally something like this should do the trick (here 3 decimals and 7 
characters for total width):


program Format_Example;
uses
    sysutils;
procedure F( _d: double);
var
   S: String;
begin
 S:= Format('%7.3f',[_d]);
 WriteLn( S);
end;

begin
 F(0.5);
 F(2.53);
 F(12.5);
end.

-- Output 

  0.500
  2.530
 12.500



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


Re: [fpc-pascal] Directory Tree

2021-04-06 Thread Jean SUZINEAU via fpc-pascal
As far as I understand, you are searching for a general tree component 
like TTreeView in Lazarus, but for FreeVision, running in text mode in 
console ?



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


Re: [fpc-pascal] Directory Tree

2021-04-14 Thread Jean SUZINEAU via fpc-pascal

Le 14/04/2021 à 13:06, James Richters via fpc-pascal a écrit :

I still can’t get off the Master branch on my windows machine. I 
deleted everything, re-forked it, re-cloned it,
I finally found on my linux machine a 'test_gICAPI\jsLignes.Exclus.txt' 
file right in tools directory, and removed it. It has been generated by 
a delphi program (with \ hardcoded for file path separator) that I 
quickly recompile with lazarus under linux. The  \ is an escape sequence 
in linux file names.
It seems it isn't a problem for TortoiseGit  on my Windows machine, he 
just ignores it.
It should work for you now. I've tested several time checking out the 
whole repository and switching to the TjsDataContexe branch

I added a Load Time edit box,  Total Run time, and total including loading 
needed in the report… Yay I managed to do something on my own!
I also cleared the old tree when a new file was loaded.. so I managed to do two 
things 
I wanted my run time to be just minutes and seconds, so I made your procedure 
that fixes the time format into a function and used that for my edit box as 
well.
Since I still can't change branches on your repository, I updated mine
https://github.com/Zaaphod/FileTree

But now I have more questions…. while I can understand the pascal code… I find 
that I am still a bit lost on how things work, so I really appreciate the help.

I would like the initial display of the tree to be expanded one level.. so just 
like I hit the + in front of M: so I thought, how hard could that be? ...

I have added a procedure vst_expand_first_level; for this .

I also thought I would display the output in another tree in the right side of 
the split.. maybe a TTreeView Tree since it won't need checkboxes, and it could 
be just displayed already expanded all the way out.
o I thought I would start by making   function TfFileVirtualTree.Get_Checked 
add the nodes to TTreeView so I tried to put
tv_addnode_from_key_value( td.Key, td.Value);
   right before
Formate_Liste( Result, #13#10, td.Key+' '+td.Value);

Well it couldn't find tv_addnode_from_key_value() because it's in 
ufFileTree.Pas  but I don't understand why it can't find it, because ufFileTRee 
is in the uses section of ufFileVirtualTree.
I did move procedure tv_addnode_from_key_value( _Key, _Value: String);  
from private to public..  but it still can't find it.  I'm not really sure how 
to get data from one of the .PAS files into the other.


Even in public, you would have needed to call it as 
fFileTree.tv_addnode_from_key_value , but it will have worked on the 
TreeView  from fFileTree, which is not what you want. You can consider a 
bit  a class as a record. If tv_addnode_from_key_value is defined in a 
class TfFileTree, you can only call it on an instance of TfFileTree, in 
this case fFileTree, the same way you would access to something defined 
in a record.


Well, this lead me to a big refactoring. I move most of the code from 
ufFileTree to  uFileTree.


I didn't put it in the interface of the unit, but you could now 
eventually use procedure TreeView_addnode_from_key_value from uFileTree 
for this.


I did the same for ufFileVirtualTree, creating a unit uFileVirtualTree 
with a class ThVirtualStringTree dedicated to the handling of a 
TVirtualStringTree.


This way I could add another VirtualTreeView with no checkboxs to 
display the results. I think it's easier to use a VirtualTreeView to 
manage your time sums.
The ThVirtualStringTree class allows to reuse the exact same code for 
the result tree with time sums, and it allows reduce the complexity and 
the amount of code in ufFileVirtualTree.



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


Re: [fpc-pascal] Directory Tree

2021-04-15 Thread Jean SUZINEAU via fpc-pascal

Le 15/04/2021 à 15:31, James Richters via fpc-pascal a écrit :


How did you make the TVirtualStringTree open the first level?  I've been 
looking to see how you did it but I don't see how that was done.
unit uFileVirtualTree, line 360,  method 
ThVirtualStringTree.vst_expand_first_level;

I would like to have the second TVirtualStringTree expanded all the way out.

it's easier, just : vst.FullExpand;
You'll find it line 373, method ThVirtualStringTree.vst_expand_full;


Is there a way to export the file list and the second TVirtualStringTree to a 
PDF file?
As far as I know, there is no way to directly export it. I will have a 
look if I have some time.

I would like to save settings to an INI file, things like window size, divider 
positions, ect.. I have done this with INI files in my console apps, I just 
write out every variable I want to save and read them back in.. but I'm curious 
if Lazarus is more sophisticated.. maybe it has a way to save all settings for 
a form by itself?  Or do I do it the same way as my console app and save each 
variable myself?
Where is the proper place to load the INI file, where it would happen before 
the forms are displayed, and where is the proper place to save the INI file 
right before the program is closed?
From tab "Misc", just drop a TIniPropStorage on your form. You need to 
set the ini filename in the component.
Then in the properties of the form, you'll find the SessionProperties 
property with a "..." button on the right. This opens a dialog which 
allows you to configure which properties of which components you want to 
persist.


I have added this , configured for a "Configuration.ini" file and 
"fFileTree" section.


The following link is for TXMLPropStorage, but it work nearly the same 
for TIniPropStorage. Just read the first paragraph "Using 
TForm.SessionProperties and TXMLPropStorage"

https://wiki.freepascal.org/Remember_form_position_and_size#Using_TForm.SessionProperties_and_TXMLPropStorage
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Directory Tree

2021-04-09 Thread Jean SUZINEAU via fpc-pascal
(I re-send my mail with different sender, it seem the first one has been 
blocked by orange)


I made a short example based on TTreeView with your data at :

https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/FileTree

You just need to download all the files , open project FileTree.lpi in 
Lazarus and hit F9.


You can multi-select with Ctrl+Click and see you select with "Get 
Selection" button.



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


Re: [fpc-pascal] Directory Tree

2021-04-13 Thread Jean SUZINEAU via fpc-pascal

Le 13/04/2021 à 13:50, James Richters via fpc-pascal a écrit :

I tried to make a fork of your repository but I could not change off the master 
branch,,  I always get an error: Checkout Failed  Cannot checkout to invalid 
path 'tools/text_glCAPI\jsLignes.Exclus.txt'  I suspect the / in the path is 
the problem because I am on Windows and it can only use \ for the path.. but I 
don't know how to fix it, so I just made my own repository of this so I can use 
GitHub.
The current version is at  https://github.com/Zaaphod/FileTree
I've removed this file. I work  both with Linux and Windows, most of the 
time it's ok, but it can happen when by mistake I commit some files with 
weird names that can cause some havoc in git in Windows ... For example 
the same file name but with differences in char case:


'tools/jsFichiers/JSFICHIERS_Resultat_du.txt'
'tools/jsFichiers/jsFichiers_Resultat_du.txt'


I noticed the time was in hours and minutes, but it's supposed to be in minutes 
and seconds, but sometimes it's in hours and minutes and seconds, so I tried to 
fix this.. it seems to be fixed ok for the totals, but to fix it I had to put 
the extra 0: in front of all my times so they are 0:03:20 instead of 3:20 I was 
able to display it the way I want in the totals, but I don't see how to change 
how it's displayed in the files.. so they are displaying with the extra 0: now.


I've added a few lines to handle this.
Conversion from datetime to string  is in TTreeData.SetdValue, and 
conversion from string to datetime is in TTreeData.SetValue.



But I noticed the VirtualTreeView is not building the tree correctly.  I am 
getting

I made an error in TfFileVirtualTree.vst_addnode_from_key_value:Recursif.
With "slNodes.AddObject( sCle, TObject(Parent));" , M:\Project1\File2 
ended up in M: instead of M:\Project1

Corrected with : slNodes.AddObject( sCle, TObject(Node));

The program takes a while to load with a large datafile,  is there a way to put 
up some kind of screen immediately, even just a box that says loading...  just 
to let the user know the program was started so they don’t try to start it 
again?  Or even more fun.. have a bargraph showing the progress through the INI 
file  (something I have absoilutly no idea how to accomplish)


I have added a gauge and a buttton to trigger the processing.

I find the execution relatively slow on Windows, I can see the 
progression of the gauge.
On Ubuntu the result appears instantly, I can't see the progression of 
the gauge ( and my linux machine is less powerful than my windows machine).



Thanks again for the help with this!
With pleasure. I couldn't do this all the time, but it happens I have a 
bit of free time for this these days.



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


Re: [fpc-pascal] Directory Tree

2021-04-17 Thread Jean SUZINEAU via fpc-pascal
In Unicode/UTF8 "char" can be represented by several bytes so my code 
won't work.


It seems you use page code 850 (here in France we are in 1252 which 
doesn't have the box chars).


In unit uFileVirtualTree line 469, I have added   type String850= type 
String(850);

declared the local variable s of String850 on line 488,

and changed on line 533 the default encoding of the Stringlist to 850 by
sl.DefaultEncoding:= TEncoding.GetEncoding(850);

It seems to be sufficient to get the box characters. I didn't dig 
further but it seems to work either on Windows and Linux and in text 
file generated.


In the ODT file I used a numbered list but  I think it will be difficult 
to get something closer to a tree.


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


Re: [fpc-pascal] Directory Tree

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

Le 15/04/2021 à 20:16, James Richters via fpc-pascal a écrit :
It doesn't have to be a PDF, it could be an image file, or even a text 
file...maybe I can just make a text file of the output and use box 
characters to draw the tree. It seems like I should be able to get the 
branches of the treedata somehow and just do a writeln to a file with 
the right formatting. 


I have added a text rendering of the tree, it's saved in a text file 
Result.txt.


The rendering code is in unit uFileVirtualTree, function 
ThVirtualStringTree.render_as_text. It's called  in ufFileVirtualTree in 
procedure TfFileVirtualTree.bGetCheckedClick:

 m.Lines .Text:= slResult.Text+#13#10+hvstResult.render_as_text;
 m.Lines .SaveToFile('Result.txt');

In function ThVirtualStringTree.render_as_text I used 3 constants for 
the chars used for drawing the tree outline:

   vertical_line_char='|';
   horizontal_line_char='-';
   angle_char='*';
   crossing_char='L';
You can tune this to your needs.

I have added to a rendering as numbered list in an odt file, the text 
file format for Libre Office and Open Office. The "template" 
FileTree.odt is duplicated with a temp name in the user temp directory, 
and opened in the software register in windows for opening odt files by 
the function OpenDocument() of Lazarus. Depending on your installation 
it can be open in Libre Office/OpenOffice or in MS Word (sometimes the 
rendering is not perfect in Word).


Before recompiling the project, you will need to open first in Lazarus 
the package pascal_o_r_mapping\02_Units\OD_DelphiReportEngine_Units.lpk 
in order to make Lazarus know where it is.
If for some reason you can't load this package, you can remove it from 
the dependency  panel of the project inspector, and in unit 
ufFileVirtualTree, comment out in the use clause the unit 
uFileVirtualTree_odt, and comment out in procedure 
TfFileVirtualTree.bGetCheckedClick the line:

 OpenDocument( FileVirtualTree_odt( 'FileTree.odt', hvstResult));

I've considered making a screenshot of virtual tree component but if the 
whole opened tree doesn't fit in the screen it will not work.


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


  1   2   >