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

  • Home
  • SEARCH
  • 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 8350803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:26:06+00:00 2026-06-09T08:26:06+00:00

I have to translate some Fortran 90 code and found an interesting language feature.

  • 0

I have to translate some Fortran 90 code and found an interesting language feature.

As an example, they define the following type and dynamic-array variable:

TYPE WallInfo
  CHARACTER(len=40) :: Name
  REAL              :: Azimuth
  REAL              :: Tilt
  REAL              :: Area
  REAL              :: Height
END TYPE WallInfo

TYPE(WallInfo), ALLOCATABLE, DIMENSION(:) :: Wall

Later in the code, they call a function:

CALL HeatFlow(Wall%Area, Wall%Azimuth)

As a Delphi programmer, this threw me a bit because Wall is an array of records!

From the usage in the routine, it is clear that Fortran can project fields from the record array as an array of their own.

SUBROUTINE HeatFlow( Area, Azimuth )
  REAL, INTENT(IN), DIMENSION(:) :: Area
  REAL, INTENT(IN), DIMENSION(:) :: Azimuth

Does anyone know if there is a way to do this with Delphi (I’m using version 2010)?

I could write a function to extract a record value as an array but this is a bit tedious because I will have to write a dedicated routine for every field (and there are a quite a few).

I’m hoping that there is some language feature in Delphi 2010 that I have missed.

  • 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-06-09T08:26:07+00:00Added an answer on June 9, 2026 at 8:26 am

    Using Extended RTTI, it is possible to create a generic function that takes the array and a field name as input and uses the array’s RTTI to extract just the values of that field and create a new array with them, with the correct data type.

    The following code works for me in XE2:

    uses
      System.SysUtils, System.Rtti;
    
    type
      FieldArray<TArrElemType, TFieldType> = class
      public
        class function Extract(const Arr: TArray<TArrElemType>; const FieldName: String): TArray<TFieldType>;
      end;
    
    class function FieldArray<TArrElemType, TFieldType>.Extract(const Arr: TArray<TArrElemType>; const FieldName: String): TArray<TFieldType>;
    var
      Ctx: TRttiContext;
      LArrElemType: TRttiType;
      LField: TRttiField;
      LFieldType: TRttiType;
      I: Integer;
    begin
      Ctx := TRttiContext.Create;
      try
        LArrElemType := Ctx.GetType(TypeInfo(TArrElemType));
        LField := LArrElemType.GetField(FieldName);
        LFieldType := Ctx.GetType(TypeInfo(TFieldType));
        if LField.FieldType <> LFieldType then
          raise Exception.Create('Type mismatch');
        SetLength(Result, Length(Arr));
        for I := 0 to Length(Arr)-1 do
        begin
          Result[I] := LField.GetValue(@Arr[I]).AsType<TFieldType>;
        end;
      finally
        Ctx.Free;
      end;
    end;
    

    .

    type
      WallInfo = record
        Name: array[0..39] of Char;
        Azimuth: Real;
        Tilt: Real;
        Area: Real;
        Height: Real;
      end;
    
    procedure HeatFlow(const Area: TArray<Real>; const Azimuth: TArray<Real>);
    begin
      // Area contains (4, 9) an Azimuth contains (2, 7) as expected ...
    end;
    
    var
      Wall: TArray<WallInfo>;
    begin
      SetLength(Wall, 2);
    
      Wall[0].Name := '1';
      Wall[0].Azimuth := 2;
      Wall[0].Tilt := 3;
      Wall[0].Area := 4;
      Wall[0].Height := 5;
    
      Wall[1].Name := '6';
      Wall[1].Azimuth := 7;
      Wall[1].Tilt := 8;
      Wall[1].Area := 9;
      Wall[1].Height := 10;
    
      HeatFlow(
        FieldArray<WallInfo, Real>.Extract(Wall, 'Area'),
        FieldArray<WallInfo, Real>.Extract(Wall, 'Azimuth')
        );
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to translate some text with Google's translate service. All code I've found
I have some simple example WinForms code which I am trying to translate into
I have to translate some code from C# to Java and I have the
I have some query.i want to translate from one language to another langugae.i am
I have some jquery code which I am trying to translate to YUI. I
I need to translate some code from Scheme to Common Lisp. Now, I have
I have some Python code I'm trying to translate to Obj-C/Cocoa. It requires a
I am trying to translate some existing C++ code to C#. I have some
I have just added a google translate in website.And set the default language English.
We have a problem here. We need to translate a website into multiple language.

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.