I am making this simple ApplescriptObjC cocoa app just as an exercise for me to understand the multi treading, it is a text field and a label, I was trying to update the label in real time while typing in the text field, but it only get updated once I press enter but not in real time, any idea how I can make that work? here is the code.
Thanks
script AppDelegate
property parent : class "NSObject"
property prgLabel: missing value
property subjectFeild: missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
activate
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
on textChange_(sender)
set SU to subjectFeild's stringValue() as string
prgLabel's setStringValue_(SU)
end textChange_
end script
1) Set the delegate of the textfield to be your app delegate.
2) Implement controlTextDidChange, which is called every time the text field changes during editing.
script AppDelegate
property parent : class "NSObject"
-- IBOutlets
property theWindow : missing value
property prgLabel: missing value
property subjectFeild: missing value
on applicationWillFinishLaunching:aNotification
subjectFeild's setDelegate:me
end applicationWillFinishLaunching_
on controlTextDidChange:notification
prgLabel's setStringValue:subjectFeild's stringValue()
end
end script
Related
Here's one I don't understand.
Given this class module (stripped down to the bare minimum necessary to reproduce the crash):
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "TestCrashClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Function Init() As TestCrashClass
Attribute Init.VB_UserMemId = 0
Dim tcc As New TestCrashClass
Set Init = tcc
End Function
Public Property Get Data() As String
Data = "test data"
End Property
Can anyone tell me why Excel totally craps out when I type in this code:
Sub MakeExcelCrash()
With TestCrashClass(
At this point, I this lovely message:
Even if I type in a full procedure without the offending parentheses and then try to add them later, I get the same crash.
The only way I can get Excel not to crash is to copy/paste a set of () from somewhere else to this line of code.
Sub MakeExcelCrash()
With TestCrashClass()
Debug.Print .Data
End With
End Sub
If the Init() method has a parameter—even an optional one—it won't crash when the opening paren is typed.
I'm more curious about why this happens than ways around it; it doesn't actually come up that often in my code and when it does I can fix it with a change in approach, but I'm really frustrated that I don't know what's causing these crashes. So maybe someone who knows more about the inner working of VBA can explain it to me?
You don't even need the With block. Any attempt to type ( after the class name takes Excel down.
The problem is that you have the VB_PredeclaredId set to true and the default member is trying to return itself. When you attach a debugger to the dying Excel instance, you can see that the underlying issue is a stack overflow:
Unhandled exception at 0x0F06EC84 (VBE7.DLL) in EXCEL.EXE: 0xC00000FD:
Stack overflow (parameters: 0x00000001, 0x00212FFC).
When you type With TestCrashClass(, what happens is that VBA starts looking for an indexer on the default property, because Init() doesn't have any properties. For example, consider a Collection. You can use the default property's (Item) indexer like this:
Dim x As Collection
Set x = New Collection
x.Add 42
Debug.Print x(1) '<--indexed access via default member.
This is exactly equivalent to Debug.Print x.Items(1). This is where you start running into problems. Init() doesn't have parameters, so VBA starts drilling down through the default members to find the first one that has an indexer so IntelliSense can display the parameter list. It starts doing this:
x.[default].[default].[default].[default].[default]...
In your case, it's creating an infinite loop because [default] returns x. The same thing happens in the Collection code above (except it finds one):
Throw in the fact that you have a default instance, and the end result is something like this:
Private Sub Class_Initialize()
Class_Initialize
End Sub
As #TimWilliams points out, having a default member that returns an instance of the same class (or a class loop eg. ParentClass.ChildClass.ParentClass.ChildClass... where ParentClass and ChildClass both have default members), and when used in certain syntax cases, such as a With block, will cause VBE to try and resolve the default member.
The first parenthesis makes VBE assume there must be a method, indexed get or array index that will take an argument, so it sets off to resolve the ultimate target member.
So the incomplete line, with a cursor located after the parenthesis:
With TestCrashClass(
Is effectively the same as:
With TestCrashClass.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init.Init '....You're inquisitive scrolling this far over, but you get the point.
At some point, your system or VBE runs out of resources and exits with the grace and poise of a thermonuclear group-hug.
+1 for improvising with a copy/pasta of a parentheses pair.
Sounds like some sort of corruption. I've had Excel behave irrationally like this before, normally in large projects, and the only way to get around it is to drag all of your classes etc into a new project.
I suspect it happens because Excel doesn't truly delete classes, modules, worksheets etc that have been removed. You can tell this because of the file size.
There is no Compact and Repair functionality, as in Access, as far as i'm aware
I have the following inputText field in MAF.
< amx:inputText value="#{bindings.searchCivilID.inputValue}" label="civil id" id = "it1">
The setter setSearchCivilID() is called each time when i change the text in the field. (like - from "1" to "12").
But when I try to delete the text or totally remove the text , the setter method is not called and hence the previous value is retained in the property.
Can you guys help me out in this?
Thanks,
Haleem.
Tick the check box:" Notify listeners when property changes" while generating generating get() and set() . so when the value of the field changes it will fire the method propertyChangeSupport.firePropertyChange("<your_variable_name>",oldValue,newValue)
I have a field called StartDate, and the field's OnChange function has a loop similar to this:
Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
If (doc.Username = somevalue) Then
If (doc.StartDate(0) = specialdate) Then
' Do something here
End if
End if
Set doc = view.GetNextDocument(doc)
Wend
My problem is that doc.StartDate holds the new value of the field but I want the old one. How do I get the field's previous value? Basically I need to compare the field's old value with its new value.
Define a global variable like "StartDateOld" in form's (Global) / (Declarations).
Assign the value of field "StartDate" to this variable in PostOpen event.
You can use the old value in variable "StartDateOld" in OnChange event then.
Don't forget to set the changed value to "StartDateOld" at the end of OnChange event's code.
This works for a document in edit mode. I don't really understand what you want to achieve with your code running through the view though...
public HtmlComboBox NetworkSelectBox
{
get
{
HtmlComboBox networkSelectBox = new HtmlComboBox(ConfigVMPage);
networkSelectBox.SearchProperties[HtmlComboBox.PropertyNames.Id] = "vnic";
networkSelectBox.SearchProperties[HtmlComboBox.PropertyNames.Name] = "vnic";
networkSelectBox.FilterProperties[HtmlComboBox.PropertyNames.ControlDefinition] = "style=\"WIDTH: auto\" id=vnic name=vnic r";
return networkSelectBox;
}
}
Above is the code I define an UI element and I want to set the property
NetworkSelectBox.SelectedItem = "LabNetworkSwitch";
I've used this way on other elements and all success, but in this one i got the error message
Microsoft.VisualStudio.TestTools.UITest.Extension.ActionNotSupportedOnDisabledControlException: Cannot perform 'SetProperty of SelectedItem with value "LabNetwokrSwitch"' on the disabled or read-only control.
How can I change the control type?
I don't think you want to change the control type. I would suggest trying either waitforready() or find(). What is likely happening is when the control is initially found it is disabled, and find() will sync the actual control with the current networkSelectBox. WaitForReady() is probably the preferable method here though it will implicitly refresh the values of the combo box until it is available for input or the time out has expired.
I doubt you will run into this issue with HtmlComboBoxes but with a couple of WinComboBoxes I have had issues where they could not be set using SelectedItem or SelectedIndex. I ended up doing KeyBoardSendkeys(Combobox,"firstLetterOfItem") until the selected value was correct.
I have a long form that the user has to fill out.
So I broke the form into logical units and created another user control for some elements (they will be reused elsewhere).
So say the form has these fields:
UserControl3.ascx
Username
password
email -- usercontrol2.ascx
address -- usercontrol2.ascx
city -- usercontrol2.ascx
state -- usercontrol2.ascx
So now in the codebehidn of usercontrol3.ascx, how will I access the usercontrol2.ascx's fields so I can write to the db?
Something like this works, but it is just not elegant:
Dim txtBox as TextBox = Ctype(parentControl.Controls(Index), System.Web.UI.Controls.TextBox)
stringVariable = txtBox.Text
The correct way to do it is to implement properties for your parentControl that access child's controls properties.
Public Property AddressField() as string
Set(byval value as string)
txtAddressField.Text = value
End Set
Get
Return txtAddressField.Text
End Get
End Property
if user control 3 contains user control 2, I would modify the code for user control 2 to expose public properties for the information that you need to retreive.
edit
There are other ways of doing it, but the property route is the safest route, and avoids strong dependencies between the two controls.