1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Converting Char to String and String to Char for the Android platform

Discussion in 'Delphi Programming' started by delphiy, Oct 31, 2015.

  1. delphiy
    Offline

    delphiy DF Member

    Hello everyone!
    I was wondering if someone can help. I wrote the following code:Code:
    PHP:
    procedure TForm4.FormCreate(SenderTObject);
    Var
     
    StringInputVariable String;
     
    CharVariable Char;
     
    StringOutputVariable String;
    begin
     StringInputVariable 
    := 'w';

     
    CharVariable := Char(StringInputVariable[1]);

     
    StringOutputVariable := String(CharVariable);

     
    Label1.Text := StringOutputVariable;
    end;
    When I Run for the Android platform I get absolutely no output in Label1 - I was expecting a 'w' in Label1.Text. The program compiles without any errors. When I compile for 32 - bit Windows I get a 'w' in Label1.Text as expected. My program basically takes a one character string input, then converts it to char, then converts it back to string and then writes this string on the screen as Label1. Why does this not work for the Android platform and how can I do workable conversions?
     
  2. drakeblood2
    Online

    drakeblood2 Guest

  3. Dergen
    Offline

    Dergen DF Member

    It's because StringInputVariable[1] should be StringInputVariable[0]

    Strings are zero based in Delphi Android and one based in Delphi Windows.
     
     
  4. mario.joker
    Offline

    mario.joker DF Junior

  5. vallemanden
    Offline

    vallemanden DF Junior

    useful post 
     
  6. nnlscxlm
    Offline

    nnlscxlm DF Member

    If you want to have same source code for both 1-based and 0-based strings (mobile platforms) you can use Low(StringVariable):

    CharVariable := StringVariable[Low(StringVariable)];

     
     
  7. hugorn
    Online

    hugorn Guest

    nice post
     

Share This Page