Dynamic variable names: Difference between revisions

Content added Content deleted
Line 926: Line 926:
D: Tdict;
D: Tdict;


FUNCTION SetType ( strVal: string ): variant;
FUNCTION SetType ( strVal: string ): variant;
(* If the value is numeric, store it as numeric, otherwise store it as string *)
(* If the value is numeric, store it as numeric, otherwise store it as string *)
BEGIN
BEGIN
Try
TRY
SetType := StrToFloat ( strVal ) ;
SetType := StrToFloat ( strVal ) ;
EXCEPT
EXCEPT
SetType := strVal ;
SetType := strVal ;
END;
END;
END;
END;


BEGIN
BEGIN
D := TDict.Create;
D := TDict.Create;
REPEAT
Write ( 'Enter variable name : ' ) ;
ReadLn ( VarName ) ;
Write ( 'Enter variable name : ' ) ;
Write ( 'Enter variable Value : ' ) ;
ReadLn ( VarName ) ;
ReadLn ( strValue ) ;
Write ( 'Enter variable Value : ' ) ;
VarValue := SetType ( strValue ) ;
ReadLn ( strValue ) ;
VarValue := SetType ( strValue ) ;
TRY
BEGIN
write('3');
TRY
D.Add ( VarName, VarValue ) ;
Write ( VarName ) ;
BEGIN
Write ( ' = ' ) ;
D.AddOrSetValue ( VarName, VarValue ) ;
WriteLn ( D [ VarName ] ) ;
Write ( VarName ) ;
Write ( ' = ' ) ;
WriteLn ( D [ VarName ] ) ;
END;
EXCEPT
WriteLn ( 'Something went wrong.. Try again' ) ;
END;
END;
UNTIL ( strValue = '' ) ;
FINALLY
D.Free;
D.Free;
END;
END.
END.
</lang>JGAD 2021/05/13
</lang>JGAD 2021/05/13