Delphi - Form Properties empty on FormCreate when set from other Form - oop

Here is an interesting case.
Have the Login Form, where some variables values are set, like company_id and SelectedlanguageCode, the idea is to pass this values to the MainForm properties to make things fast (selected language code go to Database to query), this values will be immediately required in the FormCreate Event, but here the values are missing, but debugging after the CreateForm-event the values just show.
Here is the Project Source Code:
{$R *.res}
Var
LoginOK: Boolean = False;
sCompanyId: integer;
sSelectedLanguageCode: string;
begin
// The login form is created and show up
// --------------------------------------
fLogin := TfLogin.Create(nil);
try
// Show login form. When it closes, see if login worked.
fLogin.ShowModal;
LoginOK := fLogin.CanLogin;
sCompanyId := fLogin.pCompanyId;
sSelectedLanguageCode := fLogin.gDefaultLanguageCode;
finally
fLogin.DisposeOf;
end;
if not LoginOK then
Halt; // Login failed - terminate application.
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TfMain, fMain);
// Here the properties of Main are set with the values,
// when debugging the properties get the values, you can
// see the actual values when hovering over the property
fMain.gSelectedLanguage := sSelectedLanguageCode;
fMain.gUserCompany := sCompanyId;
Application.Run;
end.
But as mentioned, in the CreateForm of Main, the properties are empty...
And... after CreateForm event, the properties have the actual value.
I need this values in CreateForm event because some methods will be invoked and need to send them...
I appreciate the answer about what is going on to understand what am I doing wrong, or if that have a good reason to be just like that then... if you can give me another approach to solve this requirement, thanks.

OK, so instead of having your initialisation code in the formCreate, move it all to a method on the main form (e.g. init()).
then in the line before you application.run you can have
mainform.init;
or
mainform.init(sSelectedLanguageCode, sCompanyId);
I always split out creation from initialisation. If the form is shown and isn't initialised you can raise an error then. i.e. in the onShow, if no company ID - tell the user there was an error and close the app....

Related

Why does NavigationView.ContainerFromMenuItem() return null except when executed from an event handler?

I am developing a WinUI3 app containing a NavigationView. The NV uses an observable collection to populate the NavigationViewItems.
The app must support expanding and collapsing NavigationViewItems programmatically. The only way I know of to do that is to set NavigationViewItem.IsExpanded = true. And the only way I know of to get the NavigationViewItem is through NavigationView.ContainerFromMenuItem().
The trouble is, ContainerFromMenuItem always returns null except when it is executed from a button event handler (such as a Click handler). The app must perform expand/collapse without user input.
For example, I have a button that launches a Click event with this code, which works just fine to toggle an NVItem:
Category selectedItem = (Category)navview.SelectedItem;
int idx1 = Categories.IndexOf(selectedItem);
var container = (NavigationViewItem)NavView.ContainerFromMenuItem(Categories[idx1]);
if (container != null)
{
container.IsExpanded = !container.IsExpanded;
}
However, that same code, when executed during app startup, such as in the MainWindow constructor after some test items are created, or in Attach(), always results in container being null.
So what am I doing wrong?
This question is somewhat similar to UWP: NavigationView.MenuItems results empty if populated programmatically but the answer to that one only deals with in-event use of ContainerFromMenuItem().
Thanks very much for any assistance on this.

Form reset for all fields except one Vue.js

I'm trying to find a way to to exclude one field input in my form that is disabled and contains the value of a users ID number
I would like to know how I can tweak this.$refs.form.reset(); because it works perfectly but it clears EVERYTHING and I wish to contain the ID value and resets the rest of the fields like name surname age income etc
The reason why I the ID is important is that the user gives this in a sign-up step at the start and this form that I am talking about is located somewhere else to complete his profile I don't want to ask the user again to type his ID in again.
If anyone knows how to accomplish this it would be a great help
The reset method of the form simply looks at all the inputs bound to it and resets each one within a loop then empties the error bag, observe:
reset (): void {
this.inputs.forEach(input => input.reset())
this.resetErrorBag()
},
There's no reason you can't do the same, except for when they're disabled:
resetForm() {
this.$refs.form.inputs.forEach(input => {
if (!input.disabled) {
input.reset()
}
})
this.$refs.form.resetErrorBag() // necessary to remove validation errors after the field values are removed
}
Then you can call that function (against your Vue instance, not your VForm) with this.resetForm() and it should work out the way you want.
Disclaimer: Can't test it at the moment. input.disabled may not be readily available and may require further inspection of the input element.

Apex, Dynamic action, Confirm action, not picking up correct text - what am I missing?

I'm obviously missing something and hoping someone might be able to help.
I've an Interactive Grid, and a button.
When the button is pressed the dynamic action on the button has 2 steps.
Action 1 - Execute Javascript to take a value from one of the IG cells and put it into a page item.
Action 2 - Confirm Action - Are you sure you wish to delete &P10_JOB_ID.
I've made the page item, &P10_JOB_ID, visible and I can see the value has correctly been changed to the value from the IG.
I write P10_JOB_ID into a database table - I get the correct value
But the confirm message isn't picking up the correct value from P10_JOB_ID.
Namely it uses the value in P10_JOB_ID when the page starts, but then as I move around the IG pressing the button and changing the value of P10_JOB_ID, the text in the confirm message never changes.
Can anyone suggest what I might have missed, I'm baffled.
Thanks a lot
Substitutions like &P10_JOB_ID. are made when the page is rendered, not dynamically, so reflect the value at time of page load.
You will need to use Javascript to perform the conform action, something like:
apex.page.confirm ('Are you sure you wish to delete ' + $v('P10_JOB_ID') + '?', 'DELETE');
$v is an APEX Javascript function that returns the current value of a page item.
I used 'DELETE' as an example of a request value; you may want to do something different here.
Ok - having the setting of value and confirm as 2 separate actions is what causes the problem.
As per fac586
That is the expected behaviour. Static text substitutions are performed once during page show processing. They are not evaluated dynamically in the browser at runtime as values change.
Drop the second action and extend the first to display the confirm dialog using the apex.message.confirm JS API method, accessing the item value using the $v shorthand method.

How should a test be written for a delegate for editing?

I have a tree view for which some fields need to use a custom delegate for editing. The delegate presents a QListView for value selection. It seems like the QAbstractItemView.edit() method should be used to initiate the edit from the test but I can't figure out how to get access to the created editor (a QListView) so I can select the proper element for the test.
This is part of a test I had working with a QComboBox delegate before switching to the QListVew, but it seems too manual.
for index, enumerator in enumerate(group.children):
editor = delegate.createEditor(
parent=viewport,
option=None,
index=target_index,
)
editor.setCurrentIndex(index)
delegate.setModelData(editor, model, target_index)
assert enumerator.uuid == item.enumeration_uuid
https://github.com/altendky/st/commit/643c5c30f87fc3bfd8b422687e81f740ec36ef44#diff-06bc81dbbd9f7a12878169d5238e1572R846
Here is what I came up with.
https://github.com/altendky/st/blob/089432162b9e8ca67eafdfcc2a4ecc34e8f0e96e/epyqlib/tests/test_attrsmodel.py#L848
for row, enumerator in enumerate(group.children):
assert view.edit(
target_index,
PyQt5.QtWidgets.QAbstractItemView.AllEditTriggers,
None,
)
editor, = view.findChildren(PyQt5.QtWidgets.QListView)
index = editor.model().index(row, 0, editor.rootIndex())
editor.setCurrentIndex(index)
editor.clicked.emit(index)
# this is fun. if you get weird issues try doing this more times
for _ in range(3):
application.processEvents()
assert enumerator.uuid == item.enumeration_uuid
Do note that I connect the editor's clicked signal to post an enter-key event since the view's are hardcoded to catch an enter event and finish editing.

Oracle APEX 5 Dynamic Action upon page load event does not work. What am i doing wrong?

The program basically aims at retrieving some fields of a record and processing and displaying that on a textbox of static content region in apex 5
My database: LCD_MONItOR table
Interface :
PLSQL code that is supposed to execute on page load event.
Declare
lcd_id LCD_Monitor.LCD__NO%TYPE;
tag LCD_Monitor.ASSET_TAG%TYPE;
pp LCD_Monitor.PURCHASE_PRICE%TYPE;
sal LCD_Monitor.SALVAGE%TYPE;
ls LCD_Monitor.LIFE_SPAN%TYPE;
accm LCD_Monitor.ACCUMULATED_DEP%TYPE;
netbook Number;
currDep Number;
Begin
select LCD__NO, ASSET_TAG, PURCHASE_PRICE,SALVAGE, LIFE_SPAN,
ACCUMULATED_DEP into lcd_id, tag, pp, sal, ls, accm from LCD_MONITOR
where LCD__No='40';
:LCD_NO:=lcd_id;
:CURR_DEP:= (pp-sal)*(1/ls);
:TOT_DEP:= (pp-sal)*(1/ls)+accm;
:NBV:=pp-(pp-sal)*(1/ls)+accm;
End;
PS: I have returned the values to the textboxes in 'Affected Elements' Section in the properties.
But when the page is loaded, no values appear in the textboxes. Any help would be appreciated.
I'm not sure if I understood correctly what exactly are you doing. If you need just fill items with data, create a before header process (in Page Designer mode, it is in Pre-rendering -> Before Header. Write your code there, it should be enough.
If you want to do it in Dynamic Action (I wouldn't recommend this way), you need to create a Dynamic Action with Event - Page Load, which will contain a True Action with properties: Action - Execute PL/SQL Code, PL/SQL Code - your code and Items to Return - LCD_NO,CURR_DEP,TOT_DEP,NBV
But make sure your items really have such names, because by default APEX creates items with names like P10_LCD_NO, where 10 (for example) is a number of the page.
Instead of directly assigning a calculated value to the textfields items, I assigned them to a variable first then assigned variables to the items i.e
Before
:CURR_DEP:= (pp-sal)*(1/ls);
:TOT_DEP:= (pp-sal)*(1/ls)+accm;
:NBV:=pp-(pp-sal)*(1/ls)+accm;
Corrected
currDep:= (pp-sal)*(1/ls);
:CURR_DEP:= currDep;
tot:= (pp-sal)*(1/ls)+accm;
:TOT_DEP:=tot;
netbook:=pp-((pp-sal)*(1/ls)+accm);
:NBV:=netbook;