[fpc-pascal] Coercing record fields together

gabor gabor at poczta.onet.pl
Mon Jul 9 19:57:41 CEST 2018


Hi.
Probably can be done with RTTI (1), enumerators (2) and generics (3) 
together.

1. https://stackoverflow.com/questions/27803383/fpc-rtti-on-records
2. http://wiki.freepascal.org/for-in_loop#Traversing_container
3. http://wiki.freepascal.org/Generics

Michał.

W dniu 2018-07-09 o 18:22, Ryan Joseph pisze:
> 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
> 



More information about the fpc-pascal mailing list