[fpc-devel] How to convert set to integer and vice versa

2014-07-22 Thread Gennady Agranov
Hi, I am new to FPC, but I do like it - thanks! We are trying to switch from Delphi to FPC, but I am stuck with the following issue - in Delphi you can cast set to integer and get it back later - again by casting. In our case it is used for persistence purposes. We have a lot of different

Re: [fpc-devel] Method for write string into TStream

2014-07-22 Thread LacaK
Recap: Way 1: Introduce new method(s), leave Write/ReadAnsiString as is. 1.1 procedure WriteRawString(const s: string); function ReadRawString(Len: integer) 1.2 (ready for future when string will be UnicodeString) procedure WriteString(const s: string); function ReadString(Len: integer)

Re: [fpc-devel] How to convert set to integer and vice versa

2014-07-22 Thread Marco van de Voort
In our previous episode, Gennady Agranov said: I am new to FPC, but I do like it - thanks! We are trying to switch from Delphi to FPC, but I am stuck with the following issue - in Delphi you can cast set to integer and get it back later - again by casting. In our case it is used for

Re: [fpc-devel] How to convert set to integer and vice versa

2014-07-22 Thread tha...@thaddy.com
You will find that if you are converting from a Delphi version equal to or before Delhi 2009, the {$Mode Delphi} or -Mdelphi directive does exactly what you want. On 22-7-2014 3:37, Gennady Agranov wrote: Hi, I am new to FPC, but I do like it - thanks! We are trying to switch from Delphi to

Re: [fpc-devel] Method for write string into TStreamt

2014-07-22 Thread tha...@thaddy.com
A case for ternary computing is not really a bad idea ;) On 21-7-2014 21:42, Hans-Peter Diettrich wrote: Dmitry Boyarintsev schrieb: How about introducing a default parameter? The parameter keeps the method backward compatible, allowing write a string without the prefix. public procedure

Re: [fpc-devel] Method for write string into TStream

2014-07-22 Thread tha...@thaddy.com
You can always use KOL for that ;) But anyway: we implemented that at the cost of read-back speed and looking for zero termination, which is flawed anyway for object pascal strings, since it can contain zero's. It can be done through RTTI with my usual complaints about that sort of shit. A

Re: [fpc-devel] Method for write string into TStreamt

2014-07-22 Thread Dmitry Boyarintsev
On Tue, Jul 22, 2014 at 6:46 AM, tha...@thaddy.com tha...@thaddy.com wrote: A case for ternary computing is not really a bad idea ;) On 21-7-2014 21:42, Hans-Peter Diettrich wrote: Dmitry Boyarintsev schrieb: How about introducing a default parameter? The parameter keeps the method

Re: [fpc-devel] How to convert set to integer and vice versa

2014-07-22 Thread Gennady Agranov
On Tue, Jul 22, 2014 at 5:14 AM, Marco van de Voort mar...@stack.nl wrote: In our previous episode, Gennady Agranov said: I am new to FPC, but I do like it - thanks! We are trying to switch from Delphi to FPC, but I am stuck with the following issue - in Delphi you can cast set to

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread Marco van de Voort
In our previous episode, Gennady Agranov said: Good. And afaik in Delphi mode this works too in FPC? Did you test? casting integer to set does not compile in FPC - and yes - I use Delphi mode :( program setcast; {$ifdef FPC} {$mode delphi} {$else} {$APPTYPE CONSOLE} {$endif} uses

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread tha...@thaddy.com
Yes, Marco, as you previously suspected, It does. I saw you gave already a similar answer to mine. The pointer casts are definitely not necessary, Gennady. Can you show a little example WHERE it doesn't work? In plain fpc, not lazarus code? On 22-7-2014 18:13, Marco van de Voort wrote: In

Re: [fpc-devel] Method for write string into TStreamt

2014-07-22 Thread tha...@thaddy.com
What I was a little bit more than hinting at in my previous answers is that it is impossible for an abstract read stream to know that there's a string to read. There is at least one higher level of implementation necessary: one that recognizes a string. That means probably something like

Re: [fpc-devel] Method for write string into TStreamt

2014-07-22 Thread Dmitry Boyarintsev
On Tue, Jul 22, 2014 at 12:17 PM, tha...@thaddy.com tha...@thaddy.com wrote: What I was a little bit more than hinting at in my previous answers is that it is impossible for an abstract read stream to know that there's a string to read. There is at least one higher level of implementation

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread Gennady Agranov
Thanks! Your example does compile, but if you replace 31 with 32 - it will not compile - no matter what you use - integer, int64 or qword And I guess I know the reason now - sizeof(left) should be equal to sizeof(right) and 33 bits enum has sizeof of 5 :( Any suggestions? Thanks, Gennady On

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread Gennady Agranov
Thanks again! I am all set now - I needed {$PACKSET 4} :) Thanks, Gennady program setcast; {$ifdef FPC} {$mode delphi} {$PACKSET 4} {$else} {$APPTYPE CONSOLE} {$endif} uses SysUtils; type tenum=0..32; tmyset= set of tenum; var x:int64; y:tmyset; begin x:=int64(y);

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread Marco van de Voort
In our previous episode, Gennady Agranov said: Your example does compile, but if you replace 31 with 32 - it will not compile - no matter what you use - integer, int64 or qword But does that work in Delphi, did you test? And I guess I know the reason now - sizeof(left) should be equal to

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread Gennady Agranov
But does that work in Delphi, did you test? You are correct - Delphi also requires that source and target are of same size - thanks! I finally figured why existing Delphi code was not compiling - I did not use {$mode delphi} in the unit - i did not want to add {$mode dlephi} to every

Re: [fpc-devel] How to convert set to integer and vice versay

2014-07-22 Thread Sven Barth
On 23.07.2014 05:54, Gennady Agranov wrote: And I know why - if you have {$mode delphi} - sizeof(tmyset) is 8, but if you do not (and use -Mdelphi) sizeof(tmyset) is 32 Do you know why -Mdelphi is different from {$mode delphi} w.r.t to sizeof(tmyset)? This should not be the case. Please