Page 1 of 1

lyr_isLocked bug?

PostPosted: Sat Jun 02, 2018 9:13 pm
by dhs
Hi,
Just wondering if anybody else has used the lyr_isLocked function in Dcal for Delphi ?
I seem to be getting unpredictable results with it in the following logic:

Code: Select allprocedure TdhForm.FormCreate(Sender: TObject);
var
  MyLyr : TLyr;     //class which simply holds layer address so that it can be added to the list as an object
  lyr     : lyraddr;
  lyrname : shortstring;
  ndx : integer;
begin
  lyr := lyr_first;
  repeat
    MyLyr := TLyr.Create(lyr);
    getlyrname (lyr, lyrname);
    if lyr_isLocked (lyr) then
      lyrname := lyrname + ' (LOCKED)';
    ndx := ListBox1.Items.AddObject(string(lyrname), MyLyr);
    ListBox1.Selected[ndx] := LyrEqual (lyr, GetLyrCurr);
    lyr := lyr_next(lyr);
  until isnil (lyr);
end;


With the above code I am getting ' (LOCKED)' appended to layer names pretty much at random.
Have I done something obviously wrong here or is the lyr_isLocked function buggy ? (I am using Dcad 20.01.00.04).

Thanks,
David H.

Re: lyr_isLocked bug?

PostPosted: Mon Jun 04, 2018 10:30 am
by David A. Giesselman
What does the Create method for your TLyr class look like?

Re: lyr_isLocked bug?

PostPosted: Mon Jun 04, 2018 1:34 pm
by dhs
Hi Dave,
Here's the entire class:

Code: Select allunit Lyr;

interface
  uses URecords;

  type
    TLyr = Class(TObject)
       private
          MyAddr : lyrAddr;
       published
         constructor Create(Addr : lyraddr);
         property Addr : lyraddr
             read MyAddr;
    end;

implementation
 constructor TLyr.Create(Addr : lyraddr);
 begin
   MyAddr  := Addr;
 end;
end.


As you can see, it's a simple assignment statement in the create. Subsequent logic retrieving the lyraddr from the list objects is working as expected.

Rgds,
David H.

Re: lyr_isLocked bug?

PostPosted: Mon Jun 04, 2018 1:47 pm
by David A. Giesselman
David,

I'm not sure why it would be giving you unpredictable results. If you modify your code to call "lyr_get" you could inspect the .group field of the Rlayer record. If that field is equal to -1, the layer is not locked.

Dave

Re: lyr_isLocked bug?

PostPosted: Mon Jun 04, 2018 4:29 pm
by dhs
Thanks Dave,

Your suggestion of inspecting the .group field of the layer record is working as expected.

Re: lyr_isLocked bug?

PostPosted: Mon Jun 04, 2018 4:40 pm
by David A. Giesselman
dhs wrote:Thanks Dave,

Your suggestion of inspecting the .group field of the layer record is working as expected.

No worries David, although I am intrigued as to why the function call was returning different results.

Re: lyr_isLocked bug?

PostPosted: Wed Jun 06, 2018 5:50 pm
by dhs
Happy send you the entire project source if you want to debug it etc to see why it is returning incorrect values, but the workaround you suggested seems to working ok.

I was working on a simple Text Replace macro as an exercise to re-familiarise myself with D4D. (It is now completed and available for download from my web site for anybody that is interested.) It will only process normal text entities, as I don't think MText or PText are accessible from DCAL or D4D (?). Any chance that these entity types will be accessible by D4D in the future ?

Rgds,
David H.