REALBasic Questions - realbasic

In REALBasic, how do I loop through all of the objects in Window1? Is there some array property of Window1 with all of its children? Also, how do you set custom properties of objects: e.g. Me.isFlamingo = true
Thanks in advance!

Adding properties to a built-in class like a pushbutton can be done in two ways. The better way would be to subclass the PushBustton class and to add properties to the subclass like you would with any custom class. The other, somewhat uglier way would be to use a pair of overloaded functions like this:
Function isFlamingo(Extends ByRef pb As PushButton) As Boolean
Dim flamingo As Boolean
//Do stuff to figure out if the PushButton is Flamingo-y
//and Return a Boolean based on the result
Return flamingo
End Function
And:
Sub isFlamingo(Extends ByRef pb As PushButton, Assigns b As Boolean)
If b Then
//Do stuff that makes the PushButton flamingo-y
Else
//Do stuff that makes the PushButton not flamingo-y
End If
End Sub

To iterate through the controls on a window, use code like this:
ListBox1.DeleteAllRows
For i As Integer = 0 To Self.ControlCount-1
ListBox1.AddRow(Self.Control(i).Name)
Next
(For this example, be sure to add at least one ListBox to the Window.)
Properties are set just like you describe: ObjectInstance.PropertyName.
If you are in the event of an object that has been dragged to the window, then you can modify its properties using Me.PropertyName. Otherwise you would use the object name.

Related

passing control indexer by reference to method to change its property

i have made a program, which include a lot of controls. The controls would be showed and hided according to the choice of the user. That means that controls overlapped on each other at design time. now i want to change the forecolor and backcolor of all controls at design time. but i founded so hard to accomplish this task, because all the control overlapping each other. so I decided to make a for loop method to iterate the controls in the form and then check each control in turn whether it has controls. when the control has also controls in it, I call the same method and pass the control to it to change the properties for the subcontrols too. The method like so:
void setColor(ref Control con)
{
con.BackColor= System.Drawing.Color.Black;
con.ForeColor=System.Drawing.Color.Yellow;
if (con.Controls.Count > 0) { setColor(ref con); }
}
so my Form include tabControl with multiple tabPages. I iterate the tabPages and wanted to pass it to this method, but I become error "Indexer may not be passed as an out or ref parameter"
I pass it so: setColor(ref tabControl1.Controls[i]);
can you please help me to solve this problem?
I have resolved the problem.
I have removed the "ref" from method and wrote the method simply like the following:
void SetColor(Control con)
{
con.BackColor = System.Drawing.Color.Black;
con.ForeColor = System.Drawing.Color.Yellow;
if (con.Controls.Count > 0)
{
for (int i=0; i<con.Controls.Count;i++)
SetColor(con.Controls[i]);
}
}
and call it so: setColor(this.Controls[i]);

Disable MDI child Form buttons

Is there possible to disable child's form buttons from parent form?
For example, I have 2 radio-buttons in parent form, one is True second False, when I choose one of them fires radiobutton.CheckedChanged event and there I have code what goes like this, but it's not working:
ChildForm.Button1.Enabled = False
where seems to be the problem? Can anyone help with this?
You would need to create an instance of the childform.
So...
ChildForm cf = new ChildForm();
cf.Button1.Enabled = false;
You have to keep in mind though, it could be a different instance than the child form that is currently being shown.
To be sure, depending on your code (which I can't see) and how your program is laid out I would probably do something like this...
ChildForm cf = new ChildForm();
cf.show();
cf.Button1.Enabled = false;
so here I know that the ChildForm that is showing is the one that has the button disabled.
In VB6 the following project works:
1 MDI form:
Option Explicit
Private Sub MDIForm_Click()
Form1.Option1.Enabled = False
End Sub
Private Sub MDIForm_Load()
Form1.Show
End Sub
Form1 is a MDI child form with 2 radio buttons on it

How do I use ExcelDNA to select a cell?

I want to force the focus onto a particular cell, which I have a reference for via XlCall.Excel(XlCall.xlfCaller). I know how to do this in VSTO, but is there a way to do it with ExcelDNA?
One way would be to use the COM Automation interface, as you would from VBA or VSTO. Just be sure to use the Application object you get from ExcelDnaUtil.Application as your root. To convert from the ExcelReference that you received from xlfCaller to a COM Range object, you might try (this is the VB.NET version):
Private Function ReferenceToRange(ByVal xlRef As ExcelReference) As Object
Dim strAddress As String = XlCall.Excel(XlCall.xlfReftext, xlRef, True)
ReferenceToRange = ExcelDnaUtil.Application.Range(strAddress)
End Function
If you want to stick with the C API, you'd first have to select the right sheet, then the actual cell. So you might have:
string myCellSheet = (string)XlCall.Excel(XlCall.xlSheetNm, myCell);
XlCall.Excel(XlCall.xlcWorkbookSelect, new object[] { myCellSheet });
XlCall.Excel(XlCall.xlcFormulaGoto, myCell);
You won't be able to change the selection in a worksheet function, so I presume you are calling this from a macro or ribbon handler.
It's possible to do with ExcelDNA:
var activeCell = new ExcelReference(5, 5);
ExcelAsyncUtil.QueueAsMacro(() => XlCall.Excel(XlCall.xlcSelect, activeCell));
"ExcelAsyncUtil.QueueAsMacro" could be skipped, it's depends on context from which you call Excel command. If you call it from another Excel function - you should wrap it up with QueueAsMacro

Scope for Actionscript 2.0 Event

I'm using Actionscript 2.0 for a mobile phone and can't get my head around Events.
I'm creating a class object with all my code and using a group of functions (all as direct 1st level children of the class). There's one function that creates a Movieclip with a square on it and sets the onPress event to another function called hit:
public function draw1Sqr(sName:String,pTL:Object,sSide:Number,rgb:Number){
// create a movie clip for the Sqr
var Sqr:MovieClip=this.canvas_mc.createEmptyMovieClip(sName,this.canvas_mc.getNextHighestDepth());
// draw square
Sqr.beginFill(rgb);
//etc ...more lines
//setup properties (these are accessible in the event)
Sqr.sSide=sSide;
Sqr.sName=sName;
//setup event
Sqr.onPress = hit; // this syntax seems to lead to 'this' within
// the handler function to be Sqr (movieclip)
//Sqr.onPress = Delegate.create(this, hit);
//I've read a lot about Delegate but it seems to make things harder for me.
}
Then in my event handler, I just cannot get the scope right...
public function hit(){
for (var x in this){
trace(x + " == " + this[x]);
}
//output results
//onPress == [type Function]
//sName == bSqr_7_4
//sSide == 20
trace(eval(this["._parent"])); //undefined
trace(eval(this["._x"])); //undefined
}
For some reason, although the scope is set to the calling object (Sqr, a Movieclip) and I can access properties I defined, I can't use the 'native' properties of a Movieclip object.
Any suggestions on how I can access the _x, _y and other properties of the Movieclip object that is pressed.
Use the array accessor or the dot accessor, but not both. For example:
trace(this._parent); // OR
trace(this["_parent"]);
As for the results of your iteration, I recall AS2 being screwy on this front. IIRC only dynamic properties are returned when looping with for ... in. This prevents Objects (which often serve as hash maps) from including their native properties when all you want are the key/value pairs you set yourself.
Also - the eval() function can be easily overused. Unless you absolutely must execute a String of AS2 that you don't have at compile-time I would recommend avoiding it. Happy coding!

GUI update issue in J2ME

Let's say I have two forms: form1 and form2.
After pressing a NEXT_COMMAND in form1, I need to change the value of the gauge in form2 and then show form2. Thus:
public void commandAction(Command command, Displayable displayable) {
....
else if (displayable == form1) {
if (command == NEXT_COMMAND) {
form2_gauge.setValue(value);
display.setCurrent(form2);
}
....
}
....
However, this doesn't work as I expected it to. It doesn't change a thing at first. On the other hand, if I go back from form2 to form1 and then again from form1 to form2 it would work.
I can't figure it out myself. I'd be enormously grateful of any possible help.
Thanks!
It seems to me that form2.gauge isn't correct here. You have to save the Gauge object like this:
Gauge form2_gauge([...]);
form2.append(form2_gauge);
Then your code would be:
[...]
form2_gauge.setValue(value);
display.setCurrent(form2);
[...]
Have you tried another sequence? Like this:
display.setCurrent(form2);
form2_gauge.setValue(value);
I don't think it would change anything, but may make it work.

Resources