FGarcia,
Cita:
Empezado por FGarcia
...Verificar que el contenido de un String este dentro de cierto rango...solo tenga números, el carácter de espacio y el punto decimal...guardar un log...
|
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
const
Data : Array[1..5] of String = (' 123456789.0','#123456789.0',' 123456789,0','A123456789.0',' @23456789.0');
var
Form1: TForm1;
implementation
{$R *.dfm}
function CheckInput(Value : String) : Boolean;
var
i : Integer;
F : TextFile;
FileName : String;
begin
Result := True;
FileName := ExtractFilePath(Application.ExeName) + 'History.txt';
FileMode := fmOpenWrite or fmShareExclusive;
AssignFile(F, FileName);
if FileExists(FileName) then
Append(F)
else
Rewrite(F);
for i := 1 to Length(Value) do
if not (Value[i] in ['0'..'9',' ','.']) then
begin
WriteLn(F,FormatDateTime('yyyy/mm/dd hh:nn:ss',Now) + ' ' + Value);
Result := False;
Break;
end;
CloseFile(F);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
for i := Low(Data) to High(Data) do
CheckInput(Data[i]);
end;
end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32,
Realiza la verificación de un string y guarda un registro por cada caso de error en un archivo histórico, como se muestra en la siguiente imagen:
Espero sea útil
Nelson.