MapInfo Pro Developers User Group

 View Only
  • 1.  Need help with RowDeletedEvent [MapInfo 17]

    Posted 09-21-2020 02:47
    Hello,

    I'm trying to implement RowDeletedEvent on Table. Idea is to take same action after user deletes record.

    I tried this code:

    private void AddHandlerToRowDel()
    {
    table = Session.Current.Catalog.OpenTable(tableFullPath);
    if (table == null)
    return;

    table.RowDeletedEvent += Table_RowDeletedEvent;
    }

    private void Table_RowDeletedEvent(object sender, RowDeletedTableEventArgs e)
    {
    //Take action
    }

    However, this doesn't raise the event after I delete object from (linked) table. Then I thought maybe I should save changes in order to trigger the event, but I got this message:
    "Cannot access file Points.DAT for writing. Please be sure that this file is not open in another application."

    This made me think it's because Table.OpenTable() locks .DAT file, however I found this in ExtensibilityReferenceHelp:
    "An open table does not imply that the files containing the data are held open for the duration the table is "open". An open table simply means that a table (MapInfo native data, RDB server table, etc.) has been made known to the`` Catalog as a table that the user wishes to interact with.", so it shouldn't lock .DAT file, right?

    Just to test, I added TableIsClosingEvent to table, and when I close table in MapInfo event doesn't fire. So, I added table.Close() in my code and that's when event gets triggered. This probably means that RowDeletedEvent is raised when you call Table.DeleteFeature()?

    ------------------------------
    Miroslav Kovacevic
    Knowledge Community Shared Account
    ------------------------------


  • 2.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Employee
    Posted 09-21-2020 16:02
    Hi Miroslav,

    MDAL has limited support for linked tables. Did you try this on a plain native or nativex table?

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 3.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Posted 09-22-2020 01:56
    Hello Bob,

    yes I have tried with native table, and same error occurs.

    ------------------------------
    Miroslav Kovacevic
    Knowledge Community Shared Account
    ------------------------------



  • 4.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Employee
    Posted 09-23-2020 17:01
    Hi Miroslav,

    Can you send me or post a small sample that reproduces the problem?

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 5.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Posted 09-24-2020 04:20
    Edited by Miroslav Kovacevic 09-24-2020 04:40
    Hi Bob,

    here is a link to small functional example of problem. And here is error message I get.

    Thank you.

    ------------------------------
    Miroslav Kovacevic
    Knowledge Community Shared Account
    ------------------------------



  • 6.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Employee
    Posted 09-24-2020 13:05
    Hi Miroslav,

    I looks like you want the row deleted event to be fired when the Pro user deletes a row via the ui.

    If that is the case then this will not work. Unfortunately the MDAL library operates in its own app domain with a separate copy of the table, (which is why you have to call OpenTable()). The event would only be fired  if a row is deleted using methods or sql via the MDAL api.

    We do not have any similar event in Pro, although if you explain what you are trying to achieve maybe we can suggest a way.

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 7.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Posted 09-26-2020 16:55
    Bob,

    thank you for clarifying this a bit. Can you give me more insight on how MDAL works with tables?

    What happends when I run Table.OpenTable()? You say "a seperate copy of table is made", while ExtensibilityReferenceHelp has this definition I quoted in earlier post: "...open table simply means that a table has been made known to the 'Catalog' as a table that the user wishes to interact with."

    If it is a copy:
    - is it up-to-date copy, or current copy at the moment of calling OpenTable()?
    - does it occupy same size in memory as table files on file system.

    Why is .DAT file locked when OpenTable() is active? I'm guessing it's to avoid conflict of deleteing/inserting/updating feature using MDAL and UI simultaniously, but I'm not sure.

    ------------------------------
    Miroslav Kovacevic
    Knowledge Community Shared Account
    ------------------------------



  • 8.  RE: Need help with RowDeletedEvent [MapInfo 17]

    Employee
    Posted 10-06-2020 10:11
    Hi, Sorry for the delay,

    When a table is opened we do not keep the files locked. They are only locked when reading or writing to them.
    Sorry for the confusion, there is no second copy of the tables files, either in memory or on disk.
    In MDAL you can use table.BeginAccess() to lock a table for read or write when you are going to issue multiple statements against a table. Have you use this?

    I am not sure what your are seeing with that error message. There could be a conflict if both Pro and MDAL are trying to update the file at the same time or if you have it locked with BeginAccess.

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------