Dynamic variable names: Difference between revisions
Content added Content deleted
m (→FreePascal) |
m (→FreePascal) |
||
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 |
|||
SetType := StrToFloat ( strVal ) ; |
SetType := StrToFloat ( strVal ) ; |
||
EXCEPT |
EXCEPT |
||
SetType := strVal ; |
SetType := strVal ; |
||
⚫ | |||
END; |
END; |
||
⚫ | |||
BEGIN |
BEGIN |
||
D := TDict.Create; |
D := TDict.Create; |
||
REPEAT |
|||
Write ( 'Enter variable name : ' ) ; |
|||
Write ( 'Enter variable name : ' ) ; |
|||
ReadLn ( VarName ) ; |
|||
Write ( 'Enter variable Value : ' ) ; |
|||
ReadLn ( strValue ) ; |
|||
VarValue := SetType ( strValue ) ; |
|||
⚫ | |||
write('3'); |
|||
⚫ | |||
⚫ | |||
BEGIN |
|||
D.AddOrSetValue ( VarName, VarValue ) ; |
|||
Write ( VarName ) ; |
|||
Write ( ' = ' ) ; |
|||
⚫ | |||
⚫ | |||
EXCEPT |
|||
WriteLn ( 'Something went wrong.. Try again' ) ; |
|||
END; |
END; |
||
UNTIL ( strValue = '' ) ; |
|||
FINALLY |
|||
D.Free; |
|||
⚫ | |||
END. |
END. |
||
</lang>JGAD 2021/05/13 |
</lang>JGAD 2021/05/13 |