We help IT Professionals succeed at work.
Get Started

Is there a neat way to find the end of a record?

Aceelec
Aceelec asked
on
202 Views
Last Modified: 2012-05-05
Hey experts, quick question... difficult to ask but.

Is there any way to define a field of a record that takes up no space.  To illustrate why I'd need this I'll give an example:

I have a TMyRecord, which may or may not have a packet of data (TPacket) at the end of it.

Currently the only way I know of finding the location of this TPacket is

var
  MyRecord : TMyRecord
begin
  Packet := TPacket(Pointer(Cardinal(@MyRecord)+SizeOf(TMyRecord))^)
end;

which works but is very messy.  Where as I could define TMyRecord as this:

TMyRecord = record
  field1, field2, field3, field4 : integer;
  endofrecord : boolean;
end;

and replace the code with this:

var
  MyRecord : TMyRecord
begin
  Packet:= TPacket(@MyRecord.endofrecord)
end;

Which is a lot neater, yet wastes the space of a boolean for myrecords that are not followed by TPackets.  (A boolean, in a non-packed record is 8 bits... which is a bit of a waste imo).  So is there any way to put a field in a record that takes no memory/has no value?
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE