MSTREAM

Top  Previous  Next

unit mStream;

 

interface

 

uses

SysUtils, WinTypes, WinProcs, Messages, Classes,

Graphics, Controls, Forms, Dialogs, stdctrls;

 

type

TStMemoryStream = class(TComponent)

private

  FRecCount : longint;

  FRecSize : longint;

  FRecnoLabel : TLabel;

  FReccountLabel : TLabel;

  FRecNo : longint;

  function GetRecCount: longint;

  function GetRecNo: longint;

  procedure SetRecSize(Value:longint);

  procedure SetRecNo(Value:longint);

  procedure SetRecNoLabel(Value:TLabel);

  procedure SetRecCountLabel(Value:TLabel);

  function GetMemory:Pointer;

protected

  copyStream : TMemoryStream;       {Tartalék stream másolásokhoz}

  procedure RecAction;

public

  TM : TMemoryStream;

  constructor Create(AOwner:TComponent);override;

  destructor Destroy;override;

  Procedure InsertRec(var Rec);

  Procedure DeleteRec(var Rec);

  Procedure NewRecCount(Rec_Count: longint);

  Function GetRec(var Rec) : boolean;

  Function WriteRec(var Rec) : boolean;

  Procedure GoTop;

  Procedure GoBottom;

  Function SkipN(No:longint) : boolean;

  Procedure GetRecN(No:longint;var Rec);

  Procedure WrireRecN(No:longint;var Rec);

  Procedure CutFromTo(FromNo,ToNo:longint);

  Procedure AddEmptyRec(var Rec);

  Procedure InsertEmptyRec(var Rec);

  Function MoveRec(FromNo,ToNo:longint) : boolean;

  Function ChangeRec(FromNo,ToNo:longint) : boolean;

  procedure LoadFromFile(const FileName: string);

  procedure SaveToFile(const FileName: string);

  procedure LoadFromStream(Stream: TStream);

  procedure SaveToStream(Stream: TStream);

  procedure Clear;

{    function Read(var Buffer; Count: Longint): Longint; virtual; abstract;

  function Write(var Buffer; Count: Longint): Longint; virtual; abstract;}

  property Memory: Pointer read GetMemory;

published

  Property RecSize : longint read FRecSize write SetRecSize ;

  Property RecnoLabel : TLabel read FRecnoLabel write SetRecnoLabel ;

  Property ReccountLabel : TLabel read FReccountLabel write SetReccountLabel ;

  Property RecNo : longint read GetRecNo write SetRecNo ;

  Property RecCount : longint read GetRecCount ;

end;

 

procedure Register;

 

 

implementation

 

procedure Register;

begin

   RegisterComponents('AL',[TStMemoryStream]);

end;

 

constructor TStMemoryStream.Create(AOwner:TComponent);

begin

   inherited Create(AOwner);

   TM := TMemoryStream.Create;

   copyStream := TMemoryStream.Create;

   FRecNo := 0;

end;

 

destructor TStMemoryStream.Destroy;

begin

   TM.Free;

   copyStream.Free;

   inherited Destroy;

end;

 

procedure TStMemoryStream.RecAction;

begin

If RecNoLabel<>nil then RecNoLabel.Caption:=IntToStr(RecNo);

If RecCountLabel<>nil then RecCountLabel.Caption:=IntToStr(RecCount);

end;

 

function TStMemoryStream.GetMemory:Pointer;

begin

Result := TM.Memory;

end;

 

procedure TStMemoryStream.LoadFromFile(const FileName: string);

begin

TM.LoadFromFile(FileName);

RecAction;

end;

 

procedure TStMemoryStream.SaveToFile(const FileName: string);

begin

TM.SaveToFile(FileName);

end;

 

procedure TStMemoryStream.LoadFromStream(Stream: TStream);

begin

TM.LoadFromStream(Stream);

end;

 

procedure TStMemoryStream.SaveToStream(Stream: TStream);

begin

TM.LoadFromStream(Stream);

end;

 

procedure TStMemoryStream.Clear;

begin

TM.Clear;

RecAction;

end;

 

procedure TStMemoryStream.SetRecSize(Value:longint);

begin

If FRecSize<>Value then begin

   FRecSize:=Value;

   RecNo := RecNo;

   RecAction;

end;

end;

 

 

procedure TStMemoryStream.SetRecNo(Value:longint);

begin

   If Value<0 then Value:=0;

   If RecCount-1<Value then Value:=RecCount-1;

   TM.Seek(Value*FRecSize,0);

   FRecNo:=Value;

   RecAction;

end;

 

 

function TStMemoryStream.GetRecCount: longint;

begin

Result := TM.Size div RecSize;

end;

 

 

function TStMemoryStream.GetRecNo: longint;

begin

If RecSize=0 then Result:=0 else

Result := TM.Position div RecSize;

end;

 

procedure TStMemoryStream.SetRecNoLabel(Value:TLabel);

begin

FRecNoLabel:=Value;

If FRecNoLabel<>nil then FRecNoLabel.Caption:=IntToStr(RecNo);

end;

 

procedure TStMemoryStream.SetRecCountLabel(Value:TLabel);

begin

FRecCountLabel:=Value;

If FRecCountLabel<>nil then FRecCountLabel.Caption:=IntToStr(RecCount);

end;

 

Procedure TStMemoryStream.InsertRec(var Rec);

VAR i,meret: longint;

  r: Array[0..0] of Char;

begin

SaveToStream(copyStream);

meret := TM.Size div SizeOf(rec);

copyStream.Seek(0,0);

TM.Clear;

For i:=1 to RecNo-1 do begin

    copyStream.read(r,SizeOf(rec));

    TM.write(r,SizeOf(rec));

end;

TM.write(rec,SizeOf(rec));

For i:=Recno to meret do begin

    copyStream.read(r,SizeOf(rec));

    TM.write(r,SizeOf(rec));

end;

copyStream.Clear;

end;

 

Procedure TStMemoryStream.DeleteRec(var Rec);

begin

 

end;

 

Procedure TStMemoryStream.NewRecCount(Rec_Count: longint);

begin

 

end;

 

Function TStMemoryStream.GetRec(var Rec) : boolean;

begin

Try

   Result := True;

   TM.Read(Rec,SizeOf(Rec));

except

   Result := False;

end;

end;

 

Function TStMemoryStream.WriteRec(var Rec) : boolean;

begin

Try

   Result := True;

   TM.Write(Rec,SizeOf(Rec));

except

   Result := False;

end;

end;

 

Procedure TStMemoryStream.GoTop;

begin

TM.Seek(0,0);

end;

 

Procedure TStMemoryStream.GoBottom;

begin

TM.Seek(0,2);

end;

 

Function TStMemoryStream.SkipN(No:longint) : boolean;

begin

TM.Seek(No*RecSize,1);

end;

 

{ N. record kinyerése}

Procedure TStMemoryStream.GetRecN(No:longint;var Rec);

begin

TM.Seek(No*RecSize,0);

TM.Read(Rec,SizeOf(Rec));

RecAction;

end;

 

Procedure TStMemoryStream.WrireRecN(No:longint;var Rec);

begin

TM.Seek(No*RecSize,0);

TM.Write(Rec,SizeOf(Rec));

RecAction;

end;

 

Procedure TStMemoryStream.CutFromTo(FromNo,ToNo:longint);

begin

 

end;

 

Procedure TStMemoryStream.AddEmptyRec(var Rec);

begin

 

end;

 

Procedure TStMemoryStream.InsertEmptyRec(var Rec);

begin

 

end;

 

Function TStMemoryStream.MoveRec(FromNo,ToNo:longint) : boolean;

begin

 

end;

 

Function TStMemoryStream.ChangeRec(FromNo,ToNo:longint) : boolean;

begin

 

end;

 

end.