Einzelnen Beitrag anzeigen

sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#1

Save and Load dynamic array

  Alt 26. Jan 2012, 14:21
Delphi-Version: 7
Hi i've this Class , please can someone help me in saving and loading its Dynamic array from a Stream


Delphi-Quellcode:
const
iGlobHolderCount =100;
type
 TFiLeSpec = record
  iSize : Integer;
 end;
 TFileSpecLst = array of TFiLeSpec;

TFiLeSpecList = record
  iMin :Integer;
  iMax :Integer;
  iCount :Integer;
  FileSpecLst :TFileSpecLst;
 end;
 TFileChecker = class
 Function LoadFromFile(AFileName : string) : boolean;
 Function SaveToFile(AFileName : string) : boolean;
private
FFileSpec : array of TFileSpec;
FFileSpecList : array[1..iGlobHolderCount] of TFileSpecList;
function GetCount: integer;
public
constructor Create;
destructor Destroy; override;
property iCount : integer read GetCount;
end;


{ TFileChecker }

constructor TFileChecker.Create;
begin
FFiLeSpec:= nil;
end;

destructor TFileChecker.Destroy;
var
 i : integer;
begin
 FFileSpec:= nil;
 for i := 1 to iGlobHolderCount do
  FFileSpecList[i].FileSpecLst := nil;
  inherited;
end;

function TFileChecker.GetCount: integer;
var
 x, i : integer;
begin
Result:=0;
 x := 0;
 for i := 1 to iGlobHolderCount do
 x:=x+ Length(FFileSpecList[i].FileSpecLst);
 Result := Length(FFileSpec)+x;
end;


function TFileChecker.LoadFromFile(AFileName: string): boolean;
var
iStream:TMemoryStream;
i:Integer;
begin
Result:=False;
SetLength(FFileSpec, 0);

iStream:= TMemoryStream.Create;
Try
iStream.LoadFromFile(AFileName);
// how it can be loaded from the Stream

Result:=True;
finally
iStream.Free;
end;

end;

function TFileChecker.SaveToFile(AFileName: string): boolean;
var
iStream:TMemoryStream;
i:Integer;
begin
Result:=False;
iStream:= TMemoryStream.Create;
Try
// how it can be saved to the Stream
iStream.SaveToFile(AFileName);
Result:=True;
finally
iStream.Free;
end;

end;
many thanks
  Mit Zitat antworten Zitat