Lazarus

Programming => Packages and Libraries => Ported from Delphi/Kylix => Topic started by: rigel on May 12, 2009, 10:41:48 am

Title: case error
Post by: rigel on May 12, 2009, 10:41:48 am
Hello,

I have very simple program on Delphi 7 and want to convert it to Lazarus. There is a problem when using case. Down is example:

Code: [Select]
var
  stInp: String;
  stOut: String;
  i: integer;
begin
  stOut := '';
  stInp := Memo1.Lines.Text;
  for i := 1 to length(stInp) do
  Begin
     case stInp[i] of
      'а': Begin stOut := stOut + 'a'; End;

Compilator stops after 'a' and say:
MAIN.PAS(243,11) Error: Constant and CASE types do not match
MAIN.PAS(243,11) Error: Ordinal expression expected

In Delphi 7 this work. How can I make it in Lazarus?
Title: Re: case error
Post by: Leledumbo on May 12, 2009, 11:00:26 am
Works fine here (2.3.1). What fpc version are you using? Please also post the whole procedure body.
Title: Re: case error
Post by: malcome on May 12, 2009, 12:05:09 pm
It seems that 'а' is "Full Width"(Called "ZENKAKU" in Japanese).
"Half Width"(Called "HANKAKU" in Japanese) correct?
Title: Re: case error
Post by: Vincent Snijders on May 12, 2009, 12:11:58 pm
I guess it must be a ascii character, not a widechar (or UTF8 string). So if the Half Width 'a' is equal to chr(97), then yes.
Title: Re: case error
Post by: rigel on May 13, 2009, 07:49:05 am
Works fine here (2.3.1). What fpc version are you using? Please also post the whole procedure body.
My fpc is 2.2.2, who is in Lazarus 0.9.26.2. Maybe I must wait next Lazarus and fpc. The procedure I write for test and is whole.
Title: Re: case error
Post by: rigel on May 13, 2009, 08:04:51 am
I guess it must be a ascii character, not a widechar (or UTF8 string). So if the Half Width 'a' is equal to chr(97), then yes.

'а' is a cyrillic ascii character, but fpc interpret it as constant and maybe here is a mistake. If I use latin 'a' is ok. How can I use other ascii character in case? Example with 'б' and 'b' is the same.
Title: Re: case error
Post by: theo on May 13, 2009, 10:06:18 am
How can I use other ascii character in case? Example with 'б' and 'b' is the same.

Afaik you can't.

Probably this might help you: http://www.theo.ch/lazarus/utf8tools.zip
Use it like this for your purpose (It's not the same but similar):

Code: [Select]
procedure TForm1.Button5Click(Sender: TObject);
var s: TUTF8Scanner;
begin
  s := TUTF8Scanner.Create(Memo1.text);
  s.FindChars := 'öäü';
  repeat
    case s.FindIndex(s.Next) of
  {ö} 0: s.Replace('oe');
  {ä} 1: s.Replace('ae');
  {ü} 2: s.Replace('ue');
    end;
  until s.Done;
  Memo1.Text := s.UTF8String;
  s.free;
end;
Title: Re: case error
Post by: Vincent Snijders on May 13, 2009, 10:27:49 am
Seems like a nice class, Theo. You should do some advertisement on Lazarus-CCR.
Title: Re: case error
Post by: rigel on May 13, 2009, 12:55:58 pm
How can I use other ascii character in case? Example with 'б' and 'b' is the same.

Afaik you can't.

Probably this might help you: http://www.theo.ch/lazarus/utf8tools.zip
Use it like this for your purpose (It's not the same but similar):

Code: [Select]
procedure TForm1.Button5Click(Sender: TObject);
var s: TUTF8Scanner;
begin
  s := TUTF8Scanner.Create(Memo1.text);
  s.FindChars := 'öäü';
  repeat
    case s.FindIndex(s.Next) of
  {ö} 0: s.Replace('oe');
  {ä} 1: s.Replace('ae');
  {ü} 2: s.Replace('ue');
    end;
  until s.Done;
  Memo1.Text := s.UTF8String;
  s.free;
end;

Thanks. I'll try.
Title: Re: case error
Post by: theo on July 09, 2009, 12:28:45 pm
Seems like a nice class, Theo. You should do some advertisement on Lazarus-CCR.

OK, it's a start: http://wiki.lazarus.freepascal.org/Theodp
TinyPortal © 2005-2018