Forum > Cocoa
[SOLVED] TCombobox causes Access Violation - Is my fix causing new problems?
Hansaplast:
In one of my more complicated and larger projects, I keep running into Access Violations at times when opening a TCombox.
In my code the list items change under certain circumstances - so I figured that would be the culprit.
Even disabling the control while changing the items list made it still crash.
Disabling all events still keeps it crashing and the debugger keeps point to a certain procedure in "CocoaTextEdits".
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TCocoaReadOnlyComboBoxMenuDelegate.menu_willHighlightItem( menu: NSMenu; item: NSMenuItem);begin if Assigned(_lastHightlightItem) then _lastHightlightItem.view.setNeedsDisplay_( True ); _lastHightlightItem:= item;end;
With the debugger stating that _lastHightlightItem is not defined (of course very likely an incorrect statement due to the crash).
I've tried numerous little test projects to see if I can reproduce this, but cannot reproduce it in those little projects.
Doing all kinds of elimination steps in my project (assuming I did something wrong) didn't fix it either.
(I'm still under the impression that I made a mistake)
However, what did fix it is commenting out the first two lines in "TCocoaReadOnlyComboBoxMenuDelegate" (note: the TComboBox is not set to be readonly - in case that is relevant), like so:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TCocoaReadOnlyComboBoxMenuDelegate.menu_willHighlightItem( menu: NSMenu; item: NSMenuItem);begin// if Assigned(_lastHightlightItem) then// _lastHightlightItem.view.setNeedsDisplay_( True ); _lastHightlightItem:= item;end;
I am confident that these two lines have a very legit purpose, so I created a few test projects to see what would break because of removing these 2 lines, and low and behold, everything I tested works just fine.
Now I'm quite confident that the dev who wrote this code, placed it there for a very valid reason.
Note: I'm aware that posting my code would be more helpful, ut it is such a large project that it would be hard for anyone to see where I may have made a mistake. On top of that: it would be my problem to figure out of course.
After digging through all my code most of the day now, I just wanted to make sure I'm not wasting my time.
So my question is: did I bump into a bug or no longer needed code in "CocoaTextEdits"?
Zvoni:
My guess is a Bug ("dangling" _lastHightlightItem).
Have you tried to first explicitely clear the Items of the ComboBox (Items is a TStrings), and THEN adding the new Items?
Just as an Try and Error.
It sounds like, e.g. Item 6 is Highlighted, and then you change (!!) the list (not clearing it), which then consists of only 3 items.
And _lastHightlightItem still points to the non-existing item.
my 2 cents
Hansaplast:
Good suggestion, and tried it right away ... (combo.items.clear)
Unfortunately, still the same crash 😞
Keeping the clear in the code though. Seems like the right thing to do.
Very much appreciate your 2 cents though - been doing trial and error for most of the day now.
Commenting out was the only thing that worked and did not seem to have an effect at all on how TComboBox works in other scenarios.
How the one who coded this reads this and might have an idea.
rich2014:
just confirm,you are using a TCombobox with ReadOnly=True, right?
please create a new issue and provide a simple test project (even if it is so simple that it does not crash)
Hansaplast:
Hi Rich2014,
Thanks for chiming in :) ...
Actually ... no.
Initially I had it set to ReadOnly := true, but I changed that to ReadOnly := False once I noticed the "ReadOnly" part in the procedure name figuring it would not use this procedure.
Changing the value does not appear to change the error (been testing with ReadOnly := False).
As mentioned before:
I have not been able to make a simple demo project that reproduces this (hence my assumption I am doing something wrong in my code). Been digging into this for a day now (in my own code) and noticed that the only thing that fixes this is disabling these 2 lines.
I assume I am doing something wrong, but since commenting out those two lines did not break TComboBox in other projects, I was wondering if this code still has a purpose.
Not sure what you mean with "a simple test project (even if it is so simple that it does not crash)" ...?
Navigation
[0] Message Index
[#] Next page