Re: [fpc-pascal] EnumToString

2011-11-01 Thread Yann Bat
You can directly write enums with Write or WriteLn and convert enums to strings with WriteStr. program EnumStr; {$mode objfpc}{$H+} type TColor = (cRed, cGreen, cBlue, cYellow); function ColorToStr(C: TColor) : String; begin WriteStr(Result, C); end; var Color : TColor; begin for Color

Re: [fpc-pascal] 2 bugs ???

2011-09-07 Thread Yann Bat
2011/9/7 Leonardo M. Ramé : > From: Yann Bat > > > The error message is correct, because inside the scope of method  Bug, _T > points to nil, and the size of nil is 0, so 1 div 0 raises the error. > I think that SizeOf(_T) should be unknown rather than 0. The compiler s

Re: [fpc-pascal] 2 bugs ???Q

2011-09-07 Thread Yann Bat
Thanks. You've just found bug number 3 ! :-) But #1 and #2 are alway here. 2011/9/7 Marco van de Voort : > In our previous episode, Yann Bat said: >> I am trying to learn freepascal generics and I think that I have found 2 >> bugs. > >> var >>   V:

[fpc-pascal] 2 bugs ???

2011-09-07 Thread Yann Bat
Hi, I am trying to learn freepascal generics and I think that I have found 2 bugs. Tested with FPC 2.4.4 Linux x86 == = BUG 1 - with SizeOf = == program SizeOfBug; {$mode objfpc}{$H+} type generic TGen<_T> = class(TObject) private FField: _T; publ

Re: [fpc-pascal] Length bug ?

2010-10-11 Thread Yann Bat
2010/10/11 Michael Van Canneyt : > > Please enter a bug report for this. > Done. http://mantis.freepascal.org/view.php?id=17604 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Length bug ?

2010-10-11 Thread Yann Bat
Hi, I think I have found a bug in FPC 2.4.0. Tested under Windows XP 32 bits and Linux 32 bits. program TestLength; begin WriteLn('L =', Length('') ); end. This program gives L = 1 but I think it should give L = 0. Is this really a bug ? Can you reproduce this ? Thanks __

Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-28 Thread Yann Bat
> It is allowed in Delphi and TP because they allow declaring typed constants > of objects. Exactly what I wanted to use. I'll have to use constructors so. Thank you for your help. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://list

Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Yann Bat
> The compiler always adds a VMT if an object has a constructor or destructor. > The reason is that the VMT also contains the instance size, which is used by > the constructor helper to allocate the required amount of memory. > Ok but why a different behaviour between [fpc | objfpc] mode and [tp

[fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Yann Bat
Hi, I don't understand why compilation of the program below failed in fpc and objfpc mode. In tp and delphi mode it works as expected but in fpc and objfpc mode the compiler complains : blob.pas(17,3) Error: Constants of objects containing a VMT aren't allowed blob.pas(17,3) Fatal: Syntax err

[fpc-pascal] Re: Memory allocation problem

2010-02-26 Thread Yann Bat
Please forgot my stupid question. GetMem works perfectly as described in the documentation. My problem cames from an another part of my program. Yann ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinf

[fpc-pascal] Memory allocation problem

2010-02-26 Thread Yann Bat
Hi, I'm looking for a function or a procedure that tries to allocate memory and return nil on failure. GetMem seems to be a good candidate but it doesn't works as expected. The FreePascal documentations (http://www.freepascal.org/docs-html/rtl/system/getmem.html) tells that it returns nil on fail