Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: reversstr in firemoneky



Permlink Replies: 7 - Last Post: Jan 7, 2017 5:29 PM Last Post By: Eli M
kareena charette

Posts: 8
Registered: 2/1/17
reversstr in firemoneky
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 2:52 AM
Hello
how to make this code work on firemonkey ios and android?
function ReverseStr(const Str: string): string;
var
i, Len: Integer;
begin
Len := Length(Str);
SetLength(Result, Len);
for i := 1 to Len do
Result[i] := Str[Succ(Len-i)];
end;

it work fine on windows but on ios does not work
on delphi berlin 1.1 upd 2
Thank you
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: reversstr in firemoneky [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 4:46 AM   in response to: kareena charette in response to: kareena charette
kareena charette wrote:

Hello
how to make this code work on firemonkey ios and android?
function ReverseStr(const Str: string): string;
var
i, Len: Integer;
begin
Len := Length(Str);
SetLength(Result, Len);
for i := 1 to Len do
Result[i] := Str[Succ(Len-i)];
end;

it work fine on windows but on ios does not work
on delphi berlin 1.1 upd 2
Thank you

This is once again like in your previous post zero based strings. You
should really consider to use the proper group for your question. This
group is about the FireMonkey cross platform graphical library and not
about string handling.

You can rewrite your code for example as:

function ReverseStr(const Str: string): string;
var
  i: integer;
  sb: TStringBuilder;
begin
  sb := TStringBuilder.Create('');
  try
    for i := High(str) downto Low(str) do
      sb.append(str[i]);
    result := sb.ToString;
  finally
    sb.Free;
  end;
end;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: reversstr in firemoneky [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 9:50 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos wrote:

sb := TStringBuilder.Create('');

I would suggest changing that line to this instead:

sb := TStringBuilder.Create(Length(str));


Your code causes the TStringBuilder to reallocate memory, potentially many
times, while appending new characters. By specifying an initial capacity
up front, the memory is allocated only one time.

--
Remy Lebeau (TeamB)
Sebastian Zierer

Posts: 182
Registered: 4/3/00
Re: reversstr in firemoneky
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 4:59 AM   in response to: kareena charette in response to: kareena charette
kareena charette wrote:
how to make this code work on firemonkey ios and android?
function ReverseStr(const Str: string): string;

Take a look at the ReverseString function in System.StrUtils.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: reversstr in firemoneky
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 7:33 AM   in response to: kareena charette in response to: kareena charette
kareena charette

Posts: 8
Registered: 2/1/17
Re: reversstr in firemoneky
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 11:24 AM   in response to: kareena charette in response to: kareena charette
thank you very much
if there any tutorial for multiplatforms developpement ? tutorial for beginner
that explains all fonction and procedure with code example?
Regards
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: reversstr in firemoneky
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 6, 2017 11:25 PM   in response to: kareena charette in response to: kareena charette
Am 06.01.2017 um 20:24 schrieb kareena charette:
thank you very much
if there any tutorial for multiplatforms developpement ? tutorial for beginner
that explains all fonction and procedure with code example?
Regards

Hello,

what do you mean with "all functions"?
Delphi contains so much stuff nowadays that describing all of it would
probably fill a whole book shelf.

As for your string type questions: they'd be suited for the RTL group
instead of the Firemonkey one. And for operating system specific
questions there are separate groups as well.

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02