title image


Smiley strings beliebiger länge in dateien speichern
mach dir ne gescheite klasse, z.b. so in der art:





type



TMeineKlasse = class(TObject)

private

FMyString: String;

FMyInt: Integer;

public

procedure SaveToStream(AStream: TStream);

procedure LoadFromStream(AStream: TStream);



procedure SaveToFile(AFileName: TFileName);

procedure LoadFromFile(AFileName: TFileName);



property MyString: String read FMyString write FMyString;

property MyInt: Integer read FMyInt write FMyInt;

end;



procedure TMeineKlasse.SaveToStream(AStream: TStream);

var

i: Integer;

begin

i:=Length(FMyString);

AStream.WriteBuffer(i, SizeOf(i));

if i > 0 then AStream.WriteBuffer(FMyString[1], i);

AStream.WriteBuffer(FMyInt, SizeOf(FMyInt));

end;



procedure TMeineKlasse.LoadFromStream(AStream: TStream);

var

i: Integer;

begin

AStream.ReadBuffer(i, SizeOf(i));

SetLength(FMyString, i);

if i > 0 then AStream.ReadBuffer(FMyString[1], i);

AStream.ReadBuffer(FMyInt, SizeOf(FMyInt));

end;



procedure TMeineKlasse.SaveToFile(AFileName: TFileName);

var

fs: TFileStream;

begin

fs:=TFileStream.Create(AFileName, fmCreate or fmShareDenyWrite);

try

SaveToStream(fs);

finally

fs.Free;

end;

end;



procedure TMeineKlasse.LoadFromFile(AFileName: TFileName);

var

fs: TFileStream;

begin

fs:=TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);

try

LoadFromStream(fs);

finally

fs.Free;

end;

end;







so einfach siehts dann aus:



var

mk: TMeineKlasse;

begin

mk:=TMeineKlasse.Create;

try

mk.MyString:='Hallo!';

mk.MyInt:=1234;



mk.SaveToFile('C:\Test.dat');



geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: