3

I was wondering if there is a way to make an array which would have multiple types of data fields.

So far I was using aMyArray: array of array [0..1] of TPoint;

But now, it is not enough for me. I need to add 3 more elements to the existing 2 "Point" elements making it an array like aMyArray: array of (TPoint,TPoint,real,real,real)

So each element of aMyArray would have 5 'children', 2 of which are of a TPoint type and 3 of them are 'real' type.

Is this possible to implement somehow?

4 Answers 4

13

Maybe a record like

TMyType = record
  Points: array[0..1] of TPoint;
  Floats: array[0..2] of Real;
end;

or

TMyType = record
  Point0: TPoint;
  Point1: TPoint;
  Float0: Real;
  Float1: Real;
  Float2: Real;
end;

works for you.

Sign up to request clarification or add additional context in comments.

2 Comments

+1. Structures with fixed numbers of elements with heterogeneous types are exactly what records are for.
A significant clue being that TPoint itself is a record.
0

You can use an array of Variants to store different data in each element. But array were designed to store homogenous data. If your data storage requirements are more complex, start to look for different containers.

1 Comment

Variants can't hold records like TPoint.
0

I would use a TStringList or decendant, with AddObject.

1 Comment

Really? Could you demonstrate that, please?
0

You may also want to use variant records. For an example see this

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.