In article <tdDoBKAKPjj8E...@occpsy.demon.co.uk>, "L. Healy"
Quote
<L.He...@occpsy.demon.co.uk> writes:
>the tel numbers go into n telnumber variables, the address lines go into
>n address line variables etc - there are six categories of variable
>altogether, some might have one or anything up to 20 values. I want to
>do different things with the different categories of variable so I can't
>read it into one long string list.
>Does anyone have nay suggestions?
declare an enumerated type to nominate the type of data ...
TListDataType = (ldtHomePhone, ldtWorkPhone, ldtMobilePhone, ldtAddress, etc
etc
Then have a few string reading and writing procedures ...
function ReadStreamInt(Stream : TStream) : integer;
{returns an integer from stream}
begin
Stream.ReadBuffer(Result, SizeOf(Integer));
end;
function ReadStreamStr(Stream : TStream) : string;
{returns a string from the stream}
var
StrLen : integer;
begin
Result := '';
{get length of string}
StrLen := ReadStreamInt(Stream);
{set string to get memory}
SetLength(Result, StrLen);
{read characters}
Stream.Read(Result[1], StrLen);
end;
procedure WriteStreamInt(Stream : TStream; Num : integer);
{writes an integer to the stream}
begin
Stream.WriteBuffer(Num, SizeOf(Integer));
end;
procedure WriteStreamStr(Stream : TStream; Str : string);
{writes a string to the stream}
var
StrLen : integer;
begin
{get length of string}
StrLen := Length(Str);
{write length of string}
WriteStreamInt(Stream, StrLen);
{write characters}
Stream.Write(Str[1], StrLen);
end;
Then you can write to a stream ...
Stream.Write(ListDataType, SizeOf(TListDataType));
WriteStreamStr(Stream, StringList.Text);
.. for every element of your data. You may have to copy each set of elements to
an individual stringlist to get the StringList.Text, which is one string of all
your individual strings deleimited with CRLF. The stream write/read functions
write and copy the string length and then the characters. so all you have is a
number of elements ...
type_of_data_value strings_of_data_value
.. in the stream, then as the first write to your stream, write the number of
these elements. The first integer you read from the stream will then become
(-1) a limit specifier of a "for" loop which will read the rest into a
stringlist.
Alan Lloyd
alangll...@aol.com