X++ unbound control - x++

I'm new to X++, and I want to put an unbound
checkbox on a tab in the sales header form
(SalesTable). When the configure line button is
pressed on the bottom half of the form for a sales
line, I need to have code in that other class
check the on/off status of the unbound control in
the SalesTable form and do something. I really
don't need the database to record the status.
The current status is I've placed the checkbox on
the form, see it on the display and can click it,
but can't refer to it.
How do I refer to the unbound
control in the SalesTable form from another class
and, is this the right approach?

You don't refer to the unbound control from another class, it is not the right approach.
Rather inform the other class when the unbound control is changed. You do that in the modified method of the checkbox control:
boolean modified()
{
boolean ret = super();
;
salesTableForm.parmSpecialAction(this.value());
return ret;
}
In this case the SalesTableForm is informed of the change of the checkbox by calling a method parmSpecialAction (name arbitrarily chosen).
The other route (you indicated in the question) would be to inform the class about the existence of the control and let the class call control.value() directly. However this will usually make the form and the class tightly coupled, which is not what we want. The controls belongs to the form where they were born and should not be passed around.
Ironically the SalesTableForm.enableUpdateJournalButtons method violates this rule, as it accepts button controls as parameters. The correct approach would be to calculate (and cache) the enableWathever values in getter functions, then let the form call the getters and enable or disable its own buttons.

Related

Unknown symbol 'textbox1' in class container-gambas error

I had copied data from one form to another previously and it worked bt right now when I am trying to copy the detail of field 'PASSPORT' from login.form to from_to.form it shows an error.
here's the login.form
and here's the from_to.form with error
Controls are not properties of their forms, and moreover they are not (by default) public.
In other words, you access controls by using a global variable having the same name as the control, and only from inside the form, as that global variable is private.
As mentioned above the controls are private to each form and not visible to each other unless you make them public.
You are trying to access login.TextBox1 from another class.
To access login.TextBox1 from the from_to.class you must do one of the following...
In the IDE on the login form select TextBox1 and set it's Public property to True.
or..
Open the project properties and select the "Make all controls public" option. this makes all controls visible across all forms.

Delphi Object Pascal corresponding run-time calls of TBindNavigator

My question is about Delphi Object Pascal corresponding run-time calls of TBindNavigator component buttons.
I'm interesting of the following buttons:
"Post";
"Cancel";
"Refresh".
How can I implement it in the code without TBindNavigator?
Would you please clarify this issue?
Thanks.
If you wish to implement the necessary actions with simultaneous check if they are enabled etc. then you do not need TBindNavigator at all. The easiest way is the following:
The sample for an FMX Form:
Add a TActionList to your form.
Add a New Standard Action form LiveBindings node of necessary TFMXBindNavigatePost, TFMXBindNavigateCancel etc. class.
Select this action and set Datasource property.
Assign the action to the necessary TButton or other control.
Steps 2-4 can be done in the other way as well.
Selet the control (i.e. TButton), select property Action and click the arrow on the right.
Select New standard action then LiveBindings. Select the necessary class TFMXBindNavigate*. The action will be assigned to the TButton.
Select TActionList and choose the added action and set DataSource property.
The action will be kept up-to-date by LiveBindings. The necessary controls will become Enabled-Disabled and will act as buttons of TBindNavigator.

Having button that runs code, but doesn't submit data to (or validates against) table

I'm trying to add a button to an existing form (BankAccountTable). I want to add a button to run an outside process with the value of one of the form fields as a parameter.
The value is being read using this code:
str value = element.design().controlName("FieldName").valueStr();
However when I click the button Dynamics displays what fields must be filled in. This doesn't happen if the click method doesn't reference the form fields (i.e. info("click");).
How can I:
Read the value of a field without triggering form validation?
and/or
Have a button (or command buttton) that doesn't trigger form validation?
The second question, how to avoid validation, is easy: set the button attribute SaveRecord to No.
You should rarely need to access the control value directly. A better option is usually to access the bound field directly: table.FieldName.
If the control is not bound to a field, then change the AutoDeclation attribute to Yes and access the control directly: fieldName.text(). The methods text, realValue or selection is a better choice than valueStr.

Delphi: Can we use metaclass reference to access properties at runtime or designtime?

The question arises from the need to reuse a code for different types of objects.
Scenario:
Drag and Drop in listboxes either from a different listbox or same.
above question arises, when i try to implement drag and drop in same control.
the user can rearrange items in a listbox by dragging them up or down.
I have written the logic, it works.
The problem is, in my app, i have used different kind of listboxes as per requirement.
So their type gets changed. in order to use the same code for drag and drop,
when the source and sender is same, i typecasted different list-boxes to the common ancestor TCustomListBox
and then sent that to the function which performs the moving of items.
The function swaps the items from the items collection to their new positions.
Now particular scenario:
i have used a checklistbox which has a checkbox associated with each item.
It so happens, that with each item, there is an object of checkstate associated.
Now in the function, for moving items, i use a tstringlist for temporary storing the items
and their objects and then delete them from the control and then reinsert them in the control.
but in case of this checklistbox, when i delete an item, the item gets deleted,
but its corresponding checkstate object remains and it gets associated to the next item,
which is not desired.
so right now i am using an int variable as a mode indicator for normal,
and special dragdrop.
when it is special, as in case of checklistbox, i typecast it to tchecklist and
then access its delete method which removes item alongwith its checkstate.
So instead of using an int as a mode, i was wondering,
whether i can use a class reference of the base class of all listboxes and
then how can i access the properties of a particular listbox type, if the need arises.
the above solution, is not optimum, thats why, i need a more generic and proper way.
See if you can help. thanks. and thanks for the advise, i do care for this community, i am not used to editing features. sorry.
i am using delphi 6.
The declaration for the function is as follows :-
DragDropItemsInListBox(p_HostIndex : Integer; p_HostListBox : TCustomListBox;
p_Mode:Integer);
call:-
the hostindex is the drop site index, hostlistbox is the control on which the item will be dropped,
in this case, the source control and destination control is same,
and mode indicates the way of deleting.
DragDropItemsInListBox(3,TCustomListBox(Source), 1);
if the mode is 0 then i delete items normally as in:-
p_HostListBox.items.delete(i);
if it is 1, which indicates special processing,
in this case as i know what to do, therefore i use,
if p_Mode = 1 then
(p_HostListBox as TRzCheckList).items.delete(i);
this removes the item alongwith the checkstate object.
but i dont wanna rely on this int based differentiation.
can i use metaclasses and if i normally call items.delete,
then will it apply to that specific type?
therefore i use, if p_Mode = 1 then (p_HostListBox as
TRzCheckList).items.delete(i);
this removes the item alongwith the checkstate object. but i dont
wanna rely on this int based differentiation. can i use metaclasses
and if i normally call items.delete, then will it apply to that
specific type?
You can not use metaclass variable - the metaclass pointer is the same for all the objects of the type. If Delphi allowed that - would have no way to know which of checklists to delete from.
However using int is poor solution indeed.
if p_HostListBox is TRzCheckList
then TRzCheckList(p_HostListBox).items.delete(i);
Sidenote: in Component Pascal there would be even more sugar: IS
implies AS there: if p_HostListBox is TRzCheckList then
p_HostListBox.items.delete(i);
Probably yet better approach to read help about RzChkLst.TRzCheckList.Items - that is property of TStrings type.
Modify the declaration
procedure DragDropItemsInListBox(p_HostIndex : Integer; p_HostListBox : TCustomListBox; p_Items : TStrings);
Call it like DragDropItemsInListBox(0, RzCheckList1, RzCheckList1.Items);
And in procedure do
p_Items.Delete(i);

Difference between setModel( ) and getModel( ) in tabbed panes

What is the actual difference between the terms setModel() and getModel() in tabbed panes (for blackberry).
BB docs notices these as being:
getModel()
Returns the PaneManagerModel associated with this view.
Does this mean i get to access the methods and variables of code inside the pane associated with that model?
setModel()
Lets you associate a PaneManagerModel with this view.
Does it only give access to set the usage of that pane for display in another pane?
Re edit:
I have used this piece of code to invoke method held inside another pane from first pane and now i want to refresh the display.But dont know how.Please guide.
model.getController().getModel().getPane(1);
//model.getPane(1).getPane().getScreen().getUiEngine().updateDisplay();
model.getPane(1).getPane().getManager().invalidate();
What to use get or set?
getModel() is a function that returns the PaneManagerModel field of the view.
setModel() allows you to set a PaneManagerModel field for your view.
This is a standard OO set/get situation. Here is a demonstration of it (so you get what it actually is, it doesn't necessarily work exactly like so)
public class View
{
private PaneManagerModel model;
public PaneManagerModel getModel()
{
return model;
}
public void setModel(PaneManagerModel me)
{
model = me;
}
}
Edit: use set. Get only lets you get what is inside. If you want to put something new in, use set. If you want to trigger code that is only executed while you're setting but you want to keep the same PaneManagerModel use setModel(getModel()); though it is ugly.
Wrong and wrong
getModel gets you the underlying PanelManagerModel. The Model handles data, and is totally separate from methods / code in the pane
setModel lets you set the underlying datamodel of your panel, but has nothing to do with display, except for setting the elements to be displayed.
This is strictly about the data items in your tabbed pane
It's all related to the concepts of "setter" and "getter".
A "Setter", which in this case is setModel(), lets you set a new Model on the View. On the other hand a "Getter" allows you to obtain a certain property of a certain object. In this case the getter gives you access to the currently set Model of the View.

Resources