Re: [fpc-pascal] Directory Tree

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

Le 18/04/2021 à 16:10, James Richters via fpc-pascal a écrit :
RE: [fpc-pascal] Directory Tree I getuFileVirtualTree.pas(533,9) 
Error: identifier idents no member "DefaultEncoding"
It seems, using svn blame, that DefaultEncoding has been added in 
FreePascal source trunk on the svn server on June 4th 2019.


I don't know the version number of the fpc release following this date 
but it's likely your lazarus/freepascal is older than mine.


I use currently Lazarus 2.0.12 / fpc 3.2.0.

It has the incorrect character in front of File1,   It’s a 
vertical_line_char instead of a crossing_char.

I have corrected this point, it should work now.
___
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-11 Thread Jean SUZINEAU via fpc-pascal
Indeed, I think it's difficult (if possible) to change the behaviour of 
the multiselection this way.


The TTreeview.MultiSelectStyle property allows you to change from 
CtrL+Click to Shift+Click.


https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/tmultiselectstyle.html

To make the multi selection with just a left click, I think the best way 
would be to use the TVirtualTreeView with checkboxes.



___
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-08 Thread Jean SUZINEAU via fpc-pascal
If you just select files, as Bart stated in another message, I think 
TShellTreeView will be more adequate and easier than TTreeView (actually 
TShellTreeView is a file tree specific descendent TTreeView).


In TTreeView (and TShellTreeView) you can enable multiselection by 
adding tvoAllowMultiSelect in Options set (something like "with 
TreeView1 do Options:=Options+[tvoAllowMultiSelect];"   or better by 
just checking Options/tvoAllowMultiSelect in the Object inspector)


https://wiki.freepascal.org/TTreeView#Example_of_using_Multiple_Node_Selection_for_Multiple_User_Selections

If you want checkboxes, I think it's possible with TVirtualStringTree 
from the VirtualTreeView package, it may be a bit harder to implement 
(as far as  I remember you need your own data structure to store the 
status of the tree) :


https://wiki.freepascal.org/VirtualTreeview

https://wiki.freepascal.org/VirtualTreeview_Example_for_Lazarus#Checkbox

VirtualTreeView package is included in Lazarus v2.0+, but I'm not sure 
it's installed by default: if you don't find a tab "Virtual controls" in 
your components, you may need to go to Package menu/Install packages, 
select virtualtreeview_package 5.5.3.1 for installation and rebuild 
Lazarus.


Here you should enable multiselection with something like

with VirtualStringTree1.TreeOptions do 
SelectionOptions:=SelectionOptions+[toMultiSelect];


or by checking TreeOptions/SelectionOptions/toMultiSelect in the Object 
inspector when your VirtualStringTree1 is selected.


(I've used VirtualTreeView a while ago, I didn't test checkboxes today)

___
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-11 Thread Jean SUZINEAU via fpc-pascal

TStringList works pretty much like an inifile section.
The index corresponds to the line number in you text block.
The Names property corresponds to the part of the line before the '=' char.
The ValueFromIndex property corresponds to the part of the line after 
the '=' char.
So if you line i contains "M:\Project1\File1=8:32", Names[i] will 
returns "M:\Project1\File1" and ValueFromIndex returns "8:32"
The text block (property Text) is viewed like a kind of list of virtual 
records "name=value"


You can iterate the nodes in the TreeView and change their text.

I have updated the example with a VirtualTreeView on a new form (you 
should download all the files in a different directory).
It's more complex to implement, but with checkboxes you just need a 
simple click.




___
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-11 Thread Jean SUZINEAU via fpc-pascal

I have updated the VirtualTreeView example with sub-totals of time.
___
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-22 Thread Jean SUZINEAU via fpc-pascal

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


For some reason the ODT file wants to know if I want to translate it 
from French, and while the font is “Courier New” for anything I would 
type into the document, the font of the text itself is “Liberation Serif”


If I change the font manually to “Courier New” I get gaps in the 
vertical lines,but if I change it to “Consolas” there are no gaps and 
it looks perfect.


Basically, I think you should replace the FileVirtualTree_txt_to_odt.odt 
by one created on your machine.


Just create an empty document in Word and save it in odt format as 
FileVirtualTree_txt_to_odt.odt.


To change the font, don't modify it directly in the paragraph, but 
modify the default style,
change  the font of the default style to the one which fits the best for 
you.


Eventually, you could make a style with a specific name, and specify it 
in the pascal code.


I have changed the font of the default style to Consolas. It works on my 
Windows machine, but not on Ubuntu.


I have switched the language to English US too.

So I thought I should be able to just save a template with the font 
set to “Consolas” and the spacing set to “No Spacing” which is 
basically single spacing it..


Well when I save it like that, when I try to run it I get:

Unable to Open File: C:\Users\James\AppData\Local\Temp\Fi8004.odt

Press OK and risk data corruption or press abort to kill the program

I think it must have something to do with using Microsoft Word to save 
the template.


May be the file was already opened ? or the template broken ? (saved in 
docx format instead of 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-22 Thread Jean SUZINEAU via fpc-pascal

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

RE: [fpc-pascal] Directory Tree
My system could not find DejaVuSans,


You can find it in 
C:\lazarus\fpc\3.2.0\source\packages\fcl-report\demos\fonts.


May be you don't need to install the font, just add on the line below 
where you changed the font:


gTTFontCache.SearchPath.Add('C:\lazarus\fpc\3.2.0\source\packages\fcl-report\demos\fonts\');

but I found it in the code and changed it to Consolas which is always 
included with Windows and is a nice clear monospaced font with nice 
box characters.
Notice it shouldn't be the name displayed for the font by Windows, but 
its Postscript name, which is buried somewhere in the ttf file, for 
example CourierNewPSMT for Courier New.


It’s almost perfectthe only issue is that there is too much space 
between the lines, so the verticals don’t touch the way they are 
supposed it.. it’s not quite double spaced, more like 1-1/4 or 1-3/8 
spaced.. if it was single spaced it would be perfect.I don’t know how 
to control the spacing between lines.I made the font bigger but there 
was still a gap.If I could close that gap it would be perfect.


Is there an easy way to send a page break between the file list and 
the tree?


I'm not an expert of fcl-report but allowing to Michael Van Canneyt 
response to "fpreport: can not use two ObjectLists as datasource in one 
report" on 18/03/2021, I think this would be difficult. It think it 
would need 2 distinct databands which seems to be not possible.


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


Re: [fpc-pascal] Hello, new Pascal programmer. had a question!

2021-08-30 Thread Jean SUZINEAU via fpc-pascal

May be something like "Snap!" ?

https://snap.berkeley.edu/snap/snap.html#present:Username=trev1315=plane%202

https://snap.berkeley.edu/project?user=trev1315=plane%202

On my own, I think starting with Lazarus and GUI apps would be far easier.

If you create a new app from a template, you can get a running app 
nearly without typing anything.



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


Re: [fpc-pascal] Hello, new Pascal programmer. had a question!

2021-08-30 Thread Jean SUZINEAU via fpc-pascal

I've forgotten to add the link to "Snap!" manual:

https://snap.berkeley.edu/snap/help/SnapManual.pdf

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


Re: [fpc-pascal] Explicit Interface implementation and inheritance

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

Ooops, may be I hit reply too fast.

It looks like when you write " TObjB = class(TObjA, IBBB)" you just 
implement IAAA twice.

If you comment out IBBB
  TImpB = class(TImpA{, IBBB})
  public
    procedure CallOfB;
    //procedure IBBB.MethodB = CallOfB;
  end;

then the "No matching implementation" error disappears, the inherited 
implementation is well taken in account.


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


Re: [fpc-pascal] Explicit Interface implementation and inheritance

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

Le 15/08/2021 à 00:43, Dmitry Boyarintsev via fpc-pascal a écrit :
Why is interface implementation not inherited, if explicit 
implementation is used.


I guess this is because you can implement an interface through 
delegation too:


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

type
  IMyInterface = interface
procedure P1;
  end;

  TMyClass = class(TInterfacedObject, IMyInterface)
  private
FMyInterface: IMyInterface; // interface type
  public
property MyInterface: IMyInterface
   read FMyInterface implements IMyInterface;
  end;


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


Re: [fpc-pascal] Conversion from C to Pascal - Left bit shift

2021-09-03 Thread Jean SUZINEAU via fpc-pascal
I made a few tests on Ubuntu 64 bits (arch x86_64) with variations on a 
small test program:

var
   E2: Byte= 3;
   E1: LongWord= 1;
   E: QWord;
begin
 E:= (1000*E1) shl E2;
 writeln( 'E2', E2);
 writeln( 'E1', E1);
 writeln( 'E', E);
end.

In the assembly window, shl is computed on 64 bits %rax, I get :

project1.lpr:132 E:= (1000*E1) shl E2;
004011B2 8b05d8f50c00 mov 0xcf5d8(%rip),%eax    
# 0x4d0790 

004011B8 4869c0e803   imul $0x3e8,%rax,%rax
004011BF 0fb60dbaf50c00   movzbl 
0xcf5ba(%rip),%ecx    # 0x4d0780 

004011C6 48d3e0   shl    %cl,%rax
004011C9 48890580b51000   mov %rax,0x10b580(%rip)    
# 0x50c750 


Changing the formula to E:= E1 shl E2, shl computed on 32 bits %edx, (I 
don't understand the "and    %edx,%edx", may be just to clear the carry ?)

I get :

project1.lpr:132 E:= E1 shl E2;
004011B2 0fb605c7f50c00   movzbl 
0xcf5c7(%rip),%eax    # 0x4d0780 
004011B9 8b15d1f50c00 mov 0xcf5d1(%rip),%edx    
# 0x4d0790 

004011BF 89c1 mov    %eax,%ecx
004011C1 d3e2 shl    %cl,%edx
004011C3 21d2 and    %edx,%edx
004011C5 48891584b51000   mov %rdx,0x10b584(%rip)    
# 0x50c750 


Changing  E1 to QWord ( E1: QWord= 1; ), shl is computed on 64 bits 
%rax, I get :


project1.lpr:132 E:= E1 shl E2;
004011B2 0fb605c7f50c00   movzbl 
0xcf5c7(%rip),%eax    # 0x4d0780 
004011B9 488b15d0f50c00   mov 0xcf5d0(%rip),%rdx    
# 0x4d0790 

004011C0 4889c1   mov    %rax,%rcx
004011C3 48d3e2   shl    %cl,%rdx
004011C6 48891583b51000   mov %rdx,0x10b583(%rip)    
# 0x50c750 



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


Re: [fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

2021-10-05 Thread Jean SUZINEAU via fpc-pascal
I don't know if it's related, but I experienced a similar problem a few 
years ago.


It's a console dll written in Freepascal and compiled for Win64 and 
Linux (Ubuntu). It uses several threads and uses CheckSynchronize to 
make calls in the main thread.


The dll is loaded and used by a 4gl program (www.4js.com), I think the 
4gl runtime is compiled with Visual C++ on Windows and GNU C++ on Linux.


With recent (a few years ago) Freepascal a similar CPU consumption when 
idle appeared, but only in Windows, not in Linux.


I didn't needed recent functionalities of Freepascal, so a dirty 
workaround for me for this project was to stick to Lazarus 1.6 / 2016 02 
14 / FPC 3.0.0 / SVN 51360 (from menu Help/About Lazarus). I don't have 
the CPU consumption with this version.


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


Re: [fpc-pascal] FPC and WebAssembly

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

Wonderful !

Thank you very much for all your work and all the work of the FPC / 
Lazarus team !


And Merry Christmas for all !

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


Re: [fpc-pascal] BoolToStr

2022-08-29 Thread Jean SUZINEAU via fpc-pascal

Le 29/08/2022 à 01:41, James Richters via fpc-pascal a écrit :

If a special function is needed for some COM thing or weird Winapi thing, then 
that function should be part of the unit that needs it, not modifying the 
generic function intended to be used for general purpose applications output 
something that does not conform to other Pascal Boolean datatypes and just 
confuses everyone.
Unfortunately, it's not just a few windows functions which use this 
behaviour but the whole Windows API:


https://docs.microsoft.com/fr-fr/windows/win32/api/winuser/nf-winuser-getmessage?redirectedfrom=MSDN

The Microsoft BOOL datatype uses this convention so the whole ecosystem 
is attracted to use it (other C program on windows, Delphi, ... )


I imagine it's more efficient at the assembler level to process the 
result of functions returning boolean.


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


Re: [fpc-pascal] I am offering a $100 reward for linking static libraries

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

Le 01/09/2022 à 07:50, Michael Van Canneyt via fpc-pascal a écrit :
The file seems corrupt. I tried several programs, none managed to open 
it. 

Indeed more than corrupt. For me, file is just empty (size 0 byte)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-22 Thread Jean SUZINEAU via fpc-pascal

Le 22/10/2022 à 23:37, Bo Berglund via fpc-pascal a écrit :

If I could get at each output that mosquitto_cli writes into a script or such
then I would be good to go.

Maybe with a redirection ( > ) to a file in bash ?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Calculating CRC16?

2022-10-25 Thread Jean SUZINEAU via fpc-pascal
I couldn't verify the code but it should be  relatively close to your  
c++ example. Not sure of the width of int type, I supposed it's 16 bits 
wide:


function CRC16( crc: Word; buf: PByte; len: Word; Poly:Word=$A001): Word;
var
   pos: Word;
   i: Word;
begin
 for pos:= 0 to len-1
 do
   begin
   crc:= crc xor Word(buf[pos]);    // * XOR byte into least sig. byte of 
crc
   // * Loop over each bit
   for i:= 8 downto 1
   do
 begin
 // * If the LSB is set
 if ((crc and $0001) <> 0)
 then
 begin
 // * Shift right and XOR 0xA001
 crc:= crc shr 1;
    crc:= crc xor Poly;
 end
 // * Else LSB is not set
 else
 // * Just shift right
 crc:= crc shr 1;
 end;
   end;
  Result:= crc;
end;
var
   S: String;
begin
 Readln( S);
 WriteLn( IntToHex( CRC16( 0, PByte(@S[1]), Length(S), $8005), 4));
end.

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


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-24 Thread Jean SUZINEAU via fpc-pascal

Le 23/10/2022 à 23:59, Bo Berglund via fpc-pascal a écrit :

Might get stuck at readln(s) if no messages are sent, i.e. no carriage-return
coming along?
AFAIK readln is blocking, right?


I've made a test with mosquitto_pub, it seems there is a line ending at 
the end of each message, so you will be blocked  only when there are no 
new message available.


If your program needs to do something else during the wait for a new 
message, you'll need to dedicate a thread or a separate program.


Maybe dedicate a thread, putting your Readln (in the case of 
mosquitto_sub ... |SomePascalProgram) or  the loop (in the case of use 
of TProcess) in your TThread descendant Execute method.


There you when you receive a new mqtt message you can call 
TThread.Synchronize (on a method of your forms for example) to process 
the message in your main thread.


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


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-24 Thread Jean SUZINEAU via fpc-pascal
If your main program is a console program, it's likely that you'll need 
to call CheckSynchronize( from unit Class) in your main program/main 
thread from time to time in order to allow the execution of calls of 
methods specified in Synchronize in your thread (which reads mqtt messages).


I'm not 100% sure for recent freepascal, but I needed to do this in a 
pascal dll (with threads) called by a C++ program, the all running in 
console.


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


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-23 Thread Jean SUZINEAU via fpc-pascal

May be with a pipe |  ?

Something like

mosquitto_sub -h 192.168.117.131 -F '@Y-@m-@d @H:@M:@S ; %t ; %p' -t '#' | 
SomePascalProgram

This way you'll receive the output of mosquitto_sub on the standard 
input of SomePascalProgram.


I've tested locally on an Apache log with
   tail -f /var/log.apache2/access.log | grep http

Le 23/10/2022 à 15:31, Bo Berglund via fpc-pascal a écrit :

What happens if the data in the AProcess output stream is less than my buffer
size, will it then stall until as many messages have arrived as will fill the
buffer?


I think you can useAProcess.Output.NumBytesAvailable to avoid stalling 
and read just what is available :


https://www.freepascal.org/docs-html/fcl/pipes/tinputpipestream.numbytesavailable.html

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


Re: [fpc-pascal] MQTT package for freepascal/lazarus?

2022-10-23 Thread Jean SUZINEAU via fpc-pascal

Le 23/10/2022 à 22:50, Jean SUZINEAU via fpc-pascal a écrit :


This way you'll receive the output of mosquitto_sub on the standard 
input of SomePascalProgram.


A very small example for SomePascalProgram for  use with pipe, reading 
on standard input and writing on standard output :


var
   s: String;
begin
 repeat
   readln( s);
   writeln( s);
 until false;
end.

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


Re: [fpc-pascal] mciSendString with long file names

2022-09-20 Thread Jean SUZINEAU via fpc-pascal

May be by escaping the spaces with ^ ?

Something like:  MyFileName:= StringReplace(MyFileName, ' ', '^ ', 
[rfReplaceAll]);


^ is the escape char for cmd.exe but may be it is active in this context 
too ?


Le 20/09/2022 à 18:31, James Richters via fpc-pascal a écrit :


I just tried it that way:

Var

pcmd: String;

MyFileName: String;

pcmd:='play "'+MyFileName+'"'+#0;

mciSendString(@pcmd[1],Nil,0,0);

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


Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread Jean SUZINEAU via fpc-pascal
As Bart suggested, you can use too the for/in loop:  for s in sl do 
WriteLn( s);


For example:

var
   sl: TStringList;
   s: String;
begin
 sl:= TStringList.Create;
 try
    sl.Add('1');
    sl.Add('2');
    for s in sl do WriteLn( s);
 finally
    FreeAndNil( sl);
    end;
end.

Output:

1
2

This works on arrays and strings too.

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


Re: [fpc-pascal] Union field after property violates "field before property" rule + property of union field not possible.

2022-08-15 Thread Jean SUZINEAU via fpc-pascal

May the solution to your problem should be just :

 TDataExample
 =
  record
    case integer
    of
  0: (mData: Int64);
  1: (mByte: packed array[0..7] of Byte);
  2: (UnionField: Int64);
  end;

?

You aren't going to define a getter or setter method on your property, 
just an "alias" to mData ?


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


Re: [fpc-pascal] Union field after property violates "field before property" rule + property of union field not possible.

2022-08-15 Thread Jean SUZINEAU via fpc-pascal
For this particular error I think you should just follow the advice of 
compiler in the error message :


Le 14/08/2022 à 11:49, Skybuck Flying via fpc-pascal a écrit :

// normal/standard property
property StandardField : integer read mStandardField write 
mStandardField;


mStandardField : integer;  // ERROR "field definition not 
allowed after methods or properties" problem 2.


Error: Fields cannot appear after a method or property definition, 
start a new visibility section first


  property StandardField : integer read mStandardField write 
mStandardField;

public
 mStandardField : integer;

But I think you'll get then, on the property line :
Error: Unknown class field or method identifier "mStandardField"

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


Re: [fpc-pascal] Union field after property violates "field before property" rule + property of union field not possible.

2022-08-15 Thread Jean SUZINEAU via fpc-pascal

An if you eventually need a read only UnionField :

 TmByte= packed array[0..7] of Byte;
 TDataExample2
 =
  record
    internal
    :
 record
   case integer
   of
 0: (mData: Int64);
 1: (mByte: TmByte);
 end;
   property mByte : TmByte read internal.mByte;
   property UnionField: Int64  read internal.mData;
  end;

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


Re: [fpc-pascal] Why does RunCommand not produce the correct output?

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

Le 01/05/2023 à 17:00, Bo Berglund via fpc-pascal a écrit :

I have created a shellscript with the same command string


May be running directly your script in bash:

RunCommand('/bin/bash', ['your_script.sh' ], OutData)

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


Re: [fpc-pascal] Why does RunCommand not produce the correct output?

2023-05-01 Thread Jean SUZINEAU via fpc-pascal
I don't have an example at hand but I think you should run a bash 
interpreter, something like :


RunCommand('/bin/bash', ['-c', ListCmd], OutData)

but I'm not 100% sure.
There is a good documentation at:
https://wiki.freepascal.org/Executing_External_Programs

May be you need to split your command in several calls and use

AProcess.Options  :=  [poUsePipes];
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pause Key

2023-04-14 Thread Jean SUZINEAU via fpc-pascal
... I wouldn't be surprised that James's program is a console one, not 
using TForm nor any windows message loop to process WM_ messages, but I 
may be wrong.


It can be more tricky in this case.

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


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-05 Thread Jean SUZINEAU via fpc-pascal
May be you could get the source code of i2ctransfer from i2c-tools and 
compare it with the code in i2c.pas ?

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


Re: [fpc-pascal] fpc isn't optimised for tail recursion, is it?

2023-06-13 Thread Jean SUZINEAU via fpc-pascal

Le 12/06/2023 à 19:05, Steve Litt via fpc-pascal a écrit :

Busted! I used Pascal 1984-1993
So I guess you are not familiar too with the "Result" variable which 
appeared with Delphi 1 in 1995 if I remember correctly.


nextt:= num;

can be written to as :

Result:= num;

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

I prefer Result because it reduces risks of confusion with recursive call
and you can eventually take the address of Result with @Result (where 
@nextt would take the address of the function nextt),
pass it by reference to another function ( e.g. FillChar( Result, 
SizeOf(Result), 0); ) ,

it behaves like a normal variable.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Function to create a record ?

2023-06-05 Thread Jean SUZINEAU via fpc-pascal

Hello, I have a hard time trying to understand what you want to test.

In your functions, you are using a record, not a class or a pointer to 
record or an object.


The personrecord just behave in your parameters and return value as an 
Integer or a String, and your fillchar doesn't write outside of the 
memory allocated for you junkvar, so I don't see what can go wrong.


If you trace the address of person.name like this:

//begin code
begin
person := newperson();
writeln('1, person.name address: ', 
IntToHex(Int64(Pointer(@(person.name);
fillchar(junkvar, junkvar_size, 'a');
person2 := newperson();
fillchar(junkvar, junkvar_size, 'b');
person := modperson(person, 'Martin');
person := modperson(person2, 'Maria');
writeln('2, person.name address: ', 
IntToHex(Int64(Pointer(@(person.name);
{writeln(junkvar);}
writeperson(person);
writeperson(person2);
end.
//end code

You'll see that the address doesn't change, for example:

1, person.name address: 0050C7F0
2, person.name address: 0050C7F0


But if you declare your personrecord as a class, the things doesn't 
behave the same way:


//begin code
const
junkvar_size = 2000;

type
personclass = class
name: string;
end;
var
person: personclass;
person2: personclass;
junkvar: array[1..junkvar_size] of char;

function newperson(): personclass;
var newp: personclass;
begin
 newp:= personclass.Create;
newp.name := '';
newperson := newp;
end;

function modperson(person: personclass; name: string): personclass;
begin
person.name := name;
modperson := person;
end;

procedure writeperson(person: personclass);
begin
writeln(person.name);
end;

begin
person := newperson();
writeln('1, person.name address: ', 
IntToHex(Int64(Pointer(@(person.name);
fillchar(junkvar, junkvar_size, 'a');
person2 := newperson();
fillchar(junkvar, junkvar_size, 'b');
person := modperson(person, 'Martin');
person := modperson(person2, 'Maria');
writeln('2, person.name address: ', 
IntToHex(Int64(Pointer(@(person.name);
{writeln(junkvar);}
writeperson(person);
writeperson(person2);
end.
//end code


You'll get a different address, something like:


1, person.name address: 77F910E8
2, person.name address: 77F91108
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Function to create a record ?

2023-06-05 Thread Jean SUZINEAU via fpc-pascal

Oops, I hit "Send message" too quickly.

The only difference in the second code is:

- personrecord renamed to personclass and declared as "personclass = class"

- "newp:= personclass.Create;" added in function newperson

Of course for a clean code, you'll need to call something like 
"FreeAndNil( person);" or "person.free" to release properly the memory 
allocated.



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


Re: [fpc-pascal] fpc isn't optimised for tail recursion, is it?

2023-06-12 Thread Jean SUZINEAU via fpc-pascal
According to you other posts, I won't be surprised that you think in a 
C/C++ way.

This doesn't change anything in your last example, but particularly  :

nextt := num;

doesn't behave like in C :

return num;

In pascal I think the equivalent would be :

nextt := num; exit;

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


Re: [fpc-pascal] Legitimate use of for and break

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

Le 17/06/2023 à 20:07, Travis Siegel via fpc-pascal a écrit :

Is this a relatively new addition to fpc or something?


I 've just found it in my Delphi 7 code (and code very likely written 
for Delphi 4), so I think it's there since at least 2000-2001 ...


May be it appeared with Delphi 1 ?

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


Re: [fpc-pascal] Microsoft SAPI on Freepascal

2023-06-26 Thread Jean SUZINEAU via fpc-pascal
It sounds like "SpVoice := CreateOleObject('SAPI.SpVoice');" is failing 
and then SpVoice is nil ?


May be try with an OleVariant instead of a simple Variant ? (i.e declare 
var SpVoice: OleVariant; )
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Floating point question

2024-02-06 Thread Jean SUZINEAU via fpc-pascal
I've just made a small test with the old Borland Delphi 7.0 build 4453 
from 2002 :


...

type
  TForm1 = class(TForm)
m: TMemo;
procedure FormCreate(Sender: TObject);
  end;

...

procedure TForm1.FormCreate(Sender: TObject);
var
   GG: Extended;
   S: String;
begin
 GG := 8427+33/1440.0;
 Str( GG: 20 : 20, S);
 m.Lines.Add( 'GG = '+S);
end;

I get :

GG = 8427.02291700

But I'm cautious, it's a delphi 7 running on a broken installation of 
Wine on Ubuntu 22.04,
I had to modify an existing delphi 7 project for this test, I couldn't 
save a new project because of problems with wine.


I have an old astronomical made with delphi 7 that I've written around 
2000, and I ported a part of it to Freepascal, I'm nearly sure there are 
unnoticed errors in this freepascal port due to to this behaviour ...
(Not really a problem because the program isn't sold any more, but I'll 
have a look next time I compile it)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Floating point question

2024-02-09 Thread Jean SUZINEAU via fpc-pascal

Le 09/02/2024 à 20:53, Jonas Maebe via fpc-pascal a écrit :
However, adding support for an option called -CFMax or similar should 
be no problem. 

It would be very nice to compile old code
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Labels

2023-12-18 Thread Jean SUZINEAU via fpc-pascal

Le 17/12/2023 à 17:47, Adriaan van Os via fpc-pascal a écrit :

Turbo Pascal (5.5) defines

label = digit-sequence . 

Are you sure ?
I had a doubt and I had a look in some very old source code from 1990 
made with tp 5.5, it seems you could have letters in labels.


Excerpt of the code:

PROCEDURE EntCh(var col,lin,lmax:byte;var nbre:boolean;var ch:string);

{entr‚e d'une chaŒne de longueur maxi lmax, si nbre=true, on ne peut entrer}

{que des nombres, signes - et + et point d‚cimal   }

LABEL    e00,e01,e02,e03,e04;

VAR  q,cpos,i,v:byte;

 k   :char;

BEGIN   e00:ch:='';

    q :=0;

    cpos:=col;

    gotoXY(col,lin);

    textbackground(7);textcolor(0);

    for i:=1 to lmax do write('_');

    gotoXY(col,lin);goto e02;

    e01:bip;

    e02:k:=readkey;v:=ord(k);

    if ((q>0) and (v=8)) then

    begin

 cpos:=cpos-1;q:=q-1;

 gotoXY(cpos,lin);write('_');

 ch:=left(ch,length(ch)-1);

 gotoXY(cpos,lin);

 goto e02;

    end;

    if ((q=0) and (v=13)) then

    begin

 ch:=k;goto e04;

    end;

    if (v=13) then goto e04;

    case nbre of

    true : if ((v>47)and (v<58)) or (v=46) then

   goto e03 else goto e01;

    false: if (v>31) then goto e03 else goto e01;

    end; {case nbre of}

    e03:q:=q+1;if (q>lmax) then goto e01;

    write(k);ch:=ch+k;cpos:=cpos+1;goto e02;

    e04:textbackground(0);textcolor(7);

    gotoXY(col,lin);write(ch);write(space(lmax-length(ch)));

END; {procedure EntCh(...)}

{--}

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


Re: [fpc-pascal] case statement

2023-12-15 Thread Jean SUZINEAU via fpc-pascal

Le 15/12/2023 à 10:39, Adriaan van Os via fpc-pascal a écrit :

I don't see a semicolon in the formal syntax.

May be included in the ' "DO" statement ' ?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Jean SUZINEAU via fpc-pascal

Le 08/01/2024 à 13:51, Peter B via fpc-pascal a écrit :

   or if not, is there another way to
turn it on in the textmode IDE?

No idea. Its easy enough if you compile from the command line.
fpc -Os -XX hello.pas

If stripping is not on by default, also use -Xs 


I guess that in the textmode IDE you just have to go Options/Compiler
and in the bottom in "Additional compiler args"
you just have to add -Os -XX - Xs

-Os :  Optimize for size rather than speed
-Xs  :  Strip all symbols from executable
-XX : Try to smartlink units (defines FPC_LINK_SMART)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Floating point question

2024-02-22 Thread Jean SUZINEAU via fpc-pascal

Le 22/02/2024 à 15:08, Thomas Kurz via fpc-pascal a écrit :

But it's supported on Linux but not on Windows? Huh?

As far as I know Extended is not supported on Linux.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Floating point question

2024-02-22 Thread Jean SUZINEAU via fpc-pascal
I see that Wikipedia is not very clear on this,  you just find "x86" 
mentioned, but for Pascal: "this Extended type is available on 16, 32 
and 64-bit platforms, possibly with padding"


https://en.wikipedia.org/wiki/Extended_precision

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


Re: [fpc-pascal] Type-casting a class variable

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

I didn't tested but I imagine it could be done with something like this ?

type
   TWindow_Class= class of TWindow;
begin
  ...
  (myClass as TWindow_Class).CreateNewWindow( );

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


<    1   2