Page 1 of 1

D4D lyr_read bug ?

PostPosted: Fri Oct 05, 2018 3:46 am
by dhs
I have a problem with the lyr_read call in the following code:
Code: Select all   function CopyLyrContent (fromlyr, tolyr : lyraddr; zshift : double) : boolean;
  var
    tempfilename : str255;
    addr : entaddr;
    mode : mode_type;
    ent : entity;
  begin
     result := true;
     getpath (tempfilename, pathtmp);
     tempfilename := tempfilename + 'dh_lmtemp';
     if fileexists (tempfilename + '.dlf') then begin
      if not deletefile (tempfilename + '.dlf') then begin
        result := false;
        exit;
      end;
     end;
     result := (lyr_write (fromlyr, tempfilename) = 0);
     if result then
      result := (lyr_read (tolyr, tempfilename, false, false) = 0);

the lyr_read on the last line of the code snippet is returning a value of -5 (and hence the function result is false).
Some D4D notes I have suggest that -5 means that the layer file is not found, but I know that it is created as I can see it in FIle Explorer. The same notes suggest that I need to add the '.dlf' extension to the file name passed to lyr_read so I tried that but it produced a fault 19 error from 736 when I did so.
I believe that the layer parameters passed to this funciton are ok: fromlyr is the (not nil) result of either a lyr_first or lyr_next call, and tolyr is the address returned by a successful lyr_create call.

Is anybody able to offer any advice on the use of the lyr_read function? This bit of code is pretty much converted straight from some existing Classic DCAL code which works just fine.

Thanks,
David H.