Prevent a user from renaming a record in certain forms

AleSlammerAleSlammer Member Posts: 25
Hi

Is it possible to prevent users from renaming records in certain forms ?
I know some people will ask what reason, and some people will tell me just to throw an error message in the rename trigger of the underlying table.

The reason for doing so is that it should be a master table renaming tables where the primary key of the master table is a foreign key.
The application is integrated with a webshop, and the webshop handles the renaming of master tables, so I should only care about renaming the tables and not telling the webshop what to do(only that the master table has been renamed - in that way I don't need to put a lot of code in the rename triggers of other than master tables)

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Does it use Number Series? Make the "No." field non editable??
  • AleSlammerAleSlammer Member Posts: 25
    Hi Mark and thank you for your answer :-)

    no the key doesn't use number series. You have to be able to insert new records in the table and define the primary keys yourself, so I don't think that's the way to go :-)
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What about make it editable based on the boolean condition ("No." = '')
  • AleSlammerAleSlammer Member Posts: 25
    that could be the way to go...in which trigger would you put the code ?
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • AleSlammerAleSlammer Member Posts: 25
    I tried with the following code:


    IF(Category <> '') THEN
    BEGIN
    CurrForm.Category.EDITABLE := FALSE;
    END

    OnAfterGetCurrRecord trigger, but it worked a little bit too well...I can't edit the field no matter I make a new record. Am I missing your point in someway ?
  • FDickschatFDickschat Member Posts: 380
    Put something like this in OnAfterGetCurrRecord:

    CurrForm."No.".EDITABLE ("No." = '')

    assuming that the Field "No." is the primary key field.

    The editable property of the field on the form is true.
    Frank Dickschat
    FD Consulting
  • lvanvugtlvanvugt Member Posts: 774
    What about using the OnModifyRecord() trigger of the Form?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • AleSlammerAleSlammer Member Posts: 25
    thanks to everybody for their response. I tried everything and I found that FDickschat's solution worked. I wonder why it worked though, since the editable is allready set to true and CurrForm."No.".EDITABLE ("No." = '') shhould logically only change the field to be editable if the no=''. The thing is I would expect that you would make it not editable from No. <> '' instead of making it editable, since it is allready editable :-k
  • BeliasBelias Member Posts: 2,998
    AleSlammer wrote:
    thanks to everybody for their response. I tried everything and I found that FDickschat's solution worked. I wonder why it worked though, since the editable is allready set to true and CurrForm."No.".EDITABLE ("No." = '') shhould logically only change the field to be editable if the no=''. The thing is I would expect that you would make it not editable from No. <> '' instead of making it editable, since it is allready editable :-k
    you should have done this
    IF(Category <> '') THEN BEGIN
      CurrForm.Category.EDITABLE := FALSE;
    END ELSE BEGIN
      CurrForm.Category.EDITABLE := TRUE;
    END;
    
    but FDicksChat solution is the perfect way: 1 line instead of 5...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • FDickschatFDickschat Member Posts: 380
    If you think about the "why" the solution is not so far away: The field properties (Editable, Enabled,...) are applied to the field only once at the time the form is opened. Instead of the properties you could also write one line of code in the OnOpenForm Trigger.

    As the form opens usually to an existing record your line of code comes in and makes the field not editable. When you press F3 nothing happens because you have not programmed it and the property is not applied again as the form is already open.
    Frank Dickschat
    FD Consulting
  • matttraxmatttrax Member Posts: 2,309
    FDickschat wrote:
    If you think about the "why" the solution is not so far away: The field properties (Editable, Enabled,...) are applied to the field only once at the time the form is opened.

    Not true at all. They are applied when a new record is loaded. What if you loaded a record that caused fields to be uneditable, but then moved to another perfectly good record without closing the form? You wouldn't expect the fields to remain uneditable.
  • FDickschatFDickschat Member Posts: 380
    matttrax wrote:
    FDickschat wrote:
    If you think about the "why" the solution is not so far away: The field properties (Editable, Enabled,...) are applied to the field only once at the time the form is opened.
    Not true at all. They are applied when a new record is loaded. What if you loaded a record that caused fields to be uneditable, but then moved to another perfectly good record without closing the form? You wouldn't expect the fields to remain uneditable.
    I don't think that is correct. In my quoted text I'm talking about the properties, not about code. If a field property says editable=no then the field remains uneditable regardless of the record and vice versa. There is no way a record can cause a field property to change it's behaviour without a line of code. That's why it is sufficient to apply properties only at the time of opening a form.

    Actually this thread supports my theory: You have to program both, the editable=true and the editabe=false part. If you set the property to true and only program the false part it is not working.
    Frank Dickschat
    FD Consulting
Sign In or Register to comment.