unit Parsen;
interface
uses
Windows, SysUtils;
type
TMyDataEntry =
record
LfdNr: Integer;
Datum, Uhrzeit, Ereignis, Teilnehmer, Bereich :
String;
end;
TMyBaseParser =
class
private
Data:
String;
DataPointer: Integer;
function OemToAnsi(
const OemStr:
string):
string;
procedure SkipSpaces;
procedure SkipTrash;
function GetTextLength(UpToLineEnd: Boolean): Integer;
function ReadLine:
String;
public
Entries:
array of TMyDataEntry;
procedure Parse(Text:
String);
virtual;
abstract;
end;
TMyParserMB256plus =
class(TMyBaseParser)
private
public
procedure Parse(Text:
String);
override;
end;
var
Zähler : integer;
implementation
{ TMySimpleBaseParser }
function TMyBaseParser.OemToAnsi(
const OemStr:
string):
string;
begin
SetLength(Result, Length(OemStr));
if Length(Result) > 0
then
OemToCharBuff(PChar(OemStr), PChar(Result), Length(Result));
end;
procedure TMyBaseParser.SkipSpaces;
begin
while (DataPointer < Length(Data))
and (Data[DataPointer] = '
')
do
Inc(DataPointer);
end;
procedure TMyBaseParser.SkipTrash;
begin
while (DataPointer < Length(Data))
and (Data[DataPointer]
in [#13, #10, #32])
do
Inc(DataPointer);
end;
function TMyBaseParser.GetTextLength(UpToLineEnd: Boolean): Integer;
function IsTerminatingChar(CharIndex: Integer): Boolean;
begin
if UpToLineEnd
then
Result := Data[CharIndex]
in [#13, #10]
else
Result := Data[CharIndex]
in [#13, #10, #32];
end;
var
CurPointer: Integer;
begin
CurPointer := DataPointer;
while (CurPointer <= Length(Data))
and not IsTerminatingChar(CurPointer)
do
Inc(CurPointer);
Result := CurPointer - DataPointer;
end;
function TMyBaseParser.ReadLine:
String;
var
TextLen: Integer;
begin
TextLen := GetTextLength(True);
Result := Copy(Data, DataPointer, TextLen);
DataPointer := DataPointer + TextLen;
SkipTrash;
end;
{ TMyParserMB256plus }
procedure TMyParserMB256plus.Parse(Text:
String);
var
CurEntry : ^TMyDataEntry;
CurLine :
String;
TempDatum :
String;
Temp1 :
String;
Temp2 :
String;
begin
Data := Text;
DataPointer := 1;
SetLength(Entries, 0);
SkipTrash;
while DataPointer < Length(Data)
do
begin
SetLength(Entries, Length(Entries) + 1);
CurEntry := @Entries[High(Entries)];
{Indexbehandlungsroutine}
CurLine := ReadLine;
if Pos('
Ereignis:', CurLine) = 1
then
begin
Delete(CurLine, 1, 10);
CurEntry.LfdNr := StrToInt(CurLine);
CurLine := ReadLine;
end;
{Datum & Uhrzeitbehandlungsroutine}
if Pos('
Datum:', CurLine) = 1
then
begin
TempDatum := CurLine;
Delete(CurLine, 1, 7);
Delete(CurLine, 11, 19);
CurEntry.Datum := CurLine;
CurLine := TempDatum;
Delete(Curline,1, 28);
CurEntry.Uhrzeit := Curline;
{Ende Datumseintrag}
{Ereignisbehandlungsroutine}
CurEntry.Ereignis := ReadLine;
CurLine := ReadLine;
if Pos('
Hauptbereich:', CurLine) <> 1
then
begin
if Pos('
AP', CurLine)
or Pos('
IE', CurLine)
or Pos('
Makro', CurLine)
or Pos('
Modem', CurLine)= 1
then
begin
CurEntry.Teilnehmer := CurLine;
CurEntry.Bereich := ReadLine;
end;
end
else
begin
CurEntry.Bereich := CurLine;
end;
end;
end;
end;
end.