I agree with Ken's idea of loading that data into XML or a mapped file.  It 
would be easier to work with and transportable between executions.

----- Original Message ----- 
From: "Ken Adam" <[EMAIL PROTECTED]>
To: "'Delphi-Talk Discussion List'" <[email protected]>
Sent: Friday, October 14, 2005 10:19 AM
Subject: RE: wierd stuff happening


>I think you need to understand that your two problems are strongly
> related.
>
> You seem to be assuming that you can write pointers to a file, and then
> read them back (which you can), and have this make some sort of sense
> (which you can't).
> Unfortunately, pointers are the address of (usually dynamically
> allocated) memory within the address space of the current instance of
> your application.
> When you run the program again, there is no reason to assume that these
> addresses will be within the address space, and more importantly, even
> if they are, the memory will not have been allocated to stroe the data
> you are trying to address - it may be unsued or more likely already in
> use for something else. Even within the same run, the memory might not
> still be allocated to the structure (if it is, then why re-read the
> data?)
>
> It is quite possihle that the "pointers" you read will point to memory
> being used by Delphi itself.
>
> You need to re-think the way in which you are saving your data
> structures to use a format which does not involve memory pointers.
>
> Desigin a binary format is not trivial, and is usually hard to extend
> when you think of one more bit of information you need to stire (because
> it breaks any data you have saved before). I am now using XML formats to
> store information which in the past I would have used binary files for -
> the files are much larger, but the e-X-tensibility makes it all
> worthwhile.
>
> Regards,
> Ken.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Richard R
> Sent: 14 October 2005 03:50
> To: 'Delphi-Talk Discussion List'
> Subject: wierd stuff happening
>
>
> Hello again. I dont have any explanation on what's going on, maybe its
> just the nature of things or delphi is seriously a messed up program
> (i'm using delphi 6 enterprise)
>
> I have a pointer that points to an array of pointers. It's under the
> public section of the TObject class. When data is put into it via the
> host application, extracting data such as name, etc works just fine.
> However, as soon as a call to the BlockRead function that reads another
> public variable of type integer named differently, it totally
> reallocates the array pointer, erasing all the data.
>
> I have shut down delphi, normally, and rebooted my ssytem and still it
> acts all wierd and stuff. Any suggestions? I dont have any viruses or
> trojans on my system, its clean. These problems only occur within this
> block of code. In different projects, i've come across really wierd crap
> happening, usually I can work around it (placing a call toa  function
> before another, which to me has no logical reason, but makes it work),
> however this problem is like the entire file is corrupt or whatever. I
> really am at my wits end. Here's the pas file, maybe you can make
> something out of it.
>
> http://element8mm.250free.com/pedata.pas
>
> procedure TSPEObjs.FRead(fname: string);
> var
>  f: File;
>  i, j: integer;
>  flag1, flag2: boolean;
> begin
>  if (fname = '') then
>    exit;
>  AssignFile(f, fname);
>  try
>    Reset(f);
>    BlockRead(f, nbrPEObjs, sizeof(nbrPEObjs)); // peObjs array is f'd
> up after this is called
>    BlockRead(f, flag1, sizeof(flag1));
>    BlockRead(f, flag2, sizeof(flag2));
>    FreeData; // if I put this behind the first block read line, peObjs
> (supposed to be nil) still gets allocated with data from god knows where
>    if (nbrPEObjs > 0) then begin
>      if flag1 then // is forced as false in write procedure
>        peObjs:= tsxMalloc(nbrPEObjs * sizeof(pointer));
>      if flag2 then
>        selDataArray:= tsxMalloc(nbrPEObjs * sizeof(TSelData));
>      for i:= 0 to nbrPEObjs - 1 do begin
>        if flag1 then
>          BlockRead(f, peObjs[i], sizeof(peObjs[i]));
>        if flag2 then begin
>          // this info gets read in correctly with all correct data
>          BlockRead(f, selDataArray[i].seltype,
> sizeof(selDataArray[i].seltype));
>          BlockRead(f, selDataArray[i].nbrSelVxs,
> sizeof(selDataArray[i].nbrSelVxs));
>          if (selDataArray[i].nbrSelVxs > 0) then begin
>            selDataArray[i].vxsIdxArray:=
> tsxMalloc(selDataArray[i].nbrSelVxs * sizeof(integer));
>            for j:= 0 to selDataArray[i].nbrSelVxs - 1 do
>              BlockRead(f, selDataArray[i].vxsIdxArray[j],
> sizeof(selDataArray[i].vxsIdxArray[j]));
>          end;
>          BlockRead(f, selDataArray[i].nbrSelEdges,
> sizeof(selDataArray[i].nbrSelEdges));
>          if (selDataArray[i].nbrSelEdges > 0) then begin
>            selDataArray[i].edgeArray:=
> tsxMalloc(selDataArray[i].nbrSelEdges * sizeof(integer));
>            for j:= 0 to selDataArray[i].nbrSelEdges - 1 do
>              BlockRead(f, selDataArray[i].edgeArray[j],
> sizeof(selDataArray[i].edgeArray[j]));
>          end;
>          BlockRead(f, selDataArray[i].nbrSelFaces,
> sizeof(selDataArray[i].nbrSelFaces));
>          if (selDataArray[i].nbrSelFaces > 0) then begin
>            selDataArray[i].faceIdxArray:=
> tsxMalloc(selDataArray[i].nbrSelFaces * sizeof(integer));
>            for j:= 0 to selDataArray[i].nbrSelFaces - 1 do
>              BlockRead(f, selDataArray[i].faceIdxArray[j],
> sizeof(selDataArray[i].faceIdxArray[j]));
>          end;
>        end;
>      end;
>    end;
>  finally
>    CloseFile(f); // when this is called, the host application has a
> cow, its interface all chewed up, etc
>  end;
> end;
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
>
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
>
> 

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to