Re: [fpc-pascal] Signing applications, how?

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

I couldn't manage to create a pfx from PuttyGen or from openssl.

Following Derek Edson's advice, I went into mmc and could see that a 
certificate was already created in my name.


In start menu, I opened under menu Visual Studio 2019 the shortcut 
Developer PowerShell for VS 2019 and typed on the command line:


signtool sign /a /fd SHA256  path_to_my_executable

and it choosed automatically my certificate to sign the executable.
Then it seems that you can add this certificate to Windows trusted 
certificates.


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


Re: [fpc-pascal] Signing applications, how?

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

I haven't tested yet for windows executables,

but recently for Android I had to sign an apk made with Lazarus for 
Android Module Wizard,


you just need a free certificate created with Android Studio .

May be for Windows a certificate created with Puttygen is sufficient ?

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


[fpc-pascal] broken link in wiki

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

It seems that in
https://wiki.freepascal.org/Translations_/_i18n_/_localizations_for_programs
in the paragraph "Quick i18n", it seems the link
   (source  ) 
http://www.redlinels.com/2014/01/10/most-widely-spoken-languages/

is no longer valid anymore.
___
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


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] 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-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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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
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-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-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] 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-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] 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-11 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] I am offering a $100 reward for linking static libraries

2022-08-31 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] 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] 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] 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] 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] 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] 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] 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] 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&ProjectName=plane%202&editMode&noRun

https://snap.berkeley.edu/project?user=trev1315&project=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] Explicit Interface implementation and inheritance

2021-08-14 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] TRegistry documentation

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


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

gives

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



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


Re: [fpc-pascal] TRegistry documentation

2021-06-16 Thread 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

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-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] 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] 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] 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-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] 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-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-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-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 à 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-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-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-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-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] 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-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-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-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-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


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-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-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-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-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
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-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-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-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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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


  1   2   >