Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:59:45+00:00 2026-05-25T16:59:45+00:00

Say I have two arrays of string, named ‘arrayone’ and ‘arraytwo’ How would I

  • 0

Say I have two arrays of string, named ‘arrayone’ and ‘arraytwo’
How would I go about sorting the ‘arrayone’ alphabetically (from A to Z), while still keeping relations to my second array.

Incase you were wondering what is in ‘arrayone’ and ‘arraytwo’, 1 has surnames and 2 has the ages of each person. My end result is to add it to a richedit.

Example of scenario:

Smith           25 
Appleseed       32
Gibbs           45

Must turn into:

Appleseed       32
Gibbs           45
Smith           25

Please no stringlist, keep it in simple array and in a procedure.

UPDATE: I switched to record.

Tried this code with no avail

for i := 0 to 26 do
for j := 0 to 26 do
  if recordname.surname[j] > recordname.surname[j+1] then begin
    line := recordname.surname[j];
    line[j] := recordname.surname[j+1];
    recordname.surname[j+1] := line;
  end;

It says Incompatible Types: ‘Char’ and ‘String’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:59:45+00:00Added an answer on May 25, 2026 at 4:59 pm

    Having given you advice about your data structure, and seen the ensuing struggles, I want to put things straight and explain more clearly what I mean.

    You original code had two arrays that were essentially unconnected. You could swap items in one array and easily forget to do so for the other array. It looks to me like the name/age pairs really should not be split apart. This leads to the following type declaration.

    type
      TPerson = record
        Name: string;
        Age: Integer;
      end;
    

    Now you need to hold an array of TPerson.

    type
      TPersonArray = array of TPerson;
    

    In order to perform a sort you need to be able to compare two items, and swap them.

    function Compare(const Person1, Person2: TPerson): Integer;
    begin
      Result := CompareText(Person1.Name, Person2.Name);
    end;
    
    procedure Swap(var Person1, Person2: TPerson);
    var
      temp: TPerson;
    begin
      temp := Person1;
      Person1 := Person2;
      Person2 := temp;
    end;
    

    Now we can put this all together with a bubble sort.

    procedure Sort(var People: TPersonArray);
    var
      i, n: Integer;
      Swapped: Boolean;
    begin
      n := Length(People);
      repeat
        Swapped := False;
        for i := 1 to n-1 do begin
          if Compare(People[i-1], People[i])>0 then begin
            Swap(People[i-1], People[i]);
            Swapped := True;
          end;
        end;
        dec(n);
      until not Swapped;
    end;
    

    Now, if you wanted to use a more complex comparison operator then you could simply replace Compare. For example, if you wanted to order by age any people that have the same name, then you use a lexicographic comparison function.

    function Compare(const Person1, Person2: TPerson): Integer;
    begin
      Result := CompareText(Person1.Name, Person2.Name);
      if Result=0 then begin
        Result := Person2.Age-Person1.Age;
      end;
    end;
    

    I have written this answer piece by piece and that is how you should approach a larger problem like this. Try to break it down in to smaller pieces, each of which is manageable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have these two arrays: string[] arr1 = new string[2]{Hello, Stack} string[]
Say I have two arrays, items and removeItems and I wanted any values found
Let's say I have two arrays: int ArrayA[] = {5, 17, 150, 230, 285};
Say I have two strings, String s1 = AbBaCca; String s2 = bac; I
Say I have two lists or arrays of strings. For example: list 1: a,
Lets say I have string like this: String q = foo (one) bla (two)
I have an issue how to implement to compare two static arrays, ie. string
Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
Say I have two tables I want to join. Categories: id name ---------- 1
Say I have two lists: var list1 = new int[] {1, 2, 3}; var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.