unit MyChkXML;
interface
uses SysUtils, WinTypes, WinProcs, Messages, Classes,Forms, Dialogs, ExtCtrls,
StdCtrls, Buttons,ggStringGrid,Grids ;
type
TCheck =
Record
Column:integer;
Rule:integer;
end;
TChecklist =
array of TCheck;
TMyChek =
class
private
MSG:TStringlist;
Checklist:TChecklist;
Grid:TStringGrid;
function Check(Checknumber:Integer):Boolean;
function MyChekGleich(Column:Integer):Boolean;
function MyChekInteger(Column:Integer):Boolean;
function MyChekFloat(Column:Integer) :Boolean;
public
procedure AddCheck(Column,Rulenumber);
function ExecuteCheck:Boolean;
function CheckResults:
String;
constructor create(AGrid:TStringGrid);
destructor destroy;
end;
implementation
constructor TMyChek.Create(AGrid:TStringGrid);
begin
inherited create;
Grid:=AGrid;
MSG:=TStringlist.create;
end;
desctructor TMyChek.Destroy();
begin
MSG.Free;
inherited;
end;
procedure TMyChek.AddCheck(Column,Rulenumber);
begin
SetLength(Checklist,Length(Checklist)+1);
Checklist[High(Checklist)].Column:=Column;
Checklist[High(Checklist)].Rule:=Rulenumber;
end;
function TMyChek.ExecuteCheck:Boolean;
var i:integer;
begin
Result:=true;
for i:=Low(Checklist)
to High(Checklist)
do
if not Check(i)
then
Result:=false;
end;
function TMyChek.Check(Checknumber):Boolean;
begin
if Checklist[i].Rule = 0
then
Result:=MyChekGleich(Checklist[i].Column)
else if Checklist[i].Rule = 1
then
Result:=MyChekInteger(Checklist[i].Column)
else if Checklist[i].Rule = 2
then
Result:=MyChekFloat(Checklist[i].Column)
else
Result:=true;
//Keine bekannte Regel, dann immer OK
end;
function TMyChek.MyChekInteger(Column:Integer):Boolean;
var i:Integer;
input:
String;
output:integer;
begin
Result:=true;
for i:=0
to Grid.Rows-1
do //Grid.Rows.Count-1 ???
begin
input:=Grid.Cells[Column,i];
if not TryStrToFloat(input,output)
then
begin
if Result
then
MSG.Add('
Spalte: '+IntToStr(Column)+'
, Regel: 1 (CheckInteger)')
MSG.Add('
Fehler in Reihe '+IntToStr(i)+'
: '+input)
Result:=false;
end;
end;
end;
function TMyChek.MyChekFloat(Column:Integer): Boolean;
begin
//Analog
end;
function TMyChek.MyChekGleich(Column:Integer):Booelean ;
begin
//Schon was schwieriger, aber solltest du auch hinkriegen.
end;
end.