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

Reply via email to