(Gast)
n/a Beiträge
|
Re: Denkblockade: Wie speicher ich ein Array in einer Datenb
3. Mai 2009, 22:45
Das kann man ja nich mit ansehen
Delphi-Quellcode:
type
TTag = record
Key, Value: string;
end;
TTags = array of TTag;
procedure WriteInt(i: Integer; stream: TStream);
begin
stream.Write(i, sizeof(i));
end;
function ReadInt(stream: TStream): Integer;
begin
stream.Read(result, sizeof(result));
end;
procedure WriteString(s: string; stream: TStream);
begin
WriteInt(Length(s), stream);
stream.Write(s[1], Length(s));
end;
function ReadString(stream: TStream): string;
begin
SetLength(result, ReadInt(stream));
stream.Read(result[1], Length(result));
end;
procedure WriteTags(tags: TTags; stream: TStream);
var i: Integer;
begin
WriteInt(Length(tags), stream);
for i := 0 to High(tags) do begin
WriteString(tags[i].Key, stream);
WriteString(tags[i].Value, stream);
end;
end;
function ReadTags(stream: TStream): TTags;
var i: Integer;
begin
SetLength(result, ReadInt(stream));
for i := 0 to High(Result) do begin
tags[i].Key := ReadString(stream);
tags[i].Value := ReadString(stream);
end;
end;
|
|
Zitat
|