unit U_Data;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TArByte =
array of Byte;
TDataType = (dtNone, dtBool, dtByte, dtChar, dtString, dtInteger, dtReal);
TData =
class
private
_Data, _TempData : TArByte;
_MaxSize, _RealSize: Integer;
_DataType : TDataType;
_DataUsed : Boolean;
public
property MaxSize: Integer
read _MaxSize;
property RealSize: Integer
read _RealSize;
property DataType: TDataType
read _DataType;
property DataUsed: Boolean
read _DataUsed;
constructor Create(MaxSize : Integer; DataType : TDataType);
destructor Destroy;
override;
procedure Input(Data : TArByte; DataSize : Integer);
procedure Output(
var Data : TArByte);
//---
procedure InputBool(B : Boolean);
function OutputBool : Boolean;
procedure InputInt(I : Integer);
function OutputInt : Integer;
procedure InputStr(S :
String);
function OutputStr :
String;
end;
implementation
constructor TData.Create(MaxSize : Integer; DataType : TDataType);
begin
_MaxSize := MaxSize;
_DataType := DataType;
_DataUsed := False;
end;
destructor TData.Destroy;
begin
FreeMem(_Data);
end;
procedure TData.Input(Data : TArByte; DataSize : Integer);
begin
if RealSize <= _MaxSize
then
begin
if DataUsed
then
FreeMem(_Data)
else
_DataUsed := true;
_RealSize := DataSize;
Move(Data, _Data, DataSize);
end
else
ShowMessage('
Speicherplatz überschritten!');
end;
procedure TData.Output(
var Data : TArByte);
var
I : Integer;
begin
//For I := 0 to _RealSize - 1 do
//Data[I] := _Data[I];
Move(_Data, Data, _RealSize)
end;
//---
procedure TData.InputBool(B : Boolean);
begin
end;
function TData.OutputBool : Boolean;
begin
end;
procedure TData.InputInt(I : Integer);
begin
end;
function TData.OutputInt : Integer;
begin
end;
procedure TData.InputStr(S :
String);
var
I,Len : Integer;
begin
len := length(S);
SetLength(_TempData, len);
for I := 0
to len - 1
do
_TempData[I] := ord(S[I+1]);
Input(@_TempData[0], len);
end;
function TData.OutputStr :
String;
var
I : Integer;
S :
String;
begin
SetLength(_TempData, RealSize);
OutPut(_TempData);
for I := 0
to RealSize - 1
do
S := S + chr(_TempData[I]);
Result := S;
end;
end.