Recent

Author Topic: case error  (Read 11708 times)

rigel

  • New Member
  • *
  • Posts: 29
case error
« 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?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: case error
« Reply #1 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.

malcome

  • Jr. Member
  • **
  • Posts: 80
Re: case error
« Reply #2 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?
« Last Edit: May 12, 2009, 12:08:34 pm by malcome »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: case error
« Reply #3 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.

rigel

  • New Member
  • *
  • Posts: 29
Re: case error
« Reply #4 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.

rigel

  • New Member
  • *
  • Posts: 29
Re: case error
« Reply #5 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.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: case error
« Reply #6 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;

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: case error
« Reply #7 on: May 13, 2009, 10:27:49 am »
Seems like a nice class, Theo. You should do some advertisement on Lazarus-CCR.

rigel

  • New Member
  • *
  • Posts: 29
Re: case error
« Reply #8 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.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: case error
« Reply #9 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