Dynamic variable names: Difference between revisions

Content deleted Content added
JPD (talk | contribs)
JPD (talk | contribs)
Line 903:
<lang Pascal>
PROGRAM ExDynVar;
 
{$mode objfpc}{$H+}{$J-}{R+}
 
(*
* Free Pascal Compiler version 3.2.0 [2020/06/14] for x86_64
Line 912 ⟶ 914:
* dynamic variables at runtime.
*)
 
USES
 
Generics.Collections,
SysUtils,
Line 918 ⟶ 922:
 
TYPE
 
Tdict = specialize TDictionary <string ansistring, variant > ;
 
VAR
VarName: stringansistring;
strValue: stringansistring;
VarValue: variant;
D: Tdict;
 
FUNCTION SetType ( strVal: stringansistring ): variant;
(* If the value is numeric, store it as numeric, otherwise store it as stringansistring *)
BEGIN
TRY
SetType := StrToFloat ( strVal ) ;
EXCEPT
SetType := strVal ;
END;
END;
Line 943 ⟶ 948:
Write ( 'Enter variable Value : ' ) ;
ReadLn ( strValue ) ;
VarValue := SetType ( strValue ) ;
TRY
BEGIN