I have a record type with methods, representing an specific hardware measurement type, read from the instrument as a string. The record contains implicit coversion to (and from) a string. If I cast a string as a record type, it seems to work, but is this safe? That is, does casting a string to a record with implicit string conversion call the implicit conversion as per assigning a temporary value?
var a: MeasurementRecord; // record type with implicit string conversion & decode methods
b: string;
c:double;
begin
b := Edit1.Text; // Or any other string source
a:=b; //Ok
a:= edit1.text; //Ok
c:= a.returnQc; // returns measurement quality value
c:= MeasurementRecord(Edit1.text).returnQC; //Avoiding local variable. This works, but is it correct useage?
end;
Yes, this is perfectly safe. The code
MeasurementRecord(Edit1.text)will create aMeasurementRecordrecord from the stringEdit1.Textusing yourand then call the function
returnQCin it. (However, if you also have athen this will be used instead since the cast is actually explicit.)