try sv := datap[row,col]; fv := StrToFloat(sv); Write(f, 'f = ', fv, ' '); flush(f); except on Exception : EConvertError do begin ShowMessage(Exception.Message); Write(f, 's = ', sv, ' '); end; end;
unit test_var_array;{$mode objfpc}{$H+}interfaceuses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs; type TForm1 = class(TForm) private { private declarations } public { public declarations } end; TDataArray = Array of Variant;var Form1: TForm1; data : array of TDataArray; row, col : integer;implementation{$R *.lfm}Procedure FillArray(var dataf : array of TDataArray);var num : integer; str : string;begin for row := 1 to 5 do for col := 1 to 5 do begin num := row + col; if (row Mod 2) = 0 then {even row store it as string} begin str := IntToStr(row) + IntToStr(col); dataf[row,col] := 'x' + str; end else dataf[row,col] := row + col/10; {odd row store it as float} end;end;Procedure PrintArray(var datap : array of TDataArray);var f : TextFile; sv : string; fv : real; vv : variant;begin Assign(f, 'C:\Test_Variant_array.txt'); Rewrite(f); for row := 1 to 5 do begin for col := 1 to 5 do begin try sv := datap[row,col]; fv := StrToFloat(sv); Write(f, 'f = ', fv, ' '); flush(f); except on Exception : EConvertError do begin ShowMessage(Exception.Message); Write(f, 's = ', sv, ' '); end; end; end; WriteLn(f,''); end; CloseFile(f);end;begin SetLength(data, 6,6); FillArray(data); PrintArray(data);end.
I can read the float values but when i try to read a string i get the EConvertError x21 is an invalid float.
I thought that the on exception would handle this.
under environment - options - Debugger - Language Exceptions i had EconvertERROR checked but it still did not work.waw that what you meant?