DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Using Formula One ActiveX control - my Excel sheet forgets locked cells (protection)


I am using Formula One ActiveX control in Delphi 5. My application generates a complex workbook and locks certain cells. When I export my Excel workbook, the locked cells are forgotten. Protection is enabled, but all cells are unlocked.


I had the same problem and found that the property EnableProtection does not work as expected.
The documentation says:

EnableProtection sets or returns whether protection is enabled for all selected sheets.


F1Book1.EnableProtection [ = boolean ]

What I found is that the number of places where you temporarily disable the protection must match exactly the number of places where you enable it. The code below will not work if the code executes updateformulas(), as in that case it assigns twice := false and only once := true

function updateformulas();
   f1book.EnableProtection := false;
   // do something with f1book
   f1book.EnableProtection := false;
   if (condition) then updateformulas;
   f1book.EnableProtection := true;

Generated 20:01:59 on Mar 21, 2018