Re: Assigning Variables at runtime?



"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


.



Relevant Pages

  • Re: File handling
    ... > I have a problem on retriving a content of a binary file I wrote into. ... Now you try to write a structure, containing a pointer to a string. ...
    (comp.lang.c)
  • Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader
    ... I solved it by looking into the MFC ... public string ReadCString() ... >> I am able to open the binary file and read out the individual ... >> old string termination issues, but I've checked the byte representing ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Speed of Applications in VBA vs VB
    ... I dont think there are any cr lf in the binary file but I'm learning a lot ... Dim filebuffer As String ... I will try the streamreader. ... functionality around the VBA engine that is not available in VBA (creating ...
    (microsoft.public.excel.programming)
  • Re: Problem in writing structure to Binary file in C lang
    ... reading those data from binary file and display it in C language. ... How should the program know the size of the string without actually ... but not the string pointed to by the structure, it also writes a binary pointer to ...
    (comp.lang.c.moderated)
  • Re: Copying byte sequence from integer/real to character array
    ... > I am writing code to write a binary file. ... > I therefore want to create a large character array, ... later you can read the file substituting a binary read (without format ... I wrote a routine that allows creating a big string of any ...
    (comp.lang.fortran)