interface
Uses Classes, SysUtils;
Type
TWorkWithParameter = class(TObject)
protected
Report: TStringList;
public
function StrListPresenceOfNames(s: String; Var x: String;
Const SList: TStringList): Boolean;
procedure StrListToNumber(s: String; Var x: Real;
Const SList: TStringList); overload;
procedure StrListToNumber(s: String; Var x: Word;
Const SList: TStringList); overload;
procedure StrListToNumber(s: String; Var x: Integer;
Const SList: TStringList); overload;
procedure StrListToNumber(s: String; Var x: Longword;
Const SList: TStringList); overload;
procedure StrListToFunctiya(s: String; Var x: String;
Const SList: TStringList);
constructor CreateWithReport(Var Protokol: TStringList);
constructor Create;
procedure FreeWithReport;
procedure Free;
function TakeOutError: TStringList;
End;
implementation
constructor TWorkWithParameter.CreateWithReport(Var Protokol: TStringList);
Begin
inherited Create;
Report := Protokol;
End;
constructor TWorkWithParameter.Create;
Begin
inherited Create;
Report := TStringList.Create;
End;
procedure TWorkWithParameter.Free;
Begin
Report.Free;
inherited Free;
End;
procedure TWorkWithParameter.FreeWithReport;
Begin
inherited;
End;
function TWorkWithParameter.TakeOutError: TStringList;
Begin
TakeOutError := Report;
End;
function TWorkWithParameter.StrListPresenceOfNames(s: String; Var x: String;
Const SList: TStringList): Boolean;
Var i: Integer;
Begin
i := SList.IndexOfName(s);
if i >= 0 then Begin
x := SList.ValueFromIndex[i];
if x <> '' then Begin
StrListPresenceOfNames := True; Exit; end
else Report.Add('Значение параметра "' + s + '" отсутствует');
end
else Report.Add('Параметр "' + s + '" отсутсвует');
StrListPresenceOfNames := False;
End;
procedure TWorkWithParameter.StrListToNumber(s: String; Var x: Word;
Const SList: TStringList);
Var i: Integer;
SNumber: String;
Label ErrorInCheslo;
Begin
if not StrListPresenceOfNames(s, SNumber, SList) then Exit;
for i := 1 to Length(SNumber) do
case SNumber[i] of
'+': if (i <> 1)or(Length(SNumber) = 1) then goto ErrorInCheslo;
'0'..'9': ;
else goto ErrorInCheslo;
end;
ErrorInCheslo: if i <= Length(SNumber) then
Report.Add('Ошибка записи "' + s + '"')
else x := StrToInt(SNumber);
End;
procedure TWorkWithParameter.StrListToNumber(s: String; Var x: Integer;
Const SList: TStringList);
Var i: Integer;
SNumber: String;
Label ErrorInCheslo;
Begin
if not StrListPresenceOfNames(s, SNumber, SList) then Exit;
for i := 1 to Length(SNumber) do
case SNumber[i] of
'+', '-': if (i <> 1)or(Length(SNumber) = 1) then goto ErrorInCheslo;
'0'..'9': ;
else goto ErrorInCheslo;
end;
ErrorInCheslo: if i <= Length(SNumber) then
Report.Add('Ошибка записи "' + s + '"')
else x := StrToInt(SNumber);
End;
procedure TWorkWithParameter.StrListToNumber(s: String; Var x: Longword;
Const SList: TStringList);
Var i: Integer;
SNumber: String;
Label ErrorInCheslo;
Begin
if not StrListPresenceOfNames(s, SNumber, SList) then Exit;
for i := 1 to Length(SNumber) do
case SNumber[i] of
'+': if (i <> 1)or(Length(SNumber) = 1) then goto ErrorInCheslo;
'0'..'9': ;
else goto ErrorInCheslo;
end;
ErrorInCheslo: if i <= Length(SNumber) then
Report.Add('Ошибка записи "' + s + '"')
else x := StrToInt(SNumber);
End;
procedure TWorkWithParameter.StrListToNumber(s: String; Var x: Real;
Const SList: TStringList);
Var i, j: integer;
SNumber: string;
tochka, stepen: boolean;
Label ErrorInCheslo;
Begin
if not StrListPresenceOfNames(s, SNumber, SList) then Exit;
tochka := False;
stepen := False;
for i := 1 to Length(SNumber) do
case SNumber[i] of
'+','-': if ((not stepen and (i <> 1))or(Length(SNumber) = 1))or(stepen and (j+1 <> i))
then goto ErrorInCheslo;
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.