How to end a record that has passed through an untyped function parameter?

Can I pass any type of record to my procedure?

Many times I used "records" with strings.

type TR = record a: string; b: string; end; 

To clear them I need to write:

 Finalize(R); FillChar(R, SizeOf(R), #0); 

The question is, how do I transfer any records to clear it?

For this, I received this hint: "The expression does not require initialization / finalization."

 procedure ClearRecord(var R); begin Finalize(R); FillChar(R, SizeOf(R), #0); end; 

Thanks for every info!

+4
source share
1 answer

Do not make it too complicated. If you do not want to write a two-line document to clear the entry, consider the announcement:

 Const TR_Empty: TR = (); 

and use it:

 R := TR_Empty; 

And as commented by others, the general procedure for this is not worth the effort.

If you have Delphi-2009 or newer, this code is valid to clear the record:

 R := Default(TR); 
+11
source

Source: https://habr.com/ru/post/1433384/


All Articles