[fpc-pascal] How to get the current translation of a resource string?
Since I want to treat a specific exception that cannot be distinguished by the class alone but only by the class and message, I need to find the current translation of the resource string used to create the exception. The documentation at https://www.freepascal.org/docs-html/current/prog/progse40.html mentions ResourceStringTableCount, ResourceStringCount, GetResourceStringCurrentValue but I can't find them anywhere in my copy of fpc 3.2.0 (they are in fpc 2.6.4 and 3.0.4). Bye -- Luca ___ 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
On Tue, 1 Dec 2020, 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) From a pure language point of view, true constants do not "exist". They are substituted wherever the compiler finds a reference. So there is no address in memory. A typed constant is like a variable (it is the precursor of the initialized variable), it has an address in memory. Michael.___ 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
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) 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
LacaK via fpc-pascal schrieb am Di., 1. Dez. 2020, 11:00: > > 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? > 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 === Regards, Sven > ___ 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
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
Re: [fpc-pascal] Initialization of constant record member of pointer type
On Mon, 30 Nov 2020, Sven Barth via fpc-pascal wrote: 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); Does this also work with variables ? Might be worth writing in the documentation... Michael.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal