[fpc-pascal] Coercing record fields together
DaWorm
daworm at gmail.com
Mon Jul 9 18:56:23 CEST 2018
Just because someone is bound to suggest it, might as well be me.
type
TRecA = record
a: string;
b: string;
end;
type
TRecB = record
A: TRecA;
c: integer;
d: integer;
end;
RecB.A := RecA;
Jeff
On Mon, Jul 9, 2018, 12:23 PM Ryan Joseph <ryan at thealchemistguild.com>
wrote:
> Could I do some RTL magic on a record to loop over its fields and set them
> to another record by name? In the example below I want to set all the
> fields in TRecA to matching named fields in TRecB. Just curious if we can
> do this automatically using RTL.
>
> type
> TRecA = record
> a: string;
> b: string;
> end;
>
> type
> TRecB = record
> a: string;
> b: string;
> c: integer;
> d: integer;
> end;
>
>
> for field in recA.GetFields do
> recB.GetFieldByName(field.name).value := field.value
>
>
> Regards,
> Ryan Joseph
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180709/69ba1598/attachment.html>
More information about the fpc-pascal
mailing list