Re: Assigning Variables at runtime?
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Sat, 30 Apr 2005 20:48:56 +0200
"Damfino" <fxengelbrecht@xxxxxxxxx> schreef in bericht
news:1114873330.937136.230690@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> All
>
> I'm a newbie to Delphi, and newsgroups so please be patient. I have
> problem that has me stumped. It's as follows:
> I have a binary file containing blocks of 194 bytes of data. Each block
> starts with a 2 byte SyncVar of 01101001, so I can easily extract the
> 194 bytes. The problem comes in that the actual structure of the data
> can (and will) be different from file to file. What I would like to do
> is define the structure in a text file, and then at runtime apply that
> structure to the binary file question.
>
> The text file would then look something like this:
> Var1 1 Bit
> Var2 16 Bits
> Var3 3 Bits
> etc.
>
> My application can then use this definition to interpret the data block
> and allow for manipulation, etc.
>
> Anyone has an idea if this is even possible?
>
> Regards
>
I would proceed along these lines:
Textfile with structure: 1,16,3, ...
Read as string (I always use a Tstringlist to read txt files, even when
there's only one string).
Separate string into Vars : array of integer. Detect NrOfVars from this
process.
(There's a procedure to separate the string into strings in a Tstrings in
IDGlobal.PAS, if you have it.)
Read your binary file in a stream.
recNr:=0;
while NOT end of stream do
begin Take next chunk of 194 bytes into data : array[0..193] of byte
for k:=0 to NrOfVars-1 do
extract next Vars[k] bits from data and assign value to a
variable[recNr,k];
inc(RecNr)
end;
Tom
.
- References:
- Assigning Variables at runtime?
- From: Damfino
- Assigning Variables at runtime?
- Prev by Date: Re: Array pointers like C++
- Next by Date: Re: Array pointers like C++
- Previous by thread: Re: Assigning Variables at runtime?
- Index(es):
Relevant Pages
|
|