[fpc-pascal] Trash variables (-gt) - Translation

2024-01-17 Thread LacaK via fpc-pascal

Hi *,
I am translating "Trash variables" (from English to Slovak), but I can 
not find appropriate words.

That's why I want to describe it in more words.
Is this correct: "Initialize local variables with random values" ? Or 
better suggestion?

Thanks
-Laco.

https://www.freepascal.org/docs-html/user/userap1.html:
-gt    Trash local variables (to detect uninitialized uses; multiple 
't' changes the trashing value)

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


Re: [fpc-pascal] no array support in sqldb/sqldbrestbridge?

2022-06-07 Thread LacaK via fpc-pascal

Hi,


So, is there no array field support in sqldb and/or in sqldbrestbridge?

there was added into DB.pas : TObjectField and TArrayField 
https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-db/src/base/db.pas

but implementation is incomplete. Methods in fields.inc are empty.

Also in TSQLConnection descendants (like TPQConnection) there is no support.

-Laco.

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


Re: [fpc-pascal] converting to UTF8

2022-03-23 Thread LacaK via fpc-pascal



procedure TestString;
var
  Original:string;
  Converted:string;
begin
  original:='ESPA'#209'A'; //ESPAÑA WIN1252
  Converted:=ansiToUtf8(original);  // converts to 'ESPA'#239#191#189'A'
 // converted Should be 'ESPA'#195#145'A'
end;

I've tried playing with strings types, string, rawstring,ansistring, 
utf8string. No way. Any hint?




To explicityly convert between run-time code pages you can use 
procedure: SetCodePage(var s: RawByteString; CodePage: TSystemCodePage; 
Convert: Boolean = True)


SetCodePage(original, 1252, False);
SetCodePage(original, CP_UTF8, True);

-Laco.

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


Re: [fpc-pascal] Text Only printing on Windows.

2022-02-10 Thread LacaK via fpc-pascal
Look at TPrinter.RawMode : 
https://lazarus-ccr.sourceforge.io/docs/lcl/printers/tprinter.rawmode.html 
and TPrinter.Write


 Printer.Title := 'xyz';
 Printer.RawMode := True;
 Printer.BeginDoc;
 Printer.Write('^MTD'); //direct thermal media
 Printer.EndDoc;

L.


Does anyone know of a way to just send pain text

to a USB printer with FPC ,preferably without Lazarus?




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


Re: [fpc-pascal] Repost: TFieldType declaration change in FPC fixes_3_2 branch

2021-10-18 Thread LacaK via fpc-pascal



/Reposted with correct branch identifier/.

I thought that a fixes branch was only for bug fixes and not for 
issuing non-backwards compatible changes. However, TFieldType in 
db.pas now has 6 extra elements.


The result is that IBX no longer compiles with the fixes_3_2 branch. I 
have also heard the same for zeoslib.


As far as I can see ZEOS is full of checks like:
{$IF FPC_FULLVERSION>=30100} ...

So I think that one more check:
{$IF FPC_FULLVERSION>30200}
  {$DEFINE WITH_FTSHORTINT} // ftShortInt 
is supported
  {$DEFINE WITH_FTBYTE} // ftByte is 
supported
  {$DEFINE WITH_FTEXTENDED} // ftExtended 
is supported

  {$DEFINE WITH_FTLONGWORD} // ftLongWord is
{$ENDIF}
... is not so big problem? (I see there is already in ZEOS such check 
added ...)


In IBX there you have "DefaultFieldClasses" array which is affected, right?

I agree that it is not ideal situation, but release cycle for major 
versions of FPC are so long that postpone all these additions to major 
releases means that users must wait years ...


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


Re: [fpc-pascal] FreePascal and MySQL 8.0

2021-09-21 Thread LacaK via fpc-pascal




https://github.com/fpc/FPCSource/tree/main/packages/mysql

I do not understand. I see a source file for mysql80dyn.pp, but
shouldn't tthere also be a mysql80conn.pp?
It is in 
https://github.com/fpc/FPCSource/tree/main/packages/fcl-db/src/sqldb/mysql

L.

___
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 LacaK via fpc-pascal


Can we say that in Pascal the result of:
    E1 shl E2
is of same type as E1 ?
(so if E1 is LongWord then result is LongWord also?)

What if there is an expression on left side:
    (E1*x) shl E2
Will E1*x promote to 64 bits (on 64 bit target)?


See documentation on automatic type conversion (the remarks section 
below table 3.3): 
https://www.freepascal.org/docs-html/ref/refsu4.html#x26-26004r3 

While this doesn't explicitly mention shift behaviour, it implies that 
E1 and (E1*x) will be promoted to native sized integer if smaller.  For 
the first example, if E1 is a longword on a 32 bit machine, the result 
should also be a longword.




But look at Delphi documentation: 
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Expressions_(Delphi)#Logical_.28Bitwise.29_Operators


"The operations x shl y and x shr y shift the value of x to the left or 
right by y bits, which (if x is an unsigned integer) is equivalent to 
multiplying or dividing x by 2^y; the result is of the same type as x"


My understanding is, that in case:
  E1 shl E2 result is of E1 type (so if E1 is LongWord on 64 bit 
platform result is still LongWord?)


Case
  (E1*x) shl E2 is subject to native integer promotion I guess?

L.
___
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 LacaK via fpc-pascal

Can we say that in Pascal the result of:
  E1 shl E2
is of same type as E1 ?
(so if E1 is LongWord then result is LongWord also?)

What if there is an expression on left side:
  (E1*x) shl E2
Will E1*x promote to 64 bits (on 64 bit target)?

-Laco.


Hello *,

I have code in C like this:
  E1 << E2
If E1 is of unsigned type then "The value of E1 << E2 is E1 
left-shifted E2 bit positions; vacated bits are zero-filled. If E1 has 
an unsigned type, the value of the result is E1 × 2^E2, reduced modulo 
one more than the maximum value representable in the result type."


I understand this as result of such operation does not grow over 32 
bits, right?


In Pascal I have:
  E1 shl E2
where E1 is of LongWord type.

On 64-bit target this result of shl can overcome 32 bits (iow operates 
on 32 bits)?
(does also bit shift operations works on 64 bits or this only affect 
arithmetic operations like multiply?)


Assembler suggests that shl works on 32 bits: shl    %cl,%r11d

-Laco.



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


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

2021-09-02 Thread LacaK via fpc-pascal

Hello *,

I have code in C like this:
  E1 << E2
If E1 is of unsigned type then "The value of E1 << E2 is E1 left-shifted 
E2 bit positions; vacated bits are zero-filled. If E1 has an unsigned 
type, the value of the result is E1 × 2^E2, reduced modulo one more than 
the maximum value representable in the result type."


I understand this as result of such operation does not grow over 32 
bits, right?


In Pascal I have:
  E1 shl E2
where E1 is of LongWord type.

On 64-bit target this result of shl can overcome 32 bits (iow operates 
on 32 bits)?
(does also bit shift operations works on 64 bits or this only affect 
arithmetic operations like multiply?)


Assembler suggests that shl works on 32 bits: shl    %cl,%r11d

-Laco.

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


Re: [fpc-pascal] Raise exception in libray which will not halt host application

2021-08-26 Thread LacaK via fpc-pascal



Please note that you won't be able to catch such an exception with 
the type from within the application, e.g.:


=== code begin ===

try
  SomeLibraryFunction;
except
  on e: TMyObject do
 Whatever;
  else
 WhateverElse;
end;

=== code end ===

The above code would go to the first branch *inside* your library, 
but it will *always* go to the else-branch outside your library, 
cause the comparison is done on the pointer to the VMT (the class 
type) which will be *different* between library and application 
(even if you use the same unit!). This is one of the main reasons 
why dynamic packages are needed for comfortable use of libraries in 
Object Pascal, because it allows such types to be shared across 
module boundaries.



My situation is even worser :-)
Library DLL is writen in Pascal, but main application is C/C#.


Then it will probably be caught as some external exception or such... 
don't know, never tried it.
*“System.Runtime.InteropServices.SEHException (0x80004005): External 
component has thrown an exception.”*





When I call in library RunError() then whole application aborts.
I need throw exception in library which can be catched in application.

I now use in unit which is used by library:

  if System.IsLibrary then
    raise TObject.Create // raise exception - type of exception is 
not important ...
    // can I call here also Windows's RaiseException()? ... so it 
will be propagated to linking application?

  else
    System.RunError(w);


"raise" internally uses . The only difference would be that you'd have 
a bit more control of exception code and such if you want to ensure 
that it's caught nicely by the C/C++/C# code.


Ok, then if raise TObject.Create; calls RaiseException then I think that 
I will use raise TObject.Create;

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


Re: [fpc-pascal] Raise exception in libray which will not halt host application

2021-08-26 Thread LacaK via fpc-pascal




Am 26.08.2021 um 10:10 schrieb LacaK via fpc-pascal:

Thank you for both answers!


Please note that you won't be able to catch such an exception with the 
type from within the application, e.g.:


=== code begin ===

try
  SomeLibraryFunction;
except
  on e: TMyObject do
 Whatever;
  else
 WhateverElse;
end;

=== code end ===

The above code would go to the first branch *inside* your library, but 
it will *always* go to the else-branch outside your library, cause the 
comparison is done on the pointer to the VMT (the class type) which 
will be *different* between library and application (even if you use 
the same unit!). This is one of the main reasons why dynamic packages 
are needed for comfortable use of libraries in Object Pascal, because 
it allows such types to be shared across module boundaries.



My situation is even worser :-)
Library DLL is writen in Pascal, but main application is C/C#.
When I call in library RunError() then whole application aborts.
I need throw exception in library which can be catched in application.

I now use in unit which is used by library:

  if System.IsLibrary then
    raise TObject.Create // raise exception - type of exception is not 
important ...
    // can I call here also Windows's RaiseException()? ... so it will 
be propagated to linking application?

  else
    System.RunError(w);

L.

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


Re: [fpc-pascal] Bookmark, TBookmarkStr, TBytes and BytesOf

2021-08-26 Thread LacaK via fpc-pascal





I have considered to convert the TBytes to AnsiString, but instead to 
doing a research about AnsiString internals, or creating a function 
that copies bytes in a loop, I supposed that there was already a 
function to do that. I found BytesOf

https://www.freepascal.org/docs-html/rtl/sysutils/bytesof.html
The abstract is  "Return the bytes in a string", when in fact, 
according with the text below,  it does the opposite, returns the 
string in an array of bytes.


Is there any function that move the bytes to an AnsiString?

AFAICS there is only 
https://www.freepascal.org/docs-html/rtl/sysutils/stringof.html

L.

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


Re: [fpc-pascal] Raise exception in libray which will not halt host application

2021-08-26 Thread LacaK via fpc-pascal

Thank you for both answers!
L.





On Thu, 26 Aug 2021, LacaK via fpc-pascal wrote:


Hello,
is there way how to raise exception in library without using SysUtils?


Raise TMyObject.Create()

Where TMyObject does not descend from Exception.

Sysutils is needed for the definition of the Exception class, and 
because it

installs some runtime error to exception conversion hooks, but you can
perfectly use exceptions without using the sysutils unit.

Michael.

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


[fpc-pascal] Raise exception in libray which will not halt host application

2021-08-26 Thread LacaK via fpc-pascal

Hello,
is there way how to raise exception in library without using SysUtils?
Now I call System.RunError() in case unexpected situation occurs in 
library (DLL), but this exits also application which links library.
Is there way how to exit library in a way that application can catch 
exception (without SysUtils).
If there is Windows call which can be used it is sufficient, as library 
is Win64 only.

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


[fpc-pascal] Conditional compilation using {$IFOPT ...} and {$IF OPTION(...)}

2021-08-25 Thread LacaK via fpc-pascal

Hello,
looking at 
https://www.freepascal.org/docs-html/prog/progsu126.html#x139-142.4.1


There is mentioned "OPTION(opt)" with comment: "evaluates to TRUE if a 
compiler option is set (mode MacPas only). It is equivalent to the 
{$IFOPT } directive."


1. What is equivalent usage for {$IFOPT R+}?
{$IF OPTION(R)} ?

2. What means comment "(mode MacPas only)"?
It will does not work for example for ObjPas mode? In my case 
Compilation fails ... (with single {$IF OPTION(R)} ) -> Error: Compile 
time expression: Wanted Boolean but got AnsiString at IF or ELSEIF

Can this OPTION be enabled for all modes?

3. Is there way how to do OR with {$IFOPT}?
if I use {$IF OPTION(R) OR OPTION(D)}  I get: "Error: Compile time 
expression: Wanted Boolean but got AnsiString at IF or ELSEIF" ...

So is there way how to do it with {$IFOPT R+D+}?

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


Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?

2021-08-11 Thread LacaK via fpc-pascal






It's like switching car brands from a VW to an Audi or so.
Some buttons are in different places, your key will maybe look
different,
but that's it. It's a car, it brings you from a to b.

It's not switching brands, it's switching the type of the car.
from a passenger i.e. to a bus.
It's still a car, but the concept is a little different.

A file version system manages versions of files.
The actual commands differ a little, but that's it.


The human psychology. There were no particular problems for anyone to 
use SVN.
It worked fine. So for the people it doesn't seem like an obvious 
reason for the change.
The change is not recognized by the brain as a needed change, as a 
cure of some sort.

Instead it's recognized as an unnecessary burden.


I must say that I have similar feelings.
No matter ...
I have related question: in SVN was possible to checkout specific 
sub-directory (for example if I am interested in fcl-db package only I 
checkedout only this sub-directory).
Is it possible with gitlab? Or I must clone whole 
https://gitlab.com/freepascal.org/fpc/source ?

Thanks ...
-Laco.

___
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 LacaK via fpc-pascal



Since the final binary size after using strip -s on the exe file is
271 kb it seems a bit big!
Or is there a lot behind the scenes I have missed?

Classes is a hog.


I had a look, and only tthreadlist (and with that tlist) were 
instantiated in the startupcode.
There are also global variables, which involve for example TComponent 
(and interfaces) ...
(see also thread "Minimal size of compiled library (DLL under Windows)" 
in this list from April 2021)

L.

___
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 LacaK via fpc-pascal





Since the final binary size after using strip -s on the exe file is
271 kb it seems a bit big!
Or is there a lot behind the scenes I have missed?

Classes is a hog.

If you want smallest executable size you must get rid of SysUtils also.
And you must call platform dependent OS API ...

L.

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


Re: [fpc-pascal] non-virtual class methods called from virtual regular method

2021-04-29 Thread LacaK via fpc-pascal


Dňa 29.4.2021 o 9:26 Michael Van Canneyt via fpc-pascal napísal(a):



On Thu, 29 Apr 2021, LacaK via fpc-pascal wrote:


Hi *,

consider the following example

T1 = class
  class procedure CP1;
  procedure P1; virtual;
end;

T2 = class(T1)
  class procedure CP1;
end;

procedure T1.P1;
begin
  CP1; // here is called allways T1.CP1, right?
  // if I want call T2.CP1 then class procedure CP1 must be also 
virtual, right?


Yes

  // so Self.CP1 does not take runtime type but is staticaly resolved 
at compile time to T1.CP1 ?


Yes.


This is bit counter-intuitive for me:

In regular virtual method, I expect, that Self resolves to runtime class 
type, thust calling CP1 should resolve to runtime type class method.


But from compiler POV I understand, that symbol CP1 must be somehow 
resolved at compile time, so compiler looks at CP1 method definition 
(and if not virtual then resolves to class method of type where is used).


In principle *virtual* class methods as such are for me strange ;-)




end;

var
  c1: T1;

begin
  c1:=T2.Create;
  c1.P1; // here is called T2.P1 - runtime class type
end.

Thanks

Btw If I need for various class descendants define various class 
constants, it is possible only by using class functions (getters), 
where descendant class getter hides parents getter?


If they depend on the class, they're not "constants" to begin with, so a
getter function is the right approach. For such purposes I use virtual 
class

functions.


Yes, on other side virtual constants will be construct which I would 
understand better:


If I need override some class wide parameter:

T1 = class
  private const CPORT=0; // virtual
end;

T1 = class (T2)
  private const CPORT=2; // override
end;

Now I must do:

T1 = class
  private class procedure GetPORT: integer; virtual;
end;

T2 = class(T1)
  private class procedure GetPORT: integer; override;
end;

class procedure T1.GetPORT: integer;
begin
  Result := 0;
end;

class procedure T2.GetPORT: integer;
begin
  Result := 2;
end;

I accept, that polymorphism in class inheritance work this way ...

L.


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


[fpc-pascal] non-virtual class methods called from virtual regular method

2021-04-29 Thread LacaK via fpc-pascal

Hi *,

consider the following example

T1 = class
  class procedure CP1;
  procedure P1; virtual;
end;

T2 = class(T1)
  class procedure CP1;
end;

procedure T1.P1;
begin
  CP1; // here is called allways T1.CP1, right?
  // if I want call T2.CP1 then class procedure CP1 must be also 
virtual, right?
  // so Self.CP1 does not take runtime type but is staticaly resolved 
at compile time to T1.CP1 ?

end;

var
  c1: T1;

begin
  c1:=T2.Create;
  c1.P1; // here is called T2.P1 - runtime class type
end.

Thanks

Btw If I need for various class descendants define various class 
constants, it is possible only by using class functions (getters), where 
descendant class getter hides parents getter?


-Laco.

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


[fpc-pascal] Inline assembler m32 source operand

2021-04-12 Thread LacaK via fpc-pascal

Hi,

how can I address m32 source operand in inline assembler instruction like :

asm
  ...
  VBROADCASTSS m32, %xmm1;
  ...
end;

if I would like broadcast to %xmm10 single 32bit value at given memory 
location in:


const SI:single=0.1;
or
var SI:single=0.1;

Now I do it by (it works):
asm
  ...
  mov $SI, %rax;
  vbroadcastss (%rax), %xmm10;
  ...
end;

00010020C4CF 48b8b04327000100 movabs $0x1002743b0,%rax
00010020C4D9 c462791810   vbroadcastss (%rax),%xmm10

Is there shorter - one liner - way? Something like:
  vbroadcastss SI, %xmm10; // compiles, but causes A/V when executed, 
because only low 32bit of address is taken (x86_64):


00010020C4D9 c46279181425b0432700 vbroadcastss 0x2743b0,%xmm10

Thanks

-Laco.

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


Re: [fpc-pascal] Minimal size of compiled library (DLL under Windows)

2021-04-06 Thread LacaK via fpc-pascal

May be, that important word is here "referenced" code.
Once some code (procedure, class) is referenced then this code is linked 
/ included.
It does not play role if it is really required by program / library ... 
right?


L.


So we see that classes like TComponent and also interfaces are touched,
but they are used only in conjuction with initilizing some global
variables like InitHandlerList, GlobalNameSpace.

But these variables are never used in my library. Only again in
finalization sections of above mentioned units.

They are used in your library as far as the linker is concerned, because
the init and finalisation sections are code like any other code.


Does it means, that smart-linking can not remove this code due to usage
of this global variables in finalization section (resp. initialization
sections)?

Indeed.


Probably it is too hard task for linker to determine which code is realy
not needed ... WPO in this regard can not help?

No. There is no way for WPO to know what side effects the initialisation
of those variables could have.


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

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


Re: [fpc-pascal] Minimal size of compiled library (DLL under Windows)

2021-04-06 Thread LacaK via fpc-pascal




I am guessing, that there must be something in initialization 
sections of units (SysUtils and Classes), which cause that some code 
is included, right?
Can I somehow to avoid this grow of size (for example I need from 
Classes only TFPList)?


Not in an easy way at the moment, I don't expect it to change anytime 
soon.


The problem is probably the streaming system that the compiler can't 
easily determine if it is used runtime. This also has resourcestrings 
as errors, uses typeinfo etc etc.  I also see interface related 
support probably because tcomponent also implements interfaces.



What I can say is, that in initialization sections are touched:

SysUtils: WidestringManager, Exceptions, FormatSettings
Classes: TCriticalSection, TList, TThreadList, TComponent 
(IUnknown,IDispatch, RegisterInitComponentHandler() -> var 
InitHandlerList), Interface (var GlobalNameSpace: IReadWriteSync)


So we see that classes like TComponent and also interfaces are touched, 
but they are used only in conjuction with initilizing some global 
variables like InitHandlerList, GlobalNameSpace.


But these variables are never used in my library. Only again in 
finalization sections of above mentioned units.


Does it means, that smart-linking can not remove this code due to usage 
of this global variables in finalization section (resp. initialization 
sections)?


Probably it is too hard task for linker to determine which code is realy 
not needed ... WPO in this regard can not help?


-Laco.


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


[fpc-pascal] Minimal size of compiled library (DLL under Windows)

2021-04-03 Thread LacaK via fpc-pascal
Hi,I did small test project for library:(with -CX -WR -O3 -Xs -XX options set)library library1;{$mode objfpc}{$H+}uses  SysUtils, Classes;beginend.  Compilation produces DLL with size 200+ KB.When in uses is only SysUtils then size is under 100 KB.Whene there are not units in uses clause then size is under 40 K
 B.I am guessing, that there must be something in initialization sections of units (SysUtils and Classes), which cause that some code is included, right?Can I somehow to avoid this grow of size (for example I need from Classes only TFPList)?TIA-Laco.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Smart-linking versus Whole Program Optimization

2021-03-10 Thread LacaK via fpc-pascal



It will be nice have this in documentation. For example in
https://www.freepascal.org/docs-html/prog/progse30.html#x195-207.3

At least explain:
- relation of -CX and -XX

Indeed.


- what is to be removed: non-referenced non-virtual methods, global
variables, and regular procedures/functions

Disagreed. Those are implementation details, may vary from target to
target, may depend on the assembler/linker rather than on FPC, etc. What
I wrote is just the high level idea. When you have e.g. published
properties and their RTTI, you can easily start having a lot of hidden
references.
I do not insist that it must be written in this way, but something 
should be there explained.


Goal is that: reader should understand what can expect from smart-linking.

-Laco.

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


Re: [fpc-pascal] Smart-linking versus Whole Program Optimization

2021-03-10 Thread LacaK via fpc-pascal
It will be nice have this in documentation. For example in 
https://www.freepascal.org/docs-html/prog/progse30.html#x195-207.3


At least explain:
- relation of -CX and -XX
- what is to be removed: non-referenced non-virtual methods, global 
variables, and regular procedures/functions

- (may be some infos about behavior on various targets)

-Laco.



On 10/03/2021 13:17, Yuriy Sydorov via fpc-pascal wrote:

On 10.03.2021 11:34, LacaK via fpc-pascal wrote:

A.) I compile my (units) program/library with -CX -XX (set in Project
Options)


Just a small note:

-CX -XX are not needed for the top-tier targets nowadays. The section
based smart linking is a default option in recent FPC versions.

At least -XX is still necessary, otherwise we don't enable dead
code/data stripping in the linker (at least not on Linux). And on macOS,
-CX is also needed, otherwise the compiler does not emit a directive in
the object files that dead code/data stripping should be enabled based
on whether or not there are references to the global symbols preceding them.

Neither parameter may be necessary on Windows, but that's probably the
only one.


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

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


[fpc-pascal] Smart-linking versus Whole Program Optimization

2021-03-10 Thread LacaK via fpc-pascal

Hi,

my goal is DO NOT include unused procedures, methods in final 
program/library on Win32 target exe/dll.


A.) I compile my (units) program/library with -CX -XX (set in Project 
Options)


B.) I did also experiments with WPO: -OWall -FWprogram.wpo -Xs- (plus 
-Owall -Fwprogram.wpo)


Questions:

1. I did not notice difference between A and B (it seems like WPO did 
not reduce size of EXE (may be that I do something wrong))
1.1 is there way how I can check which procedures were striped out or 
vice-versa included?


2. Is smart-linking/WPO capable to remove unused:
2.1  regular procedures/functions ?
2.2  methods of classes (non virtual, virtual) ?
2.3  class methods of classes ?

Thank you

-Laco.

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


Re: [fpc-pascal] Cannot write datetime field on sqlite3 database on ARM

2021-03-09 Thread LacaK via fpc-pascal


Dňa 9.3.2021 o 15:34 Toru Takubo via fpc-pascal napísal(a):

On 2021/03/09 18:11, LacaK via fpc-pascal wrote:
I did run test program on RaspberryPI: Linux+ARM and results are as 
expected.

(FPC 3.2.0)

-Laco.

Thank you for your reproduction test. It may be a good news that the 
problem would

not be in the compiler but around configuration or environment.

Do you have a native compiler on RaspberryPI, or using cross compiler?


I am using cross compiler. (build by FpcUpDeluxe)



My compiler setting is below. Does something missing or wrong?


My settings are:

-Tlinux
-Parm
-MObjFPC
-Scghi
-O1
-g
-gl
-l
-vewnhibq
-Filib\arm-linux
-Fu.
-FUlib\arm-linux
-FE.
-oproject1



---
C:\lazarus\fpc\3.2.0\bin\i386-win32\fpc.exe
-Tlinux
-Parm
-MObjFPC
-Sh
-CX
-O3
-XX
-l
-vewnibq
-vh-
-vm5057,5028,5024,3042
-Fiobj\arm-linux
-Fu.
-FEobj\arm-linux
-oobj\arm-linux\project1
---

If possible, would you publish your executive of the test program to 
try it?


Uploaded to 
http://moja.uschovna.zoznam.sk/link/af6c3620-b919-4d64-9ab4-978af3d84717


-Laco.


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


Re: [fpc-pascal] Cannot write datetime field on sqlite3 database on ARM

2021-03-09 Thread LacaK via fpc-pascal
I did run test program on RaspberryPI: Linux+ARM and results are as 
expected.

(FPC 3.2.0)

-Laco.

Dňa 9.3.2021 o 1:47 Toru Takubo via fpc-pascal napísal(a):

On 2021/03/08 16:54, Michael Van Canneyt via fpc-pascal wrote:



On Mon, 8 Mar 2021, Toru Takubo via fpc-pascal wrote:


Hi,

I am developing my app on Windows and building apps for other
platforms by using cross compiler. Now I have a problem only
occurred on Linux ARM.

The problem is that it cannot write datetime field on sqlite3
database. It can read/write other fields like int, varchar
or blob, but always write zero in datetime (maybe float as well)
field.

Does anyone have an idea about this issue? I am not sure it is
fpc issue, but better to report bug?


It sounds like a floating point problem. As you probably know, a 
TDateTime

type is actually a double type. Did you try with a float value ?

The DB explorer tools probably just use strings to read/write from the
database, so they will not be bothere by such things, but FPC stores 
dataset

values in 'native' formats in memory.

I don't know what to advise to further investigate the issue, One 
thing to
try would be to test whether normal float arithmetic or date 
arithmetic works.

If not, then the compiler people will need to give more advice.



I created a simple test code, and ran on linux-i386 and linux-arm.
Test on linux-i386 is OK but on linux-arm, I got unexpected values
"30-12-99" as datetime and "2.12199579096527E-314" as float, which are 
different

from values previously set. (except INT and VARCHAR fields)

---linux-i386
INT, VARCHAR,   DATETIME,   DOUBLE
0, 9-3-21 08:50:23, 9-3-21 08:50:23, 0
1, 9-3-21 12:16:06, 9-3-21 12:16:06, 0.142857142857143
2, 9-3-21 15:41:49, 9-3-21 15:41:49, 0.285714285714286
3, 9-3-21 19:07:32, 9-3-21 19:07:32, 0.428571428571429
4, 9-3-21 22:33:15, 9-3-21 22:33:15, 0.571428571428571
5, 10-3-21 01:58:58, 10-3-21 01:58:58, 0.714285714285714
6, 10-3-21 05:24:40, 10-3-21 05:24:40, 0.857142857142857
7, 10-3-21 08:50:23, 10-3-21 08:50:23, 1
8, 10-3-21 12:16:06, 10-3-21 12:16:06, 1.14285714285714
9, 10-3-21 15:41:49, 10-3-21 15:41:49, 1.28571428571429

---linux-arm-
INT, VARCHAR,   DATETIME,   DOUBLE
0, 9-3-21 08:55:53, 30-12-99, 2.12199579096527E-314
1, 9-3-21 12:21:36, 30-12-99, 2.12199579096527E-314
2, 9-3-21 15:47:18, 30-12-99, 2.12199579096527E-314
3, 9-3-21 19:13:01, 30-12-99, 2.12199579096527E-314
4, 9-3-21 22:38:44, 30-12-99, 2.12199579096527E-314
5, 10-3-21 02:04:27, 30-12-99, 2.12199579096527E-314
6, 10-3-21 05:30:10, 30-12-99, 2.12199579096527E-314
7, 10-3-21 08:55:53, 30-12-99, 2.12199579096527E-314
8, 10-3-21 12:21:36, 30-12-99, 2.12199579096527E-314
9, 10-3-21 15:47:19, 30-12-99, 2.12199579096527E-314

I used a shared library libsqlite3.so included in the "DB Browser for 
SQLite",
so it should work. What can cause such a problem only in the specific 
field

on the specific platform?

Thank you in advance for any advice.

Toru




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


[fpc-pascal] Initialization of constant pointer type - bug? [was: Re: Initialization of constant record member of pointer type]

2020-12-16 Thread LacaK via fpc-pascal

Hello,

this compiles under FPC 3.0.4

const
  s: AnsiString = 'abc';
  p: pointer = @s[1];

but not under FPC 3.2.0
(I checked old Delphi XE and there it does not compile also)

Is it regression bug or not?

-Laco.






Thank you, yes it works. I have used:

const
   MyConst1: AnsiString = 'abc'
   MyConst2: TMyRec = (a: @MyConst1[1]);


It doesn't compile with fpc 3.2.0 (I'm trying, without success so 
far, your open62541 translation).



Yes, you are right. That ^ compiles under FPC 3.0 but not under FPC 3.2

I have updated test program (now compiles also under FPC 3.2)

Thanks

-Laco.



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


Re: [fpc-pascal] Initialization of constant record member of pointer type

2020-12-14 Thread LacaK via fpc-pascal




Because MyConst1 is not an *untyped* constant. Only untyped 
constants can be used in constant expressions (a pointer to 
something can be considered an untyped constant).


The following might work though I did not test it:

=== code begin ===

const
   MyStr = 'abc'
   MyConst1: AnsiString = MyStr;
   MyConst2: TMyRec = (l: Length(MyStr); a: @MyConst1[1]);


=== code end ===


Yes it works, but I must define 2 constants (MyStr and MyConst1),
which is not so nice ;-)

It would be nice to have support for true constants:

const
   MyConst1 = 'abc' ;
   MyConst2: TMyRec = (l: Length(MyConst1); a: @MyConst1[1]);

But may be that there are technical reasons why it is problematic 
(may

be that true constants are stored in another memory locations, which
can not be easy addressed)


Yes, that's one of possible reasons.

Regarding Length in constant value assignment - remember that 
Length is a function. In case of real constants, the call may be 
replaced by the compiler with the constant value. However typed 
constants may not be constant, so generic replacement throughout 
the source code at compile time is not possible (if it appears in 
the main body or some function, the length may already be changed 
to something else) and selective replacement may result in a 
behaviour not expected by the user. The only questionable case is 
IMHO the case of {$WRITEABLECONST OFF} - the compiler _might_ be 
able to perform the compile-time substition in that case (and thus 
allow using Length of such a constant in constant value 
assignment), but it doesn't do that in that case either apparently.


Yes I have no problem with {$WRITEABLECONST OFF} if it will allow 
Length().


Somewhere I read (may be in Delphi documentation) that some intristic
functions like Low(), High(), Pred() and also Length() etc. can be
used in constant expressions because compiler can evaluate them if
theirs arguments are also constants.
Which is the case in my example.
For now {$WRITEABLECONST OFF} does not help ;-)


Yes, that's what I mentioned as well, but it might be changed for 
this particular case. You might create a ticket for that if Delphi 
allows to use Length that way; obviously, you might create such a 
ticket even if Delphi doesn't allow to do that. ;-)


I checked it with older Delphi XE and it seems, that Delphi XE does 
not support Length() for typed constant also when {$WRITEABLECONST OFF}


I do not believe that this will be accepted for FPC, so I don not 
open new feature request in bug tracker.


On other side FPC developers read this mailing list so if they 
consider this as a useful/doable feature may be that someone will 
take look at it 


I just happened to write a construct like this (in Delphi):

const
  X_0: array[0..4276] of SmallInt = (.

  MAP: array['0'..'9'] of TSomething = (
    (Samples: @X_0; Count: Length(X_0)), ...



In FPC is possible also (with "array of AnsiChar"):

   MyConst1: array[0..2] of AnsiChar = 'abc';
   MyConst2: TMyRec = (l: Length(MyConst1); a: @MyConst1);

(but it does not work with plain "AnsiString" as mentioned above)

-Laco.


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


Re: [fpc-pascal] Initialization of constant record member of pointer type

2020-12-14 Thread LacaK via fpc-pascal




Thank you, yes it works. I have used:

const
   MyConst1: AnsiString = 'abc'
   MyConst2: TMyRec = (a: @MyConst1[1]);


It doesn't compile with fpc 3.2.0 (I'm trying, without success so far, 
your open62541 translation).



Yes, you are right. That ^ compiles under FPC 3.0 but not under FPC 3.2

I have updated test program (now compiles also under FPC 3.2)

Thanks

-Laco.


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


Re: [fpc-pascal] Initialization of constant record member of pointer type

2020-12-04 Thread LacaK via fpc-pascal


Dňa 2.12.2020 o 16:09 Tomas Hajny via fpc-pascal napísal(a):

On 2020-12-02 16:01, LacaK via fpc-pascal wrote:

Dňa 2.12.2020 o 13:55 Tomas Hajny via fpc-pascal napísal(a):

On 2020-12-01 11:39, Ladislav Karrach via fpc-pascal wrote:


Because MyConst1 is not an *untyped* constant. Only untyped 
constants can be used in constant expressions (a pointer to 
something can be considered an untyped constant).


The following might work though I did not test it:

=== code begin ===

const
   MyStr = 'abc'
   MyConst1: AnsiString = MyStr;
   MyConst2: TMyRec = (l: Length(MyStr); a: @MyConst1[1]);


=== code end ===


Yes it works, but I must define 2 constants (MyStr and MyConst1),
which is not so nice ;-)

It would be nice to have support for true constants:

const
   MyConst1 = 'abc' ;
   MyConst2: TMyRec = (l: Length(MyConst1); a: @MyConst1[1]);

But may be that there are technical reasons why it is problematic (may
be that true constants are stored in another memory locations, which
can not be easy addressed)


Yes, that's one of possible reasons.

Regarding Length in constant value assignment - remember that Length 
is a function. In case of real constants, the call may be replaced 
by the compiler with the constant value. However typed constants may 
not be constant, so generic replacement throughout the source code 
at compile time is not possible (if it appears in the main body or 
some function, the length may already be changed to something else) 
and selective replacement may result in a behaviour not expected by 
the user. The only questionable case is IMHO the case of 
{$WRITEABLECONST OFF} - the compiler _might_ be able to perform the 
compile-time substition in that case (and thus allow using Length of 
such a constant in constant value assignment), but it doesn't do 
that in that case either apparently.


Yes I have no problem with {$WRITEABLECONST OFF} if it will allow 
Length().


Somewhere I read (may be in Delphi documentation) that some intristic
functions like Low(), High(), Pred() and also Length() etc. can be
used in constant expressions because compiler can evaluate them if
theirs arguments are also constants.
Which is the case in my example.
For now {$WRITEABLECONST OFF} does not help ;-)


Yes, that's what I mentioned as well, but it might be changed for this 
particular case. You might create a ticket for that if Delphi allows 
to use Length that way; obviously, you might create such a ticket even 
if Delphi doesn't allow to do that. ;-)


I checked it with older Delphi XE and it seems, that Delphi XE does not 
support Length() for typed constant also when {$WRITEABLECONST OFF}


I do not believe that this will be accepted for FPC, so I don not open 
new feature request in bug tracker.


On other side FPC developers read this mailing list so if they consider 
this as a useful/doable feature may be that someone will take look at it ...


Thanks

-Laco.


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


Re: [fpc-pascal] Initialization of constant record member of pointer type

2020-12-02 Thread LacaK via fpc-pascal


Dňa 2.12.2020 o 13:55 Tomas Hajny via fpc-pascal napísal(a):

On 2020-12-01 11:39, Ladislav Karrach via fpc-pascal wrote:


Because MyConst1 is not an *untyped* constant. Only untyped 
constants can be used in constant expressions (a pointer to 
something can be considered an untyped constant).


The following might work though I did not test it:

=== code begin ===

const
   MyStr = 'abc'
   MyConst1: AnsiString = MyStr;
   MyConst2: TMyRec = (l: Length(MyStr); a: @MyConst1[1]);


=== code end ===


Yes it works, but I must define 2 constants (MyStr and MyConst1),
which is not so nice ;-)

It would be nice to have support for true constants:

const
   MyConst1 = 'abc' ;
   MyConst2: TMyRec = (l: Length(MyConst1); a: @MyConst1[1]);

But may be that there are technical reasons why it is problematic (may
be that true constants are stored in another memory locations, which
can not be easy addressed)


Yes, that's one of possible reasons.

Regarding Length in constant value assignment - remember that Length 
is a function. In case of real constants, the call may be replaced by 
the compiler with the constant value. However typed constants may not 
be constant, so generic replacement throughout the source code at 
compile time is not possible (if it appears in the main body or some 
function, the length may already be changed to something else) and 
selective replacement may result in a behaviour not expected by the 
user. The only questionable case is IMHO the case of {$WRITEABLECONST 
OFF} - the compiler _might_ be able to perform the compile-time 
substition in that case (and thus allow using Length of such a 
constant in constant value assignment), but it doesn't do that in that 
case either apparently.


Yes I have no problem with {$WRITEABLECONST OFF} if it will allow Length().

Somewhere I read (may be in Delphi documentation) that some intristic 
functions like Low(), High(), Pred() and also Length() etc. can be used 
in constant expressions because compiler can evaluate them if theirs 
arguments are also constants.

Which is the case in my example.
For now {$WRITEABLECONST OFF} does not help ;-)

-Laco.


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


Re: [fpc-pascal] Initialization of constant record member of pointer type

2020-12-01 Thread LacaK via fpc-pascal


Dňa 30.11.2020 o 23:26 Sven Barth via fpc-pascal napísal(a):

Am 30.11.2020 um 13:20 schrieb LacaK via fpc-pascal:

Hi,

is there a way how to initialize record member of pointer type (other 
than PChar) in the following example:


type
  TMyRec=record
    a: PByte; // if I change PByte to PAnsiChar then it works
  end;

const
  MyConst: TMyRec = (a: 'abcd'); // I want to a points to static 
memory where 'abcd' is stored


I would like to initialize a to be pointer to another known constant 
or directly to supplied string constant.


For example something like:

const
  MyConst1='abcd';
  MyConst2=TMyRec = (a: @MyConst1);


Untyped constants don't have an address you can take. You need to use 
a typed constant:


=== code begin ===

const
  MyConst1: Byte = 123;
  MyConst2: TMyRec = (a: @MyConst1);

=== code end ===


Thank you, yes it works. I have used:

const
  MyConst1: AnsiString = 'abc'
  MyConst2: TMyRec = (a: @MyConst1[1]);

unfortunately it seems, that I can not use Length(MyConst1) in:

type
  TMyRec=record
    l: integer;
    a: PByte;
  end;

const
  MyConst1: AnsiString = 'abc';
  MyConst2: TMyRec = (l: Length(MyConst1); a: @MyConst1[1]);

Why is it prohibited?

-Laco.

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


[fpc-pascal] Initialization of constant record member of pointer type

2020-11-30 Thread LacaK via fpc-pascal

Hi,

is there a way how to initialize record member of pointer type (other 
than PChar) in the following example:


type
  TMyRec=record
    a: PByte; // if I change PByte to PAnsiChar then it works
  end;

const
  MyConst: TMyRec = (a: 'abcd'); // I want to a points to static memory 
where 'abcd' is stored


I would like to initialize a to be pointer to another known constant or 
directly to supplied string constant.


For example something like:

const
  MyConst1='abcd';
  MyConst2=TMyRec = (a: @MyConst1);

TIA

-Laco.

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


Re: [fpc-pascal] -Fu unit search path and network paths

2020-09-22 Thread LacaK via fpc-pascal





are supported in -Fu (unit search path) networks paths? i.e. 
-Fu\\server\share -Fu\\server\share\path ?
Correction: unit cannot be found only if it is placed in "share 
root" \\server\share !

When is placed in \\server\share\path then it is found.

Why?


Possibly Share vs directory.   A directory has 4 slashes 
(\\x\y\

Try \\server\share\.
*Does not works. More confusing is that, when I map \\server\share 
to F:\ and I add F:\ to search path it does not work also!

*

*(if unit is in any subdirectory i.e. F:\something then it works ... 
so only root does not work!)*


*
*


[0.015] Handling option "-Fud:\"
[0.015] interpreting option "-Fud:\"
[0.015] Path "D:\" not found

So the path exist function probably fails on root dirs.


This looks like the infamous wrong implementation of checking of 
directory existence based on reading its attributes (which doesn't 
work for the root directory, because it has no specific entry on the 
file-system and thus also no attributes, at least on DOS-like systems) 
without special handling of the special case of the root directory:


cfileutl.pas, line 361-375 (trunk):

    function TCachedDirectory.DirectoryExists(const 
AName:TCmdStr):boolean;

  var
    Attr : Longint;
  begin
    if not TryUseCache then
  begin
    Result:=PathExists(Name+AName,false);
    exit;
  end;
    Attr:=GetItemAttr(AName);
    if Attr<>0 then
  Result:=((Attr and faDirectory)=faDirectory)
    else
  Result:=false;
  end;

I suggest filing a bug report.


Reported https://bugs.freepascal.org/view.php?id=37793

If you can add there more details please do it ;-)

-Laco.


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


Re: [fpc-pascal] -Fu unit search path and network paths

2020-09-21 Thread LacaK via fpc-pascal


Dňa 21.9.2020 o 12:35 Marco van de Voort via fpc-pascal napísal(a):


Op 2020-09-21 om 08:57 schreef LacaK via fpc-pascal:



Hi *,

are supported in -Fu (unit search path) networks paths? i.e. 
-Fu\\server\share -Fu\\server\share\path ?
Correction: unit cannot be found only if it is placed in "share root" 
\\server\share !

When is placed in \\server\share\path then it is found.

Why?


Possibly Share vs directory.   A directory has 4 slashes 
(\\x\y\

Try \\server\share\.
*Does not works. More confusing is that, when I map \\server\share to 
F:\ and I add F:\ to search path it does not work also!

*

*(if unit is in any subdirectory i.e. F:\something then it works ... so 
only root does not work!)*


*
*



Note that probably none of this is supported, just coincidence because 
Windows functions interpret it themselves.


*But how to explain cause with F:\ ?*

*
*

*L.*
**


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


Re: [fpc-pascal] -Fu unit search path and network paths

2020-09-21 Thread LacaK via fpc-pascal





Hi *,

are supported in -Fu (unit search path) networks paths? i.e. 
-Fu\\server\share -Fu\\server\share\path ?
Correction: unit cannot be found only if it is placed in "share root" 
\\server\share !

When is placed in \\server\share\path then it is found.


Addition:

when I use in *uses* clause:

use unit1 in '\\server\share\unit1.pas'

then *it works* also when I omit search path from -Fu (no search paths 
specified in Project Options)


strange, does not?


Why?


When I am compiling project, which is located on local drive, but 
uses units from network, error is raised while compiling project file 
.lpr "Cannot find XYZ used by ..."

(when I map network path to drive letter then it works as expected)

TIA

-Laco.

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

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

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


Re: [fpc-pascal] -Fu unit search path and network paths

2020-09-21 Thread LacaK via fpc-pascal



Hi *,

are supported in -Fu (unit search path) networks paths? i.e. 
-Fu\\server\share -Fu\\server\share\path ?
Correction: unit cannot be found only if it is placed in "share root" 
\\server\share !

When is placed in \\server\share\path then it is found.

Why?


When I am compiling project, which is located on local drive, but uses 
units from network, error is raised while compiling project file .lpr 
"Cannot find XYZ used by ..."

(when I map network path to drive letter then it works as expected)

TIA

-Laco.

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

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


[fpc-pascal] -Fu unit search path and network paths

2020-09-21 Thread LacaK via fpc-pascal

Hi *,

are supported in -Fu (unit search path) networks paths? i.e. 
-Fu\\server\share -Fu\\server\share\path ?
When I am compiling project, which is located on local drive, but uses 
units from network, error is raised while compiling project file .lpr 
"Cannot find XYZ used by ..."

(when I map network path to drive letter then it works as expected)

TIA

-Laco.

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


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-13 Thread LacaK via fpc-pascal
<<< text/html;charset=utf-8: Unrecognized >>>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Sending Hex codes over TCP/IP

2020-09-13 Thread LacaK via fpc-pascal
Dňa Fri, 11 Sep 2020 19:13:38 -0400 James Richters via fpc-pascal  napísal:> What I'm trying to do is control some different ethernet relays. > They use> MODBUS TCP.   I'm trying to keep it as simple as possible.  I found >a modbus> library for Pascal but it was way over complicated for that I need >to do,> and while it  looks like it would do some cool stuff,  the one >function I> need wasn't implemented yet.> You can look at my simple MODBUS TCP implementation ... http://lacak.users.sourceforge.net/freepascal.htmlI think that it is simple/straightforward to understand.If there is something not implemented yet I can add it
  ... (I just implemented what I needed for my work project)-Laco.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-10 Thread LacaK via fpc-pascal
>  .>>> The implicit conversion is explicitly expected by the user>>> in this case if I understand it correctly (source in CP1250), right?>> >> If you mean the "non implicit conversion" requires explicit>> conversion by the user, then yes.> > No, I mean that the original poster explicitly mentioned that he >expected the implicit conversion to be performed as necessary when he >specified that his source code was in CP1250.> Yes It was my first strict expectation: - code page of source file explicityl specified {$cod
 epage 1250}- string constants are in this encoding so compiler is aware of encoding string constantsMy second relaxed expectation was:- if string variable is of type String(1250) (and initialized to string constant) then if assigned to string(CP_ACP), which I take as two distinct types, conversion should happen. But something goes wrong "in Lazarus".To be fair, pure FPC console program (with DefaultSystemCodePage set to UTF-8) shows correct results, but in Lazarus the behavior is "strange". I believe, that this "strange" behavior can be explain
 ed, but for me is it hard to follow.My conclusion up to now is, that dynamic code page of strings is not taken into account when assigned to Caption. Caption expects UTF-8, but supplied is cp1250. So only way how to handle this is do conversion explicitly in my code or use WideString, which works as expected and can be shared between Delphi7 and Lazarus.Questions which remains for me unanswered:1. does FPC checks for dynamic code page of strings parameters in WriteLn() ? It should explain why strings are displayed correctly in console application2. does my guess "if code page of source file = declared code page of string then compiler does not insert conversion code" is right?3. does my guess "if destination code page of string is CP_ACP and source is string literal (in source file code page) then no conversion code is inserted" is right?-Laco.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-09 Thread LacaK via fpc-pascal




> This is a bit counter intuitive to me.

It is explained here:
https://wiki.freepascal.org/Unicode_Support_in_Lazarus

IMO "c4" case (c4: String1250 = 'áéíóčž';) is not fully explained. 
Probably what here happens is, that declared code page of c4 = source 
file code page and in that case compiler does not insert conversion 
code. StringCodePage(c4)=1250 (also StringCodePage(c2)=1250) so dynamic 
code page is right, but when assigning to TLabel.Caption current dynamic 
code page is not taken into account



For LacaK I recommend using UTF-8 encoding as much as possible. Then 
everything "/just works/".


yes I use this, but I have "one" specific case where I want share one 
file between Delphi7 and Lazarus



You could have a unit or .inc file with WinCP constants for Delphi7, 
and then some IFDEFs. They should be explicitly converted to UTF-8 for 
LCL.


UnicodeString constants can also be a good solution. It triggers an 
automatic conversion when assigned to a String variable. The 
conversion is usually fast enough.


Yes this is what I use (WideString constants) and it is only solution 
which works for me in Delphi7/Lazarus


Thanks

L.


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


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-09 Thread LacaK via fpc-pascal



attached simple Lazarus compilable project (one Form).

...
type
   String1250 = type AnsiString(1250);

const
   c2: AnsiString = 'áéíóčž';
   c3: WideString = 'áéíóčž';
   c4: String1250 = 'áéíóčž';

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
begin
   label1.Caption:='áéíóčž'; // FAIL
   label2.Caption:=c2;   // FAIL
   label3.Caption:=c3;   // OK
   label4.Caption:=c4;   // FAIL
end;

The attached pure FPC-variant of your project works fine with FPC 3.2.0
for me (except for the very first writeln, because that one gets
interpreted as "writeln(shortstring)"),


*yes for me on Windows it works also (under Lazarus 2.0.8 with FPC 3.0.4)
*

*
*


  so it may be Lazarus-specific.
Best ask it on the Lazarus list or post it on their bug tracker instead.


*I add CC also to Lazarusdev group
(attached simple project)
*

*
*



Also make sure you did *not* build your Lazarus with -dDisableUTF8RTL


*I do not build Lazarus with -dDisableUTF8RTL (I simply use default 
installation)*


*As Sven wrote there is at least "c4" case, where declared code page 
(AnsiString(1250)) is different from AnsiString (CP_ACP) codepage and 
also from dynamic code page (DefaultSystemCodepage which is under 
Lazarus (UTF8=65001))*


*I am still confused how this CodePage aware stuff is expected to work 
and when implicit conversios are included (as far as I understand here 
ONLY declared/static codepage plays role) and when dynamic codepage is 
taken into account and when not?*


*L.*


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


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-07 Thread LacaK via fpc-pascal

Hello Jonas,

attached simple Lazarus compilable project (one Form).

...
type
  String1250 = type AnsiString(1250);

const
  c2: AnsiString = 'áéíóčž';
  c3: WideString = 'áéíóčž';
  c4: String1250 = 'áéíóčž';

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
begin
  label1.Caption:='áéíóčž'; // FAIL
  label2.Caption:=c2;   // FAIL
  label3.Caption:=c3;   // OK
  label4.Caption:=c4;   // FAIL
end;

TIA

-Laco.



I would like to have source file in Windows-1250 encoding, where are
stored literal strings like 'áéíóčž' in Windows-1250 encoding (I share
this one file between FPC/Lazarus and Delphi 7). Windows-1250 is also
ANSI code page of my Windows OS. In source file I have:

{$IFDEF FPC}
   {$CODEPAGE cp1250}
{$ENDIF}

and in Lazarus I have set: File settings / Encoding / CP1250
(at this point in .pas file are all characters correctly encoded in
Windows-1250 code page)

When I compile application and run it, string literals (characters with
accents) are not preserved.
Is there way how to get it working?

The attached program uses the same environment as Lazarus
(DefaultSystemCodePage forced to UTF-8) and prints the string correctly
for me (under Mac OS X).

Please always provide a compilable program when reporting issues.


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


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-03 Thread LacaK via fpc-pascal



Hi *,

I would like to have source file in Windows-1250 encoding, where are 
stored literal strings like 'áéíóčž' in Windows-1250 encoding (I 
share this one file between FPC/Lazarus and Delphi 7). Windows-1250 
is also ANSI code page of my Windows OS. In source file I have:


{$IFDEF FPC}
  {$CODEPAGE cp1250}
{$ENDIF}
A pure string constant will still have CP_ACP as code page (which in 
Lazarus will by default mean UTF-8) also when you declare it as a 
typed String constant. The $CodePage directive will only influence the 
binary encoding of the string. 


*and probably this is something non intuitive for me. Also after reading 
https://wiki.freepascal.org/FPC_Unicode_support#String_constants it is 
hard to understand for me. After reading "The compiler has to know the 
code page according to which it should interpret string constants, as it 
may have to convert them at compile time." my expectation is, that when 
I explicitly define encoding of source file by using **{$CODEPAGE 
cp1250} then compiler will be aware of string encoding in that file and 
will handle it appropriate. Now it works in another way which is not 
clear to me ... can it be better explained in wiki (any example)?*


*
*


What you need to do is the following:

type
  String1250 = type String(1250);

const
  MyString: String1250 = 'áéíóčž';

This way the string itself will have code page 1250 and if you assign 
to a normal String or a UnicodeString the compiler will insert the 
appropriate conversions.


*yes, this I can understand, but it will not work in Delphi 7 ...*

*TIA*

*L.*


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


[fpc-pascal] String literals and code page of .pas source file

2020-09-02 Thread LacaK via fpc-pascal

Hi *,

I would like to have source file in Windows-1250 encoding, where are 
stored literal strings like 'áéíóčž' in Windows-1250 encoding (I share 
this one file between FPC/Lazarus and Delphi 7). Windows-1250 is also 
ANSI code page of my Windows OS. In source file I have:


{$IFDEF FPC}
  {$CODEPAGE cp1250}
{$ENDIF}

and in Lazarus I have set: File settings / Encoding / CP1250
(at this point in .pas file are all characters correctly encoded in 
Windows-1250 code page)


When I compile application and run it, string literals (characters with 
accents) are not preserved.

Is there way how to get it working?

Only work-around which worked for me (in both Delphi and Lazarus) was use:

const
  STRINGLITERAL1: WideString = 'áéíóčž';

Thanks

-Laco.

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


Re: [fpc-pascal] Lazarus 2.0.10 FPC 3.2.0 TFPHTTPClient no longer supports https

2020-08-05 Thread LacaK








After upgrading to Lazarus 2.0.10 FPC 3.2.0 , my existing code 
using TFPHTTPClient.Get('https://api.telegram.org/bot')

returns the error "No SSL Socket support compiled in"

How can I fix it?


Simply add one of the units opensslsockets or gnutlssockets to the uses
clause of the program.

Can this information being added into 
https://wiki.freepascal.org/User_Changes_3.2.0, please?


Done.


Perfect!

L.

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


Re: [fpc-pascal] Lazarus 2.0.10 FPC 3.2.0 TFPHTTPClient no longer supports https

2020-08-04 Thread LacaK




After upgrading to Lazarus 2.0.10 FPC 3.2.0 , my existing code using 
TFPHTTPClient.Get('https://api.telegram.org/bot')

returns the error "No SSL Socket support compiled in"

How can I fix it?


Simply add one of the units opensslsockets or gnutlssockets to the uses
clause of the program.

Can this information being added into 
https://wiki.freepascal.org/User_Changes_3.2.0, please?


TIA

-Laco.


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


Re: [fpc-pascal] FPC_CURRENCY_IS_INT64

2019-10-14 Thread LacaK
>> what is the meaning of this compiler define?>> I am expecting, that Currency datatype is internaly stored using >>Int64>> datatype (*1).>> This compiler define is set for Win64, but not for Win32.>> Does it means, that on Win32 there is Currency internaly represented>> using another data type?>>> > Correct. On all non-Win64 x86 systems the Currency type is a FPU >based type.x87 FPU based data types only when doing calculations inside FPU?Am I right, that in memory layout is sam
 e as for Int64 on Win64 and also on Win32? When I try:var  c: currency:  i: int64 absolute c;begin  // SizeOf(c) = SizeOf(i) = 8 on both Win32 and also Win64  c:= ;
   // then in "i" is c*1  writeln(i); // prints c*1end.So in memory is stored always as int64 and when CPU/FPU is working with it then is converted to extended and loaded into FPU registers - FILD. And when stored back into memory FIST is used to convert value in FPU register to signed 64bit integer and stored into memory.So it is safe to assume that in memory is Currency always stored as Int64 on Win32, Win64?Thanks-Laco.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] FPC_CURRENCY_IS_INT64

2019-10-14 Thread LacaK

Hi,

what is the meaning of this compiler define?
I am expecting, that Currency datatype is internaly stored using Int64 
datatype (*1).

This compiler define is set for Win64, but not for Win32.
Does it means, that on Win32 there is Currency internaly represented 
using another data type?


TIA

-Laco.

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


Re: [fpc-pascal] Overloading Inc and Dec procedures?

2019-09-18 Thread LacaK





Hi *,

seems, that overloading of Inc, Dec internal compiler procedures
is not
allowed.
Is it by intention or can it be fixed (adding overload keyword to
system
function definitions?).


Yes, this is by intention and no, it can't be fixed.


Thank you!

Can it be then somewhere documented?

L.


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


[fpc-pascal] Overloading Inc and Dec procedures?

2019-09-18 Thread LacaK

Hi *,

seems, that overloading of Inc, Dec internal compiler procedures is not 
allowed.
Is it by intention or can it be fixed (adding overload keyword to system 
function definitions?).


I would like to add support for:

  procedure Inc(var a: integer; b: single); overload; inline;
  begin
    a := a + Round(b);
  end;
  procedure Inc(var a: single; b: single); overload; inline;
  begin
    a := a + b;
  end;
  procedure Dec(var a: integer; b: single); overload; inline;
  begin
    a := a - Round(b);
  end;
  procedure Dec(var a: single; b: single); overload; inline;
  begin
    a := a - b;
  end;

But nor this approach nor operator overloading is allowed.
(Error message: Wrong number of parameters specified for call to "Inc" 
is emited , when simple Inc(a); is used
I can avoid this error by prefixing System.Inc(), but it will require 
change on many places in code)


I need use addition or subtraction on operands, which left of them can 
be either "integer" or "single" type (specialized generic type)


Example:

var x,y: TAnyNumericType; x1,y1: single; i: integer;
Inc(x, x1); // x,y can be either integer or single
Inc(y, y1);
Inc(i); // Error: Wrong number of parameters specified for call to "Inc"

TIA

-Laco.

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


Re: [fpc-pascal] Generics: Error: Can't determine which overloaded function to call

2019-09-18 Thread LacaK
Work-around which produces good assembler without writting/reading 
intermediate variables:


class function T2DPoint.Sqr(value: T): T; static; inline;
begin
  Result := value*value;
end;

function T2DPoint.Distance(P: T2DPoint): Single; inline;
begin
  Result := Sqrt(Sqr(x-P.x) + Sqr(y-P.y));
end;




Is there other solution as:

function T2DPoint.Distance(P: T2DPoint): Single;
var dx,dy: T;
begin
  dx := x-P.x;
  dy := y-P.y;
  Result := Sqrt(dx*dx + dy*dy);
end;

(for integer operations Sqr() is implemented as "value*value", so 
there is no difference (compared to above mentioned implementation) 
but for floating point operations there is called internal function 
"fpc_in_sqr_real" which is IMO implemented in smarter way that 
"value*value" (I can not find where/how is implemented)?)


TIA

-Laco.


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


[fpc-pascal] Generics: Error: Can't determine which overloaded function to call

2019-09-18 Thread LacaK

Hi *,

I have generics record, where one method computes distance between 2 points:

function T2DPoint.Distance(P: T2DPoint): Single;
begin
  Result := Sqrt(Sqr(x-P.x) + Sqr(y-P.y));
end;

But this does not compile as there are many versions of Sqr() in the 
scope Sqr(longint), Sqr(QWord), Sqr(Extended), Sqr(int64)


Point coordinates (x,y) can be either integer or single (in my case) 
when specializing, so decision which version of Sqr() to call should be 
postponed to specializing phase, does not?


Is there other solution as:

function T2DPoint.Distance(P: T2DPoint): Single;
var dx,dy: T;
begin
  dx := x-P.x;
  dy := y-P.y;
  Result := Sqrt(dx*dx + dy*dy);
end;

(for integer operations Sqr() is implemented as "value*value", so there 
is no difference (compared to above mentioned implementation) but for 
floating point operations there is called internal function 
"fpc_in_sqr_real" which is IMO implemented in smarter way that 
"value*value" (I can not find where/how is implemented)?)


TIA

-Laco.

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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-16 Thread LacaK



Yes, GetTextBOM/SetTextBOM as described above make sense, good idea.

Just to be clear - I don't have capacity to work on the implementation 
myself,


unfortunately this is also my case for now



your potential contribution would be appreciated.


maybe sometime later I will take the time to look at it

L.


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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-16 Thread LacaK




Hi *,

As promised, I discussed the idea of adding support for UTF-16 encoded 
text files (and preferably UTF-32 as well while at it) to the RTL with 
other core team members. Overall, I didn't come across anybody oposing 
this idea, the only (logical) requirement is taking care of the 
performance implications of this change, i.e. avoiding considerable 
performance decrease in processing of 8-bit encoded files (actually, 
this is one of reasons of my suggestion to add codepoint size 
information to the text file record and use that instead of checking 
individual values of the codepage variable to find out the codepoint 
size implications every time working with the file - see below).




Yes, I believe that extending SetTextCodePage with supporting UTF-16
makes sense (with certain caveats like that calling it should be
performed before Rewrite in case of new files creation, or otherwise
the BOM mark will not be added to the beginning of the file). The
other question is what needs to happen within the text file record -
as mentioned in my other post, I'd prefer adding a new field
specifying the codepoint size rather than having to check for specific
codepage values in all code branches which would need to be created
for handling the difference.

Moreover, the case of opening a file is somewhat trickier, because the
file may have the encoding specified within the file itself. Would we
add code for reading the first bytes every time Reset is called for a
text file not associated with another device (console) and set the
fields in the text file record (possibly overriding an explicit
setting from SetTextCodePage)? Personally, I'd do so, but others may
have a different opinion.

 .
 .

After the discussion with some people from the core team, I suggest 
the following:


1) New attribute for the codepoint size will be added to the text file 
record and all the text file I/O needs to be checked and possibly 
extended to with using this attribute instead of current implicit 
expectation that the codepoint size is always 1 byte.


2) Support for UTF-16BE/LE and UTF-32BE/LE will be added to 
SetTextCodePage, the new codepoint size attribute will be updated as 
appropriate.


3) New function 'DetectUtfBom (var T: text): boolean' will be added. 
This function may be called after the call to 'Reset (T: text)' to 
check for existence of BOM at the beginning of the text file. If it is 
found (Result=true), SetTextCodePage is invoked automatically from 
DetectUtfBom with the codepage value corresponding to the found BOM 
and encoding variant. If BOM is not found (Result=false), nothing 
changes.


4) A new procedure 'SetUtfBom (var T: text; CodePage: word; BOM: 
boolean)' will be added. This procedure may be called after the call 
to Rewrite and allows writing BOM to the respective text file. 
SetTextCodePage with the respective value will be called from SetUtfBom.


Comments, anybody?


Thank you Tomas.

My comment per function names: use pattern SetText.../GetText...
So for inspiration:
- GetTextBOM or ReadBOM(var T: Text; SetCodePage:boolean=True):Word,
  (parameter SetCodePage should specify if SetTextCodePage will be 
called automatically if desired). Retunr value will be CP_NONE (no BOM) 
or CP_UTF8, CP_UTF16,...

- SetTextBOM or WriteBOM(var T: Text; CodePage: Word)
  (writtes BOM corresponding to given CodePage and will call 
SetTextCodePage). Boolean BOM parameter is IMO not needed as call to 
this function signals, that user wants write BOM else user will call 
SetTextCodePage() only


-Laco.

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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-05 Thread LacaK

From user POV we have this situation:
- on one side there is input text file encoded UTF-16 (either LE or BE)
- on other side there is FPC, where RTL procedures like AssignFile, 
SetTextCodePage, Reset, Read(Ln), Write(Ln) are available.


My original intention was simply use call to existing procedure 
SetTextCodePage with parameter CP_UTF16, which in my opinion will simply 
signal to RTL, that input/output text file is/should be encoded using UTF16.
Then any subsequent call to ReadLn with any destination variable 
(ansistring, unicodestring, integer, etc.) will simply do something like:
- read from file byte sequence, which will be interpreted as UTF-16 so 
we will have on input UnicodeString
- this UnicodeString will be further transliterated to requested 
destination variable (as there are in FPC implicit conversions between 
UnicodeString and AnsiString this would be no problem)


(for Write(Ln) same will happen only in reverse order: source variable 
-> UnicodeString -> Write to File)


If SetTextCodePage(CP_UTF16) is not appropriate, then we must IMO 
introduce any new procedure which will give to user possibility signal 
that "I have UTF-16 encoded text file" or "I want that all writes to my 
text file should be encoded UTF-16".
(but personally I do not see reason to introduce new procedure as 
SetTetCodePage for me perfectly fit)


So firstly we need design/proposal, which is/will be accepted.
(probably here is needed deeper knowledge of RTL internals so it is 
reason why also others core developers should step in)


L.



On 2019-09-05 13:04, Joost van der Sluis wrote:

Op 05-09-19 om 12:06 schreef Tomas Hajny:

On 2019-09-05 09:00, LacaK wrote:

Is there consensus/demand on such solution and any patch in this
direction will be accepted?


I'm not aware of potential discussion about this so far, thus I 
cannot talk about any existing consensus (let's hear others), but I 
believe that such a consensus could be reached.


Yes, that's for sure. There's at least one person from the core team 
list already involved. ;-)


I think that this question from LacaK was not that strange. For people
outside the core team, it is not always clear who is member of core.

 .
 .

Absolutely, the question was perfectly valid, sorry if my response 
sounded differently. In any case, I also explicitly mentioned people 
I'd like to be involved in reaching the consensus. I will make sure to 
get their opinion (either here or elsewhere) and provide the summary 
here for LacaK and others as appropriate.


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

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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-05 Thread LacaK






You may be able to improve on this using system.BlockRead.
Probably yes, but then I must read in local buffer and examine buffer 
for CR/LF.


And return from my function UCS2ReadLn() only portion of string up to
CR/LF and rest of string return on next call to my function.
(so I must keep unprocessed part in global buffer)



Also, you are assuming low order byte first which may not be portable.


Yes, In my case LE is sufficient as far as I check presence of BOM 
$FF$FE


Just as a comment - a contribution allowing ReadLn to read UTF-16 
files (preferably complete from functional point of view, especially 
without shortcuts like handling only UCS2 instead of complete Unicode) 
would be obviously welcome.



Is there consensus/demand on such solution and any patch in this 
direction will be accepted?
If yes we must agree on implementation details and IMO also someone must 
check what situation is in Delphi ... because I guess, that if Delphi 
does not support this that also FPC will not diverge?
Question1: should be supported "SetTextCodePage(CP_UTF16)" and 
"SetTextCodePage(CP_UTF16BE)"?

Question2: is this supported in Delphi?
If answer to both questions is YES then I will fill bug report as start 
point.


As I wrote there is in sources explicit comment: "// all standard input 
is assumed to be ansi-encoded" which will be no more true if we will add 
UTF-16 support.


I can imagine, that we can add check for TextRec(T).CodePage=CP_UTF16 
and CP_UTF16BE and these two situations handle specially (in read and 
also in write procedures of text files)


But as far as Read[Ln]/Write[Ln] is core functionality I think, that 
somebody of core developers should look at it ... ;-)


-Laco.


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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-04 Thread LacaK



You may be able to improve on this using system.BlockRead.
Probably yes, but then I must read in local buffer and examine buffer 
for CR/LF.


And return from my function UCS2ReadLn() only portion of string up to 
CR/LF and rest of string return on next call to my function.

(so I must keep unprocessed part in global buffer)




Also, you are assuming low order byte first which may not be portable.


Yes, In my case LE is sufficient as far as I check presence of BOM $FF$FE

L.



On 04/09/2019 11:14, LacaK wrote:

Nice! Thank you very much.

As an alternative for F:TextFile I am using:

procedure UCS2ReadLn(var F: TextFile; out s: String);
var
  c: record
  case boolean of
   false: (a: array[0..1] of AnsiChar);
   true : (w: WideChar);
 end;
begin
  s:='';
  while not Eof(F) do begin
    System.Read(F,c.a[0]);
    System.Read(F,c.a[1]);
    if c.w in [#10,#13] then
  if s = '' then {begin of line} else break {end of line}
    else
  s := s + c.w;
  end;
end;

which works for me also, but I would be like to have better solution. 
I will try LoadFromFile with TEncoding once FPC 3.2 will be out.


-L.


Stupid an lazy workaround, probably not suitable for larger files.

{$mode objfpc}
{$h+}
uses
   sysutils;

type
   TUCS2TextFile = file of WideChar;

procedure ReadLine(var F: TUCS2TextFile; out S: UnicodeString);
var
   WC: WideChar;
begin
   //Assume file is opend for read
   S := '';
   while not Eof(F) do
   begin
 Read(F, WC);
 if WC = WideChar(#$000A) then
   exit
 else
   if (WC <> WideChar(#$000D)) and (WC<>WideChar(#$FEFF {Unicode LE
BOM})) then S := S + WC;
   end;
end;

var
   UFile: TUCS2TextFile;
   US: UnicodeString;
begin
   AssignFile(UFile, 'ucs2.txt');
   Reset(Ufile);
   while not Eof(UFile) do
   begin
 ReadLine(UFile, US);
 writeln('US = ',US);
   end;
   CloseFile(UFile);
end.

Outputs
US = Line1
US = Line2
US = Line3
which is correct for my test file (Unicode LE encoding created with 
Notepad).


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

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


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

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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-04 Thread LacaK

Nice! Thank you very much.

As an alternative for F:TextFile I am using:

procedure UCS2ReadLn(var F: TextFile; out s: String);
var
  c: record
  case boolean of
   false: (a: array[0..1] of AnsiChar);
   true : (w: WideChar);
 end;
begin
  s:='';
  while not Eof(F) do begin
    System.Read(F,c.a[0]);
    System.Read(F,c.a[1]);
    if c.w in [#10,#13] then
  if s = '' then {begin of line} else break {end of line}
    else
  s := s + c.w;
  end;
end;

which works for me also, but I would be like to have better solution. I 
will try LoadFromFile with TEncoding once FPC 3.2 will be out.


-L.


Stupid an lazy workaround, probably not suitable for larger files.

{$mode objfpc}
{$h+}
uses
   sysutils;

type
   TUCS2TextFile = file of WideChar;

procedure ReadLine(var F: TUCS2TextFile; out S: UnicodeString);
var
   WC: WideChar;
begin
   //Assume file is opend for read
   S := '';
   while not Eof(F) do
   begin
 Read(F, WC);
 if WC = WideChar(#$000A) then
   exit
 else
   if (WC <> WideChar(#$000D)) and (WC<>WideChar(#$FEFF {Unicode LE
BOM})) then S := S + WC;
   end;
end;

var
   UFile: TUCS2TextFile;
   US: UnicodeString;
begin
   AssignFile(UFile, 'ucs2.txt');
   Reset(Ufile);
   while not Eof(UFile) do
   begin
 ReadLine(UFile, US);
 writeln('US = ',US);
   end;
   CloseFile(UFile);
end.

Outputs
US = Line1
US = Line2
US = Line3
which is correct for my test file (Unicode LE encoding created with Notepad).

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

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


Re: [fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-04 Thread LacaK






is there any smart way how to read string data line by line from UCS2
encoded text files (lines delimited by $0A00).

So, some LoadFromFile with a stream is no option for you?
It should be an option, but AFAIK LoadFromFile with optional TEncoding 
is not a part of FPC 3.0.4


It is only in upcoming 3.2.0 ...





I wonder if Delphi supports ReadLn() for UTF-16 encoded text files ...?

 From what I gather from the Embarcadero wiki and google searches it does not.
I only have D7 so I cannot test that myself though,

Seems you need to use LoadFromFile with a TEncoding specified, see:
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Using_TEncoding_for_Unicode_Files


Yes it was my impression also ... I was wondering if there is other way?
(best using ReadLn() ... so I can open TextFile, then read first 2-3 
bytes (BOM) and detect what encoding file has (UTF-8 or UTF-16) and then 
either use ReadLn with AnsiString (UTF-8 case) or UnicodeString (UTF-16 
case))


L.



Bart

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


[fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

2019-09-03 Thread LacaK

Hi *,

is there any smart way how to read string data line by line from UCS2 
encoded text files (lines delimited by $0A00).


Using ReadLn(TextFile, UnicodeStringVariable) does not work as per 
comment in text.inc:


// all standard input is assumed to be ansi-encoded

Nor reading into WideChar varible does not work.
Nor setting SetTextCodePage to CP_UTF16 helped.

I wonder if Delphi supports ReadLn() for UTF-16 encoded text files ...?
Is there way how to add support for it in FPC? May be if there will be 
set TextRec(T).CodePage=CP_UTF16 then any of the fpc_Read_Text_* 
procedures will assume that input file is utf-16 encoded and not ansi?


Now I work-around by reading two chars into array[0..1] of Char and then 
cast it to UnicodeChar.

(I know that it is not safe for UTF-16, but for UCS2 it works)

Thanks

-Laco.

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


[fpc-pascal] Open file for append when exists else create new one

2019-07-09 Thread LacaK

Hi,

I want to achieve this:

If file with given name already exists then open it for append else 
create new one and open it for append.


I use something like:

  FileName:='FileName'+formatdatetime('yymmdd',date)+'.log';
  if FileExists(FileName) then F:=FileOpen(FileName, 
fmOpenWrite+fmShareDenyWrite) else F:=FileCreate(FileName);

  FileSeek(F, 0, 2); //... 0 bytes from the end of the file
  FileWrite(F, Pointer(s)^, length(s));
  FileClose(F);

or:

  if FileExists(FileName) then
    FS := TFileStream.Create(FileName, fmOpenWrite+fmShareDenyWrite)
  else
    FS := TFileStream.Create(FileName, fmCreate+fmShareDenyWrite);
  FS.Seek(0, soEnd);
  FS.Write(s[1], Length(s));
  FS.Free;

Is there way how to achieve this using one-line without checking 
FileExists ? i.e.:
resulting efect like when using on Windows CreateFile(FileName, 
GENERIC_WRITE, FILE_SHARE_READ, *OPEN_ALWAYS,*...)*
CreationDisposition =  OPEN_ALWAYS - Opens a file, always if exists else 
create new one.
If the specified file exists, the function succeeds and the last-error 
code is set to ERROR_ALREADY_EXISTS (183).
If the specified file does not exist and is a valid path to a writable 
location, the function creates a file and the last-error code is set to 
zero.*


L.
**

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


Re: [fpc-pascal] Compile for WinCE 7, target ARM, CPU Cortex-A9

2019-04-09 Thread LacaK









Note that you probably don't need two different cross
compilers if your cpu-OS target is the same


Target CPU family is same: "arm", but Target processor is not
the same: "ARMv4" versus "ARMv7" ...

So I do not know if this requires two pre-compiled
cross-compilers or not?

You only need different compilers if you have different ABIs
(e.g. Soft Float vs. Hard Float). For WinCE that isn't applicable
however.


So it does not matter how I build cross-compiler using
FpcUpDeluxe: wheter I use "-Cparmv5" or "-Cparmv7A" ?


Correct.

Then there is still problem with precompiled RTL/packages?

Because when I only change "Target processor" (in Lazarus build
using FpcUpDeluxe) I can compile application, but I can not run it
on target system (so I guess, that resulting EXE is not compiled
for target processor).

When I add to Custom options: -CfVFPV2 then I get error while
compiling: Fatal: Can't find unit system used by Test1

When I download and install default Lazarus and cross-compiler
then when I change "Target processor" to "ARMv5" or "ARMv7A" I
get: "project1.lpr(22,0) Error: Error while assembling exitcode 1"


As said by Christo you need to select the correct set of compiled 
units. Also you need to select the correct processor type when 
building your application.



I did this test:

1. I have precompiled units for "-Cparmv5" and "-Cparmv7A"and I have 
saved these precompiled units
2. Then I copy "v5" units to expected directory (of FpcUpDeluxe 
structure) fpc\units\arm-wince
3. Then I run Lazarus and try build for Target processor ARMv5 and run 
on target system ... works


4. Then I have copied "v7" units over prior "v5" units
5. I repeated step 3 ... works on target system with ARMv7 processor

Until now only question is :
Can I set somewhere (in Project Options), in inteligent way, where 
compiler will look for precompiled units ... to be able in one project 
switch between Build modes, where each build mode will look in other 
directory ?


But when I try set also "-CfFPV2" (in Project Options / Custom Options ) 
then I get:


Fatal: Cannot find system used by fcllaz. Make sure all ppu files of a 
package are in its output directory. ppu in wrong 
directory=D:\TEMP\fpcupdeluxe\fpc\units\arm-wince\rtl\system.ppu..


I can resolve this error (beside using precompiled units with same flag 
set) by adding "-CfFPV2" also in fpc.cfg after:

#IFDEF FPC_CROSSCOMPILING
#IFDEF WINCE
#IFDEF CPUARM

So in this use case it is not sufficient only have two (or third) 
distinct sets of precompiled units ...


So can these problems be solved somehow using only Project Options 
without need to modify fpc.cfg ?


Btw. in fpc.cfg I have:
# searchpath for units and other system dependent things
-FuD:\TEMP\fpcupdeluxe\fpc/units/$fpctarget
-FuD:\TEMP\fpcupdeluxe\fpc/units/$fpctarget/*
-FuD:\TEMP\fpcupdeluxe\fpc/units/$fpctarget/rtl

Can this be avoided in fpc.cfg and transfered to Project Options ? (is 
/* supported in Lazarus, becuase Lazarus complains about non-existent 
directory)


TIA

-Laco.

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

Re: [fpc-pascal] Compile for WinCE 7, target ARM, CPU Cortex-A9

2019-04-05 Thread LacaK






Note that you probably don't need two different cross compilers
if your cpu-OS target is the same


Target CPU family is same: "arm", but Target processor is not the
same: "ARMv4" versus "ARMv7" ...

So I do not know if this requires two pre-compiled cross-compilers
or not?

You only need different compilers if you have different ABIs (e.g. 
Soft Float vs. Hard Float). For WinCE that isn't applicable however.


So it does not matter how I build cross-compiler using FpcUpDeluxe: 
wheter I use "-Cparmv5" or "-Cparmv7A" ?


Then there is still problem with precompiled RTL/packages?

Because when I only change "Target processor" (in Lazarus build using 
FpcUpDeluxe) I can compile application, but I can not run it on target 
system (so I guess, that resulting EXE is not compiled for target 
processor).


When I add to Custom options: -CfVFPV2 then I get error while compiling: 
Fatal: Can't find unit system used by Test1


When I download and install default Lazarus and cross-compiler then when 
I change "Target processor" to "ARMv5" or "ARMv7A" I get: 
"project1.lpr(22,0) Error: Error while assembling exitcode 1"


-Laco.


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

Re: [fpc-pascal] Compile for WinCE 7, target ARM, CPU Cortex-A9

2019-04-05 Thread LacaK



Drawback is that I must now maintain 2 FPC
installations/cross-compilers
(Win32-WinCE): one for targer WinCE 5,6 with CPUs ARMv5 and
another for
WinCE 7 with ARMv7 CPU (It is not sufficient to setup build modes in
project ... also all units must be pre-compiled ... at least I do not
know how to bypass this limitation)


I suspect your problem is related to this feature request: 
https://bugs.freepascal.org/view.php?id=30294



Yes seems so ...


Note that you probably don't need two different cross compilers if 
your cpu-OS target is the same


Target CPU family is same: "arm", but Target processor is not the same: 
"ARMv4" versus "ARMv7" ...


So I do not know if this requires two pre-compiled cross-compilers or not?


, only two different versions of the RTL (and perhaps packages) in a 
way that enables the compiler to pick the correct version.  For 
avr-embedded I change the unit output folder name to 
avr-embedded-SUBARCH and add the subarch macro to fpc.cfg.  For arm 
you may also need to handle different ABI versions (I don't cross 
compile for arm).


I can set in Project Options "Unit Output Directory", but how to set 
where RTL/packages are located ...


Perphas recompilation RTL/packages for given target processor from 
sources is okay for me, but is it doable in one Lazarus with one cross 
compiler?


-Laco.


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

Re: [fpc-pascal] Compile for WinCE 7, target ARM, CPU Cortex-A9

2019-04-04 Thread LacaK



Hi,

Is there needed something special to setup when I want compile for my 
Symbol MC9200 device, which has Windows Embedded Compact 7 and Dual 
core 1GHz OMAP 4 processor (ARM Cortex-A9).


When I set up simplest project with only few lines of code and compile 
for OS="WinCE", CPU family="arm" and I run this application I get 
Access Violation on target device. I have tested with target CPU = 
(default), ARMv3, ARMv4 but other CPUs like ARMv5,... does not compile 
("Error while assembling exitcode 1").


Is ARM Cortex-A9 supported in Free Pascal compiler and does "Access 
violation" can be caused by wrong cross compiler setup?

What to do to get working solution?


Answering my own question:

When I build cross compiler using FpcUpDeluxe, where I set "Cross Build 
Options Override" to "-Cparmv7A" (The Cortex -A9 cores implement the 
ARMv7-A architecture) then I can sucessfully compile my application for 
WinCE 7.


Drawback is that I must now maintain 2 FPC installations/cross-compilers 
(Win32-WinCE): one for targer WinCE 5,6 with CPUs ARMv5 and another for 
WinCE 7 with ARMv7 CPU (It is not sufficient to setup build modes in 
project ... also all units must be pre-compiled ... at least I do not 
know how to bypass this limitation)


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

[fpc-pascal] Compile for WinCE 7, target ARM, CPU Cortex-A9

2019-04-03 Thread LacaK

Hi,

Is there needed something special to setup when I want compile for my 
Symbol MC9200 device, which has Windows Embedded Compact 7 and Dual core 
1GHz OMAP 4 processor (ARM Cortex-A9).


When I set up simplest project with only few lines of code and compile 
for OS="WinCE", CPU family="arm" and I run this application I get Access 
Violation on target device. I have tested with target CPU = (default), 
ARMv3, ARMv4 but other CPUs like ARMv5,... does not compile ("Error 
while assembling exitcode 1").


Is ARM Cortex-A9 supported in Free Pascal compiler and does "Access 
violation" can be caused by wrong cross compiler setup?

What to do to get working solution?

Thanks in advance

-Laco.


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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-22 Thread LacaK





(I am asking because in future probably in our company we will need 
generate PDF invoices which should be digitaly signed)


I've looked at the documentation and it is quite doable to implement 
this. Could be a nice task, but it will and somewhere at the bottom of 
my to-do list until I need it for my work myself.


Of course. I understand. If it goes into play may be I will look at 
details also. As far as we are company owned by state we have relative 
strong restrictive policy for what we can spend money ;-|


L.


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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-22 Thread LacaK




(but looking into PDF there is still in FontDescriptor wrong
MissingWidth attribute, which does not goes into play AFAICS)

What do you think is wrong with it?

Look into test-noembed.pdf which I have attached to prior email. There is:
10 0 obj
<<
/Type /FontDescriptor
/FontName /Courier#20New
/FontFamily /Courier#20New
/Flags 32
/Ascent 1255
/Descent -386
/CapHeight 1170
/FontBBox [-122 -680 623 1021]
/ItalicAngle 0
/StemV 70
/MissingWidth 61453   <-- HERE
>>

endobj



  On my side it is set to 600, which
as far as I can see is correct for cour.ttf subset embedded font.


Yes that is correct and I have 600 in:

8 0 obj
<<
/Type /Font
/Subtype /CIDFontType2
/BaseFont /Courier#20New
/CIDSystemInfo 9 0 R
/FontDescriptor 10 0 R
/W [ 16 [600] 36 [600] 40 [600] 44 [600] 50 [600] 56 [600] 200 [600] 101 
[600] 203 [600] 207 [600] 210 [600] 253 [600] 277 [600] 226 [600] 228 [600]]

>>
endobj



  That
value is only used by PDF viewers when they need to display a glyph, but
the glyph is not defined in the selected font.


Yes may be that wrong value will never be used so it will have no 
negative impact, but it is potential source of problem ...





I'll take another look at the spacing issue.


Thank you ... In case no font is embedded all is okay, but in case font 
is embedded something wrong is still there ...







Can I ask what is purpose of Sections in PDF structure?
Because when I want use more than 1 Section I get exception "Dictionary
element "Count" not found."

It allows you to be infinitely flexible with the layout of a document.
eg: If a report had several sections with different margins, headers,
footers, orientation etc. You would use sections to set those. Attached
is a very simple PDF showing sections. Note: some had different page
layout, page numbering etc.

If you have a decent PDF (reporting) viewer that support sections, you
can jump between sections like you jump between pages.
I ma trying look at PDF document using Adobe Acrobat Reader and Foxit 
Reader, but I can not see sections (nor any support for jumping between 
them) ...


So in PDF document sections correspond to /Kids [5 0 R 14 0 R 21 0 R] ...



  fpGUI's "report
preview" supports that.

I'll take a look at the sections issue you raised. Would you be so kind
as to create a Mantis report for that specific bug.


https://bugs.freepascal.org/view.php?id=35258






Would it be possible to add "shortcut" AddPage directly to TPDFDocument,
which will add Page to last Section or create new section if none exists?

Obviously it could be added, but do we? It's comes down to different
users with different needs. Plus what Michael said about the Dutch
saying. ;-)


Of course, but why not make life easier if we can. I think, that 99% of 
users will use only 1 section and also section concept is not intuitive 
without explanation (or if is not documented)


Same holds for default Options. If now is preset in constructor:

FOptions := [poCompressFonts, poCompressImages];

how many users will benefit from?:

FOptions := [poCompressFonts, poCompressImages, poPageOriginAtTop, 
poSubsetFont];


I think that it is useful. (why repeat something which can be preset and 
gives reasonable default settings)
It has also educational effect, which teach users what is optimal. In 
case of poSubsetFont why someone should not use always poSubsetFont? IMO 
it is always good choice have smaller sized file than bigger, does not?







How complicated would be add support for digital signing of PDF documents?

I briefly looked at that when I implemented fpPDF, and that is quite
tricky.  Plus I don't fully understand all the requirements yet.

:-( ok thank you

(I am asking because in future probably in our company we will need 
generate PDF invoices which should be digitaly signed)




How complicated would be (in case of embedding fonts) subset only those
characters, which are used in document, not a whole font?

That is exactly how [poSubsetFont] works. Simple to test. Embed a large
font like "DejaVu Sans". With poSubSetFont disabled, a one page PDF with
the only text "Hello World" will be a couple of MBs in size. Then enable
poSubsetFont and see the massive size reduction.


Yes

-Laco.


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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-22 Thread LacaK



I attached 2 patches to the bug tracker which solves the problem for me.

1.
I can confirm, that in my case it is fixed for NO-embedded case only. 
For embedded fonts case there is still small issue (some characters are 
okay, some are shifted) - see attachments


(but looking into PDF there is still in FontDescriptor wrong 
MissingWidth attribute, which does not goes into play AFAICS)


2.
Can I ask what is purpose of Sections in PDF structure?
Because when I want use more than 1 Section I get exception "Dictionary 
element "Count" not found."

Try:
  PDF.Sections.AddSection;
  PDF.Sections[0].Title := 'Section1';
  PDF.Sections[0].AddPage(PDF.Pages.AddPage);

  PDF.Sections.AddSection;
  PDF.Sections[1].Title := 'Section2';
  PDF.Sections[1].AddPage(PDF.Pages.AddPage);

3.
Would it be possible to add "shortcut" AddPage directly to TPDFDocument, 
which will add Page to last Section or create new section if none exists?
(if I guess right there is no big usage of sections in user code, so 
hide sections from user POV is no issue)


4.
How complicated would be add support for digital signing of PDF documents?

5.
How complicated would be (in case of embedding fonts) subset only those 
characters, which are used in document, not a whole font?

(or does it works already so?)

6.
Would it be possible to use as default:
FOPtions := [poCompressFonts, poCompressImages, poPageOriginAtTop, 
poSubsetFont];

(which are IMO most used options)

Thank you

-Laco.




test-noembed.pdf
Description: Adobe PDF document


test-embed.pdf
Description: Adobe PDF document
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-21 Thread LacaK



I am trying work with fpPDF. I can create PDF document, but character
out of ASCII range are displayed wrong (in PDF file they are stored as
UTF8).

First things first... what version of FPC are you using? FPC 3.0.4 or
FPC 3.1.1 - just so I know what code to look at.


I tried both versions 3.0.4 and also trunk




I had a quick look and indeed there is something strange (or different)
with the "cour.ttf" font. At closer inspection (using FontForge font
editor) the "cour.tff" as supplied by Microsoft is some hybrid
TTF+Bitmap font. The "arial.ttf" is a pure truetype font (no bitmap
glyphs embedded).

Not 100% sure yet if that is the cause or not. Maybe some special
processing is needed for hybrid fonts. I'll investigate further.


I think that problem is related to font parsing. As I wrote in comment 
to bug report #35251 there is incorrectly extracted information about 
char Widths ... look into attached generated PDF there ...


Thank you ...

-Laco.

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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-20 Thread LacaK







Is there way how to get correct PDF file WITHOUT embedding full 
Courier font?


You can embed only the needed characters for every font ?
Probably yes, but fpPDF will not handle this automatically? AFAIK I 
can not control this.


But why I get unreadable characters? What I am doing wrong ?


It seems that there is problem specific to CourierNew font (cour.ttf).
With Arial (arial.ttf) it works as expected.

Attached program which demonstrates problem.


Reported as bug https://bugs.freepascal.org/view.php?id=35251
(probably there is problem in parsing Courier New TTF font?)


I am not sure this is the reason.

I suspect that the Arial font has unicode glyphs, and courier not.

I do not know, but with other fonts: Arial, Verdana, Consolas it works 
as expected. Do you think, that Courier New is only exception?


When I look at 
https://docs.microsoft.com/en-us/typography/font-list/courier-new I do 
not see there something special compared to other fonts ...


But my knowledge about font structures (and also about PDF internals) is 
minimal ...



Because how is the PDF generator supposed to know that it should 
transcode your text to latin 2 ?


I do not know if it is necesssary.

I have used FPDF port of PHP PDF library, which I have rewritten to 
pascal and there I can use "Courier New" font.

(in both ways as embedded and also when not embedded)

Probably FPDF handles PDF generation bit differently, but when I write 
into file any text in code page CP1250 and I embedd Courier New font 
(generated in advance by using makefont.php utility) then I get correct 
result.


So my raw guess was that it must be doable also using fcl-pdf somehow?

-Laco.

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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-20 Thread LacaK





Is there way how to get correct PDF file WITHOUT embedding full 
Courier font?


You can embed only the needed characters for every font ?
Probably yes, but fpPDF will not handle this automatically? AFAIK I 
can not control this.


But why I get unreadable characters? What I am doing wrong ?


It seems that there is problem specific to CourierNew font (cour.ttf).
With Arial (arial.ttf) it works as expected.

Attached program which demonstrates problem.


Reported as bug https://bugs.freepascal.org/view.php?id=35251
(probably there is problem in parsing Courier New TTF font?)

-Laco.


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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-19 Thread LacaK



Is there way how to get correct PDF file WITHOUT embedding full 
Courier font?


You can embed only the needed characters for every font ?
Probably yes, but fpPDF will not handle this automatically? AFAIK I 
can not control this.


But why I get unreadable characters? What I am doing wrong ?


It seems that there is problem specific to CourierNew font (cour.ttf).
With Arial (arial.ttf) it works as expected.

Attached program which demonstrates problem.

-Laco.

unit test_fpPDF1;

{$mode objfpc}{$H+}
{$codepage UTF8}


interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
Edit1: TEdit;
procedure FormShow(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

uses fpPDF;

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
var
  PDF: TPDFDocument;
  Font1, Font2: integer;
begin
  PDF := TPDFDocument.Create(Self);
  PDF.Infos.Producer := '';
  PDF.Infos.CreationDate := Now;
  PDF.Options := [poPageOriginAtTop, {poNoEmbeddedFonts,} poSubsetFont, 
poCompressFonts, poCompressImages];
  PDF.DefaultOrientation := ppoPortrait;
  PDF.DefaultPaperType := ptA4;
  PDF.DefaultUnitOfMeasure := uomMillimeters;
  PDF.FontDirectory := 'C:\WINDOWS\FONTS';
  PDF.StartDocument;
  PDF.Sections.AddSection;
  PDF.Sections[0].AddPage(PDF.Pages.AddPage);;

  //FontIndex := PDF.AddFont('Courier');
  Font1 := PDF.AddFont('cour.ttf', 'CourierNew');
  Font2 := PDF.AddFont('arial.ttf', 'Arial');
  PDF.Pages[0].SetFont(Font1, 10);
  PDF.Pages[0].WriteText(10,10,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  PDF.Pages[0].WriteText(10,15,'');
  PDF.Pages[0].WriteText(10,20,Edit1.Text);

  PDF.Pages[0].SetFont(Font2, 10);
  PDF.Pages[0].WriteText(10,30,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  PDF.Pages[0].WriteText(10,35,'');

  PDF.SaveToFile('test.pdf');
end;

end.

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

Re: [fpc-pascal] fpPDF and support of Latin2 charset

2019-03-19 Thread LacaK





Hi,

I am trying work with fpPDF. I can create PDF document, but character 
out of ASCII range are displayed wrong (in PDF file they are stored 
as UTF8).
Probably it is because I use standard Courier font, which is 
expecting only "Latin characters" ? I use:


FontIndex := PDF.AddFont('Courier'); // --> test1.pdf

When I want to use TTF font:

FontIndex := PDF.AddFont('cour.ttf','CourierNew');  // --> test2.pdf
(nothing else this line has changed)

I get strange PDF file (I can open it but content is wrong)

What I am doing wrong? Is there way how to get correct PDF with 
characters from Latin2 code page?


Not to my knowledge. You must use unicode for characters outside the 
ASCII range.


Seems, that Adobe in 
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf 
in Annex D2: "Latin Character Set and Encodings" specifies exactly which 
characters are supported (by standard 14 fonts). Characters not listed 
there are simply replaced by "X" in Adobe Acrobat Reader. But Foxit 
reader displays them correctly (so I can use full range of characters 
from CP1250 when I specify appropriate 

[fpc-pascal] fpPDF and support of Latin2 charset

2019-03-19 Thread LacaK

Hi,

I am trying work with fpPDF. I can create PDF document, but character 
out of ASCII range are displayed wrong (in PDF file they are stored as 
UTF8).
Probably it is because I use standard Courier font, which is expecting 
only "Latin characters" ? I use:


FontIndex := PDF.AddFont('Courier'); // --> test1.pdf

When I want to use TTF font:

FontIndex := PDF.AddFont('cour.ttf','CourierNew');  // --> test2.pdf
(nothing else this line has changed)

I get strange PDF file (I can open it but content is wrong)

What I am doing wrong? Is there way how to get correct PDF with 
characters from Latin2 code page?
Is there way how to get correct PDF file WITHOUT embedding full Courier 
font?


Thanks

-Laco.

Full source code is:

var
  PDF: TPDFDocument;
  FontIndex: integer;
begin
  PDF := TPDFDocument.Create(Self);
  PDF.Infos.Producer := '';
  PDF.Infos.CreationDate := Now;
  PDF.Options := [poPageOriginAtTop, {poNoEmbeddedFonts,} poSubsetFont, 
poCompressFonts, poCompressImages];

  PDF.DefaultOrientation := ppoPortrait;
  PDF.DefaultPaperType := ptA4;
  PDF.DefaultUnitOfMeasure := uomMillimeters;
  PDF.FontDirectory := 'C:\WINDOWS\FONTS';
  PDF.StartDocument;
  PDF.Sections.AddSection;
  PDF.Sections[0].AddPage(PDF.Pages.AddPage);;

  //FontIndex := PDF.AddFont('Courier');
  FontIndex := PDF.AddFont('cour.ttf', 'CourierNew');
  PDF.Pages[0].SetFont(FontIndex, 10);
  PDF.Pages[0].WriteText(10,10,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  PDF.Pages[0].WriteText(10,15,'');
  PDF.Pages[0].WriteText(10,20,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');

  PDF.SaveToFile('test.pdf');
end;



test1.pdf
Description: Adobe PDF document


test2.pdf
Description: Adobe PDF document
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Conversion of buffer of UnicodeChars to AnsiString

2019-01-22 Thread LacaK
Hi,

is there smarter way how to convert buffer of UnicodeChars to AnsiString
taking into account codepage conversion as:

as := String(UnicodeCharLenToString(buffer, buflen shr 1));

?

And second question if I want to avoid warnings: "Implicit conversion
from WideString to AnsiString ..." in cases:

as := ws;

I must use only explicit typecast:

as := AnsiString(ws); ?


-Laco.

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

Re: [fpc-pascal] Small typo in User_Changes_Trunk ?

2019-01-07 Thread LacaK

> Am Mo., 7. Jan. 2019, 08:33 hat LacaK  <mailto:la...@zoznam.sk>> geschrieben:
>
> Hi,
>
> reading
> 
> http://wiki.freepascal.org/User_Changes_Trunk#Modeswitch_TypeHelpers_in_Delphi_modes_enables_type_helper-syntax
> there is:
>
> Remedy: The only problems arise if one disabled the modeswitch on
> purpose which now longer disallows the extension of primitive types.
>
> Is there missing "no"?:
>
> Remedy: The only problems arise if one disabled the modeswitch on
> purpose which now *no* longer disallows the extension of primitive
> types.
>
>
> Ehm, yes. Well spotted. If you want you can fix it :)

Fixed.

-Laco.


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

[fpc-pascal] Small typo in User_Changes_Trunk ?

2019-01-06 Thread LacaK
Hi,

reading
http://wiki.freepascal.org/User_Changes_Trunk#Modeswitch_TypeHelpers_in_Delphi_modes_enables_type_helper-syntax
there is:

Remedy: The only problems arise if one disabled the modeswitch on
purpose which now longer disallows the extension of primitive types.

Is there missing "no"?:

Remedy: The only problems arise if one disabled the modeswitch on
purpose which now *no* longer disallows the extension of primitive types.

-Laco.

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

Re: [fpc-pascal] Can't determine which overloaded function to call

2018-12-05 Thread LacaK

>> helps, but why is it not needed in Win32? Why for Win32
>> "integer"-"integer" is considered as "integer" so compiler can determine
>> which overloaded function to call and for Win64 compiler compiler can
>> NOT determine which overloaded function to call?
>
> It is because as documented at
> https://www.freepascal.org/docs-html/ref/refsu4.html (remarks under
> table 3.2), FPC evaluates integer expressions using the native integer
> type of the platform.

Do you mean: "2. Every integer smaller than the ”native” size is
promoted to a signed version of the ”native” size. Integers equal to the
”native” size keep their signedness. "?


> On Win32 this is 32 bit, while on Win64 this is 64 bit. On the other
> hand, "integer" is always 32 bit in Delphi mode.
>
> This means that on Win32, there is an exact match for overload
> selection in your test program, while on Win64 there is not and the
> int64 -> integer and int64 -> single type conversions have the same
> priority.

I understand now. Although I must say that it is bit unintuitive for me ;-)

So I can workaround using:
    function Offset(const Ax,Ay: PtrInt): TRec1; overload;

Thank you for explanation

-Laco.

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

Re: [fpc-pascal] Can't determine which overloaded function to call

2018-12-04 Thread LacaK

>
>> Hi *,
>>
>> this code compiles for target Win32 but does not compile for
>> Win64/x86-64. Why? Is there workaround?
>> (Error: Can't determine which overloaded function to call)
>> Thank you
> For me, in win32 works fine

Yes in Win32 works also for me. And this is my question why it does work
in Win32 and does not work in Win64?


>
> try this
>
> r1.Offset(a-Integer(1),b-Integer(1));

does not helps


>
> or
>
> r1.Offset(Integer(a-1),Integer(b-1));

helps, but why is it not needed in Win32? Why for Win32
"integer"-"integer" is considered as "integer" so compiler can determine
which overloaded function to call and for Win64 compiler compiler can
NOT determine which overloaded function to call?

It seems to me as inconsistent?

L.

=== code sample ===

  TRec1 = record
    x,y: integer;
    function Offset(const Ax,Ay: integer): TRec1; overload;
    function Offset(const Ax,Ay: single): TRec1; overload;
  end;

function TRec1.Offset(const Ax,Ay: integer): TRec1;
begin
end;

function TRec1.Offset(const Ax,Ay: single): TRec1;
begin
end;

var
  r1: TRec1;
  a,b: integer;

begin
  r1 := r1.Offset(a-1,b-1); // HERE Error:
end.  




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

[fpc-pascal] Can't determine which overloaded function to call

2018-12-04 Thread LacaK
Hi *,

this code compiles for target Win32 but does not compile for
Win64/x86-64. Why? Is there workaround?
(Error: Can't determine which overloaded function to call)
Thank you
-Laco.

=== code sample ===

  TRec1 = record
    x,y: integer;
    function Offset(const Ax,Ay: integer): TRec1; overload;
    function Offset(const Ax,Ay: single): TRec1; overload;
  end;

function TRec1.Offset(const Ax,Ay: integer): TRec1;
begin
end;

function TRec1.Offset(const Ax,Ay: single): TRec1;
begin
end;

var
  r1: TRec1;
  a,b: integer;

begin
  r1 := r1.Offset(a-1,b-1); // HERE Error:
end.  



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

Re: [fpc-pascal] Firebird vs. SQLite vs. PosgreSQL

2018-11-06 Thread LacaK
Hi,

Comparasion of some basic features between database engines you can find
at:
https://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems

L.


> Hi,
> This isn't a Free Pascal question but I wanted to ask about the
> Firebird database [1] because it seems as the Free Pascal community
> uses it the most by far, so I hope it isn't too off-topic.
>
> I've read the Firebird webpage and installed it but I can't seem to
> find documentation on how it compares to SQLite and PostgreSQL. My
> high level understanding is that it sits somewhere it between but I'm
> looking for more in depth comparisons on performance, data integrity
> tests and maybe even some real world experience anecdotes (+ive and
> -ive) on deployment, maintenance etc.
>
> Thanks!
> -deech
>
> [1] https://firebirdsql.org/
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Regression in StrToDateTime()

2018-06-14 Thread LacaK



You also can make your own procedure to fix the issue for yourself.
Like you can rewrite the function StrToDateTime() to change all '. ' 
to '.' and then call the original function StrToDateTime()
Of course it is possible, but IMO it should be fixed in general way. I 
have reported bug #33860
I can prepare think about patch, but I must know what situations, 
formats must be supported by SplitDateTimeStr() and what is expected output.

(this should be documented is source code)
L.




On Thu, 14 Jun 2018, LacaK wrote:


Hi,

now I am migrating my applications from FPC 2.6.4 to FPC 3.0.4 and I 
noticed that logic in function StrToDateTime() was changed.


In 2.6.4 there was first detected position of first TimeSeparator and 
then walking back to first occurence of WhiteSpace.
This approach allows DateSeparator='. ' (dot+space) which is for 
example default settings in Windows7 in Slovak language 
(TimeSeparator=':').


Now in FPC 3.0.4 firs occurence of space causes division of date and 
time. It results in where:
'11. 07. 2018 13:00' is divided to date part = '11.' and time 
part='07. 2018' which is wrong.


There is in FPC 3.0.4 new function SplitDateTimeStr():
...
  //find separator
  if (FS.DateSeparator<>#32) then
    begin
    while (pWhiteSpace)) do

  Inc(p);
    end
  else
    begin
    p:=Pos(FS.TimeSeparator, DateTimeStr);
    if (p<>0) then
  repeat
    Dec(p);
  until (p=0) or (DateTimeStr[p] in WhiteSpace);
    end;
...

In first part of code is located first occurnce of white space, which 
is also part of DateSeparator!

Can this be to fixed ?

L.

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



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


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

[fpc-pascal] Regression in StrToDateTime()

2018-06-14 Thread LacaK

Hi,

now I am migrating my applications from FPC 2.6.4 to FPC 3.0.4 and I 
noticed that logic in function StrToDateTime() was changed.


In 2.6.4 there was first detected position of first TimeSeparator and 
then walking back to first occurence of WhiteSpace.
This approach allows DateSeparator='. ' (dot+space) which is for example 
default settings in Windows7 in Slovak language (TimeSeparator=':').


Now in FPC 3.0.4 firs occurence of space causes division of date and 
time. It results in where:
'11. 07. 2018 13:00' is divided to date part = '11.' and time part='07. 
2018' which is wrong.


There is in FPC 3.0.4 new function SplitDateTimeStr():
...
  //find separator
  if (FS.DateSeparator<>#32) then
    begin
    while (pWhiteSpace)) do

  Inc(p);
    end
  else
    begin
    p:=Pos(FS.TimeSeparator, DateTimeStr);
    if (p<>0) then
  repeat
    Dec(p);
  until (p=0) or (DateTimeStr[p] in WhiteSpace);
    end;
...

In first part of code is located first occurnce of white space, which is 
also part of DateSeparator!

Can this be to fixed ?

L.

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

Re: [fpc-pascal] Currency and Int64 casting

2018-05-18 Thread LacaK



Moreover:

var
  c: currency;
  i1: int64;
  i2: int64 absolute c;

begin
  c := 68719476736;
  i1 := Trunc(c*1);
  writeln(c,', ',i1,', ',i2);
  readln;
end.

Win32 (as expected):  6.8719476736E+10, 68719476736, 
68719476736
Win64 (wrong)  :  6.8719476736E+10, 
53550614319 , 68719476736



I have created bug report:
https://bugs.freepascal.org/view.php?id=33758


L.


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

Re: [fpc-pascal] Currency and Int64 casting

2018-05-18 Thread LacaK

Moreover:

var
  c: currency;
  i1: int64;
  i2: int64 absolute c;

begin
  c := 68719476736;
  i1 := Trunc(c*1);
  writeln(c,', ',i1,', ',i2);
  readln;
end.

Win32 (as expected):  6.8719476736E+10, 68719476736, 
68719476736
Win64 (wrong)  :  6.8719476736E+10, 53550614319 
, 68719476736


L.


Than you,



I have

unit1.pas:36   i:=Int64(c);

0046EEE0 488b45e8 mov-0x18(%rbp),%rax

0046EEE4 488945e0 mov%rax,-0x20(%rbp)

unit1.pas:38   writeln(i);

at Level0 and
unit1.pas:36  i:=Int64(c);
0046EECD 4c8b2424 mov (%rsp),%r12
unit1.pas:38  writeln(i);
at Level3.
So we can clearly say, that x64_86 output is different on Linux and 
Windows64
It is at least strange from my POV because I would expect consistent 
results across platforms.


I just noticed that you wrote you are expecting 1000. You should 
expect 1 since currency has four decimals.

Yes, it was typo. Of course I expect 1

L.


V.

__
> Od: LacaK <la...@zoznam.sk>
> Komu: fpc-pascal@lists.freepascal.org
> Datum: 18.05.2018 07:54
> Předmět: Re: [fpc-pascal] Currency and Int64 casting
>


Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 1.00E+00 1

What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19i1 := Int64(c);
0040158D a100c04200   mov0x42c000,%eax
00401592 a310c04200   mov%eax,0x42c010
00401597 a104c04200   mov0x42c004,%eax
0040159C a314c04200   mov%eax,0x42c014

and for Win64:
test_curr_int64.lpr:19i1 := Int64(c);
000115BD 488b0d3caa0300   mov 
0x3aa3c(%rip),%rcx# 0x10003c000

000115C4 48b84b598638d6c56d34 movabs $0x346dc5d63886594b,%rax
000115CE 48f7e9   imul   %rcx
000115D1 48c1fa0b sar$0xb,%rdx
000115D5 48c1e93f shr$0x3f,%rcx
000115D9 4801ca   add%rcx,%rdx
000115DC 4889152daa0300   mov 
%rdx,0x3aa2d(%rip)# 0x10003c010



L.

__
> Od: LacaK <la...@zoznam.sk> <mailto:la...@zoznam.sk>
> Komu: FPC-Pascal users discussions
<fpc-pascal@lists.freepascal.org>
<mailto:fpc-pascal@lists.freepascal.org>
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that
I can
use: i: int64 absolute c;)

Thanks

-Laco.

___
fpc-pascal maillist  - fpc-pascal@lists.freepascal.org
<mailto:fpc-pascal@lists.freepascal.org>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -fpc-pascal@lists.freepascal.org
<mailto:fpc-pascal@lists.freepascal.org>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




--

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


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




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


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

Re: [fpc-pascal] Currency and Int64 casting

2018-05-18 Thread LacaK

Than you,



I have

unit1.pas:36 i:=Int64(c);

0046EEE0 488b45e8 mov-0x18(%rbp),%rax

0046EEE4 488945e0 mov%rax,-0x20(%rbp)

unit1.pas:38 writeln(i);

at Level0 and
unit1.pas:36  i:=Int64(c);
0046EECD 4c8b2424 mov (%rsp),%r12
unit1.pas:38  writeln(i);
at Level3.
So we can clearly say, that x64_86 output is different on Linux and 
Windows64
It is at least strange from my POV because I would expect consistent 
results across platforms.


I just noticed that you wrote you are expecting 1000. You should 
expect 1 since currency has four decimals.

Yes, it was typo. Of course I expect 1

L.


V.

__
> Od: LacaK <la...@zoznam.sk>
> Komu: fpc-pascal@lists.freepascal.org
> Datum: 18.05.2018 07:54
> Předmět: Re: [fpc-pascal] Currency and Int64 casting
>


Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 1.00E+00 1

What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19i1 := Int64(c);
0040158D a100c04200   mov0x42c000,%eax
00401592 a310c04200   mov%eax,0x42c010
00401597 a104c04200   mov0x42c004,%eax
0040159C a314c04200   mov%eax,0x42c014

and for Win64:
test_curr_int64.lpr:19i1 := Int64(c);
000115BD 488b0d3caa0300   mov 
0x3aa3c(%rip),%rcx# 0x10003c000

000115C4 48b84b598638d6c56d34 movabs $0x346dc5d63886594b,%rax
000115CE 48f7e9   imul   %rcx
000115D1 48c1fa0b sar$0xb,%rdx
000115D5 48c1e93f shr$0x3f,%rcx
000115D9 4801ca   add%rcx,%rdx
000115DC 4889152daa0300   mov 
%rdx,0x3aa2d(%rip)# 0x10003c010



L.

__
> Od: LacaK <la...@zoznam.sk> <mailto:la...@zoznam.sk>
> Komu: FPC-Pascal users discussions
<fpc-pascal@lists.freepascal.org>
<mailto:fpc-pascal@lists.freepascal.org>
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that
I can
use: i: int64 absolute c;)

Thanks

-Laco.

___
fpc-pascal maillist  - fpc-pascal@lists.freepascal.org
<mailto:fpc-pascal@lists.freepascal.org>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -fpc-pascal@lists.freepascal.org
<mailto:fpc-pascal@lists.freepascal.org>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




--

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


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


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

Re: [fpc-pascal] Currency and Int64 casting

2018-05-17 Thread LacaK



Linux 64-bit Lazarus 1.9.0 r57948M FPC 3.1.1 x86_64-linux-qt gives

 1.00E+00 1


What is dissassembly for:
  i:=Int64(c);?

I have for Win32:
test_curr_int64.lpr:19i1 := Int64(c);
0040158D a100c04200   mov0x42c000,%eax
00401592 a310c04200   mov%eax,0x42c010
00401597 a104c04200   mov0x42c004,%eax
0040159C a314c04200   mov%eax,0x42c014

and for Win64:
test_curr_int64.lpr:19i1 := Int64(c);
000115BD 488b0d3caa0300   mov 0x3aa3c(%rip),%rcx
# 0x10003c000

000115C4 48b84b598638d6c56d34 movabs $0x346dc5d63886594b,%rax
000115CE 48f7e9   imul   %rcx
000115D1 48c1fa0b sar$0xb,%rdx
000115D5 48c1e93f shr$0x3f,%rcx
000115D9 4801ca   add%rcx,%rdx
000115DC 4889152daa0300   mov %rdx,0x3aa2d(%rip)
# 0x10003c010



L.


__
> Od: LacaK <la...@zoznam.sk>
> Komu: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>
> Datum: 17.05.2018 13:33
> Předmět: [fpc-pascal] Currency and Int64 casting
>

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can
use: i: int64 absolute c;)

Thanks

-Laco.

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


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


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

[fpc-pascal] Currency and Int64 casting

2018-05-17 Thread LacaK

Hi,

consider following program:

var
  c: currency;

begin
  c := 1;
  writeln(c,' ',Int64(c));
  readln;
end.

FPC 3.0.4
On Win32/x86 I get: 1, 1000  (what I am expecting)
On Win64/x86_64 I get: 1, 1

Is is as expected ?

Is there safe way for both platforms how to get 1000 (beside that I can 
use: i: int64 absolute c;)


Thanks

-Laco.

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

Re: [fpc-pascal] Multiple active class helpers at same time

2018-04-23 Thread LacaK





Is planned support for multiple class(objet, record) helpers in a
way,
that all class helpers can be used in parallel  not only one?


Yes, it is planned. Main problem currently (aside from time) is to 
define when a method hides the method of another helper, especially 
when inheritance (both for the helper and the extended type) is involved.
Later in uses clause wins ... as for other cases where in different 
units are used same names

But probably problem is deeper , what I am not aware of ;-)
-Laco.

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

Re: [fpc-pascal] Multiple active class helpers at same time

2018-04-23 Thread LacaK



Dňa 23.4.2018 o 13:52 Maciej Izak napísal(a):
2018-04-23 13:45 GMT+02:00 Maciej Izak >:


https://github.com/maciej-izak/PascalSmartPointers/tree/master/examples



small mistake, this is more proper url :)

https://github.com/maciej-izak/PascalSmartPointers/tree/master/sources 



--

Thank you.
Can you give small example for my use case ? I can not understand from 
above mentioned examples.


So I need to have:

unit A;
type
  TClassA = class
public
   procedure Method1;
  end;

unit B;
type
  TClassAHelper1 = class helper for TClassA
public
  procedure MethodB1;
  procedure MethodB2;
end;

unit C;
type
  TClassAHelper2 = class helper for TClassA
public
  procedure MethodC1;
  procedure MethodC2;
end;

and in program:

use A,B,C;
var instanceA: TClassA;
...
instanceA := TClassA.Create;
instanceA.Method1;
instanceA.MethodB1; // defined in unit B
instanceA.MethodC1; // defined in unit C
...

L.

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

[fpc-pascal] Multiple active class helpers at same time

2018-04-23 Thread LacaK

Hi ,

I am sure that this was already discussed, but I can not find any 
conclusion.


Is planned support for multiple class(objet, record) helpers in a way, 
that all class helpers can be used in parallel  not only one?


My use case is:

In unit A I have declared base class.
In unit B I have declared helper for class defined in unit A which adds 
some extended functionality (new methods) to class A
In unit C I have declared helper for class defined in unit A which adds 
some extended functionality (new methods) to class A


In program P1 once I need only functionality defined in A, B so I use A,B
In program P2 I need functionality defined in A,B,C so I want use A,B,C 
but It does not work as only one class helper can be active.


If such feature will not be implemented, is there any other way how to 
solve this problem (how to add functionalities to one class by adding 
more units to final program)?
If such featurn can be implemented is there already feature request in 
bug tracker?


Thanks

-Laco.

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

Re: [fpc-pascal] FPC attributes / annotations support

2017-11-29 Thread LacaK



the idea) a rewrite of a multi-million lines of code project into C#, rather
than move to open source development tools where they can keep the huge code
base, the same language and reuse the same development skills. How weird??
Have corporates lost their minds.

I believe that the real problem is to find Object Pascal programmers
comparing with other languages.
The companies are thinking in their future.

"Who will maintain this code?"
"No one are using Object Pascal nowadays".

I hear something like this two times per month.  :\

However, we know the potential of Object Pascal as a language to do anything.
If we have a better marketing, maybe more programmers could have more
interest to use the language.
IMO root of problem is in schools. People come to companies from schools 
and what they have learned in schools, is what they are expecting in 
companies ...
When I walked to school, we learned Pascal, I am suspicious, that this 
does not happen nowadays.


-Laco.

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

Re: [fpc-pascal] Callbacks as nested functions

2017-10-23 Thread LacaK
Btw there is long-time open ...  may be related bug 
https://bugs.freepascal.org/view.php?id=18702


L.


Dňa 23.10.2017 o 16:42 Michael Van Canneyt napísal(a):



On Mon, 23 Oct 2017, Ryan Joseph wrote:




On Oct 23, 2017, at 9:05 PM, Michael Van Canneyt 
 wrote:


It is not the default because neither Delphi nor TP allow this.


then that begs the question, why not? :) If local functions are a 
useful feature then local callbacks should be too.


Well, we're not Delphi compiler developers, TP is long defunct, so 
this is the wrong place to ask :)


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


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

Re: [fpc-pascal] TBufDataset vs TClientDataset

2017-10-10 Thread LacaK


Also, what's the difference between TBufDataset and TMemDataset? 
Aren't they both in-memory datasets? If so, why do we have two 
different components for the same thing?



As Michael wrote TMemDataSet is older.

And I add that it is also much "lighter". So for somebody who does not 
need "complexity" of TBufDataset there is IMO still space for TMemDataSet.
(IMO there is no need to emulate TMemDataSet by TBufDataSet ... there is 
TBufDataset a long time and everybody who needs his functionality can 
switch to TBufDataset without much effort)


There may be confusing with naming and purpose, but this can be easily 
solved by adding 1-2 sentences to documentation ...

I added one sentence to: http://wiki.freepascal.org/TMemDataset

-Laco.

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

  1   2   3   >