[fpc-pascal] Re: How can you convert an enum value to string?

2010-09-12 Thread Frank Church
On 30 August 2010 11:30, Frank Church  wrote:

> Is there a subroutine that can convert an enum value to a strings, so that
> I can do something like ShowMessage(EnumToStr(enumValue))?
>
> --
>
program testnums;
//{$APPTYPE CONSOLE}


uses
  Classes, SysUtils;
type
   stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
location Type

var
 d : stType;
 s : string;
 i : integer;
begin

 d:= stLite;
 writestr(s,d);
 writeln(s + ' ' + IntToStr(Integer(d)));

 d:= stDb;
 writestr(s,d);
 writeln(s + ' ' + IntToStr(Integer(d)));

 d:= stBothLite;
 writestr(s,d);
 writeln(s + ' ' + IntToStr(Integer(d)));

 d:= stBothDB;
 writestr(s,d);
 writeln(s + ' ' + IntToStr(Integer(d)));

 readln;
end.

This is the code I created, as enums are stored as integers, or  QWORDs,
what is the default way of displaying the integer value of an enum.


Frank Church
>
> ===
> http://devblog.brahmancreations.com
>



-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Question mark?

2010-09-12 Thread Jonas Maebe

On 11 Sep 2010, at 20:54, Luis Fernando Del Aguila Mejía wrote:

> That is, When I use readln, then the Widestring manager use the charset of
> the command interpreter (cmd 850), and when I use writeln, then the
> Widestring manager, use the charset of the Operating System (ANSI-1252).
> (only windows)
> 
> Am I right, or am I wrong?

I don't know the details of how it works under Windows.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Question mark?

2010-09-12 Thread Marco van de Voort
In our previous episode, Jonas Maebe said:
> On 11 Sep 2010, at 20:54, Luis Fernando Del Aguila Mej?a wrote:
> 
> > That is, When I use readln, then the Widestring manager use the charset of
> > the command interpreter (cmd 850), and when I use writeln, then the
> > Widestring manager, use the charset of the Operating System (ANSI-1252).
> > (only windows)
> > 
> > Am I right, or am I wrong?
> 
> I don't know the details of how it works under Windows.

More or less yes. The cmdline interpreter uses a different (labelled OEM,
generally more doslike) charset, then the Windows system charset
(Windows-xx, refered to in windows api as "ANSI")

Searching for OEM in Mantis yields some of the known problems with this,
namely 14467,15233,16064.  Our current model does not properly model this as
far as I can see.

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


[fpc-pascal] What is wrong with this enum and array related code

2010-09-12 Thread Frank Church
program testnums;
//{$APPTYPE CONSOLE}

uses
  Classes, SysUtils;
type
   stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
location Type
   stTypes = Array [stType] of integer;
var
 d : stType;
 s : string;
 i : integer;
begin
 writeln('');
 for i := Ord(low(stType)) to Ord(high(stType)) do
 begin
  d := stTypes[i - Ord(low(stType))];
   writestr(s,d);
   writeln(d + ' ' + IntToStr(Integer(i)));
 end;
 readln;

end.

-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Re: What is wrong with this enum and array related code

2010-09-12 Thread Frank Church
I need to elaborate more on this code

On this line

d := stTypes[i - Ord(low(stType))];

since stTypes is an array, I expect stTypes[n], with n being 1 to 4,  to
retrieve an array value and as 'i - Ord(low(stType)) evaluates to integer it
should compile but it generates an error.

What would be the correct way?

On 12 September 2010 12:51, Frank Church  wrote:

> program testnums;
> //{$APPTYPE CONSOLE}
>
> uses
>   Classes, SysUtils;
> type
>stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
> location Type
>stTypes = Array [stType] of integer;
> var
>  d : stType;
>  s : string;
>  i : integer;
> begin
>  writeln('');
>  for i := Ord(low(stType)) to Ord(high(stType)) do
>  begin
>   d := stTypes[i - Ord(low(stType))];
>writestr(s,d);
>writeln(d + ' ' + IntToStr(Integer(i)));
>  end;
>  readln;
>
> end.
>
> --
> Frank Church
>
> ===
> http://devblog.brahmancreations.com
>



-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What is wrong with this enum and array related code

2010-09-12 Thread Vincent Snijders
2010/9/12 Frank Church :
> program testnums;
> //{$APPTYPE CONSOLE}
>
> uses
>   Classes, SysUtils;
> type
>    stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
> location Type
>    stTypes = Array [stType] of integer;
> var
>  d : stType;
>  s : string;
>  i : integer;
> begin
>  writeln('');
>  for i := Ord(low(stType)) to Ord(high(stType)) do
>  begin
>   d := stTypes[i - Ord(low(stType))];
>    writestr(s,d);
>    writeln(d + ' ' + IntToStr(Integer(i)));
>  end;
>  readln;
>
> end.

I think the array and enum are correct, but the usage isn't. I did not
compile this code, but I expect a type mismatch error. You are using
an integer as index in d := stTypes[i - Ord(low(stType))], but you
declared stTypes an array to be indexed by stType.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: What is wrong with this enum and array related code

2010-09-12 Thread Vincent Snijders
2010/9/12 Frank Church :
> I need to elaborate more on this code
>
> On this line
>
> d := stTypes[i - Ord(low(stType))];
>
> since stTypes is an array, I expect stTypes[n], with n being 1 to 4,  to
> retrieve an array value and as 'i - Ord(low(stType)) evaluates to integer it
> should compile but it generates an error.
>
> What would be the correct way?
>
> On 12 September 2010 12:51, Frank Church  wrote:
>>
>> program testnums;
>> //{$APPTYPE CONSOLE}
>>
>> uses
>>   Classes, SysUtils;
>> type
>>    stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
>> location Type
>>    stTypes = Array [stType] of integer;
>> var
>>  d : stType;
>>  s : string;
>>  i : integer;

>> begin
>>  writeln('');
>>  for i := Ord(low(stType)) to Ord(high(stType)) do
for  d:= low(stType) to high(stType) do

>>  begin
>>   d := stTypes[i - Ord(low(stType))];
i := stTypes[d];
>>    writestr(s,d);
>>    writeln(d + ' ' + IntToStr(Integer(i)));
>>  end;
>>  readln;
>>
>> end.
>>
>> --
>> Frank Church
>>
>> ===
>> http://devblog.brahmancreations.com
>
>
>
> --
> Frank Church
>
> ===
> http://devblog.brahmancreations.com
>
> ___
> fpc-pascal maillist  -  fpc-pas...@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Fw: Question mark?

2010-09-12 Thread Luis Fernando Del Aguila Mejía

ok, I understand.

Excuse my ignorance. But what is mantis?
What routines of the Windows API, use the Widestring Manager in Windows?
Is there a guide to understanding the source of FPC?

Thank you.
Danke. 
___

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


Re: [fpc-pascal] Re: What is wrong with this enum and array related code

2010-09-12 Thread Frank Church
On 12 September 2010 13:05, Vincent Snijders wrote:

> 2010/9/12 Frank Church :
> > I need to elaborate more on this code
> >
> > On this line
> >
> > d := stTypes[i - Ord(low(stType))];
> >
> > since stTypes is an array, I expect stTypes[n], with n being 1 to 4,  to
> > retrieve an array value and as 'i - Ord(low(stType)) evaluates to integer
> it
> > should compile but it generates an error.
> >
> > What would be the correct way?
> >
> > On 12 September 2010 12:51, Frank Church  wrote:
> >>
> >> program testnums;
> >> //{$APPTYPE CONSOLE}
> >>
> >> uses
> >>   Classes, SysUtils;
> >> type
> >>stType = (stLite := -100, stDb, stBothLite, stBothDb); //settings
> >> location Type
> >>stTypes = Array [stType] of integer;
> >> var
> >>  d : stType;
> >>  s : string;
> >>  i : integer;
>
> >> begin
> >>  writeln('');
> >>  for i := Ord(low(stType)) to Ord(high(stType)) do
> for  d:= low(stType) to high(stType) do
>
> >>  begin
> >>   d := stTypes[i - Ord(low(stType))];
> i := stTypes[d];
> >>writestr(s,d);
> >>writeln(d + ' ' + IntToStr(Integer(i)));
> >>  end;
> >>  readln;
> >>
> >> end.
> >>
> >> --
> >> Frank Church
> >>
> >> ===
> >> http://devblog.brahmancreations.com
> >
> >
> >
>

Does that mean that although an enum is an ordinal type, an integer cannot
be coerced into using it to index an array?



> > --
> > Frank Church
> >
> > ===
> > http://devblog.brahmancreations.com
> >
> > ___
> > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Re: What is wrong with this enum and array related code

2010-09-12 Thread Honza
2010/9/12 Frank Church :
> Does that mean that although an enum is an ordinal type, an integer cannot
> be coerced into using it to index an array?

IMO just cast it to the correct type (of the array index) giving the
compiler a chance to accept it.

-- 
bflm
freepascal-bits.blogspot.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] How to download fpc242 rc1 (to test a possible bug)

2010-09-12 Thread Luiz Americo Pereira Camara

Hi,

I noticed that there's a folder for fpc242 rc1 in 
ftp://ftp.freepascal.org/pub/fpc/beta/


Trying to access gives an error 550

The reason to get the 242 version is to test an bug reported by a user 
of the fpc243 snapshot provided at http://www.hu.freepascal.org/lazarus/


Basically it would not compile the attached file

Luiz
program testGeneric;

{$Mode ObjFpc}
{$H+}

uses 
  Fgl;
  
type
  TIntegerList = specialize TFPGList ;
  
var
  List: TIntegerList;
  i, j: Integer;
begin
  List := TIntegerList.Create;
  i := 1;
  List.Add(i);
  i := 2;
  List.Add(i);
  for j := 0 to List.Count - 1 do
WriteLn(List[j]);
  List.Delete(0);
  for j := 0 to List.Count - 1 do
WriteLn(List[j]);
  List.Destroy; 
end. ___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How to download fpc242 rc1 (to test a possible bug)

2010-09-12 Thread Marco van de Voort
In our previous episode, Luiz Americo Pereira Camara said:
> I noticed that there's a folder for fpc242 rc1 in 
> ftp://ftp.freepascal.org/pub/fpc/beta/
> 
> Trying to access gives an error 550
> 
> The reason to get the 242 version is to test an bug reported by a user 
> of the fpc243 snapshot provided at http://www.hu.freepascal.org/lazarus/

242 branched of in may. So unless it is a recent regression in the 2.4.x
family, it will behave the same.
 
> Basically it would not compile the attached file

And it did compile with 2.4.0?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to download fpc242 rc1 (to test a possible bug)

2010-09-12 Thread Luiz Americo Pereira Camara

Marco van de Voort escreveu:

In our previous episode, Luiz Americo Pereira Camara said:
  
I noticed that there's a folder for fpc242 rc1 in 
ftp://ftp.freepascal.org/pub/fpc/beta/


Trying to access gives an error 550

The reason to get the 242 version is to test an bug reported by a user 
of the fpc243 snapshot provided at http://www.hu.freepascal.org/lazarus/



242 branched of in may. So unless it is a recent regression in the 2.4.x
family, it will behave the same.
 
  

Basically it would not compile the attached file



And it did compile with 2.4.0?
  


Yes. Also with 251

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


Re: [fpc-pascal] How to download fpc242 rc1 (to test a possible bug)

2010-09-12 Thread Marco van de Voort
In our previous episode, Luiz Americo Pereira Camara said:
> >
> > And it did compile with 2.4.0?
> 
> Yes. Also with 251

Hmm, I think I know what that is. A wrong merge that should have been
reverted.

http://bugs.freepascal.org/view.php?id=16121

I'll see if I can squeeze that in.

The 2.5.1 breakage is a different question though.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal