C Builder TForm not allocated or created properly all its controls - forms

I'd like to know how I can check that all the controls on the form are created and initialized.
I have a form I am showing when a user presses the update button. It has only a TProgressBar control.
The handle is not NULL for this control and at random stages it can or can't set the Position/Max values.
When I set TProgressBar->Max value to some integer it remains 0 after.
So the question is:
How to really create the form and all controls on it (i am currently using just Form->Show() method, which as I can check calls the constructor)
Also I have following form creation code in main cpp file:
Application->CreateForm(__classid(TupdateProgramForm), &updateProgramForm);
How to check that all controls on the form are created and PAINTED (showed and visible)

In C++ Builder the form and the controls created at design-time are translated into binary objects through automatic scripts that produce Delphi code.
To view the originated Delphi code just right-click anywhere on form at design-time and select 'View as text'. This will show the Delphi source code of the form and it's controls.

After a form and all child controls created, the OnCreate event of that form invoked and you can place your initialization and checking code in this event, for example:
void __fastcall TfrmMain::updateProgramFormCreate(TObject *Sender)
{
ProgressBar->Max = 100;
ProgressBar->Value = 20;
}

Related

Custom Form Layout Validation

I want to have my own validation flow, with custom layout and message.
By default, the validation from the form builder put all the error message beside the input field. And it will validate all fields at once after submit.
I want to validate field by field after submitting, and error message is displayed in the same place for all the input fields (beside the submit button/on top of the form).
Currently I'm trying custom form layout with "ASCX" type. Is it possible to do all the validation in the back-end code ".cs"?
Or I must inject java script at the custom form layout design in source mode?
Or there is any better way to do it?
In HTML layout type you can place validation macros anywhere you need -> $$validation:FirstName$$
You can also specify a validation that executes without submitting the form - example -> http://devnet.kentico.com/articles/tweaking-kentico-(2)-unique-fields
Anyway, with the validation macro above you can move the error message wherever you want.
In your online form, go to Layout and enter your layout markup manually using HTML and the macros for form field values, labels and validation. There you can specify where all your form elements will go on the form, even the button.
If you want to have custom CS for your validation of that form, you're better off creating a custom event handler for the form before insert. See documentation below:
Custom event handler
Form Event handler
using CMS;
using CMS.DataEngine;
using CMS.OnlineForms;
using CMS.Helpers;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomFormModule))]
public class CustomFormModule : Module
{
// Module class constructor, the system registers the module under the name "CustomForms"
public CustomFormModule()
: base("CustomForms")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the Insert.After event
// This event occurs after the creation of every new form submission
BizFormItemEvents.Insert.After += Insert_After;
}
private void Insert_After(object sender, CMS.OnlineForms.BizFormItemEventArgs e)
{
if (e.Item.TypeInfo.ObjectType.ToLower().Contains("bizform.codename"))
{
//do some work or form validation
}
}
}

Disable a form if the other is updatable

I'm using page fragments to create a view and in the same page I have two forms to view / update specific information.
What I want know if it's possible to disable one form (or button, since it's the way I use to change from readable to updatable) based on if the other is in updatable mode.
Simplifying I have form A and B, both in the same page as readable. When I select A to update I want B to disable the option to edit until A is back to read mode, and the same to B form.
Can anyone help me?
---Update
Flows
A
B
In each fragment (view) I have a button that as an action to the fragment (edit)
What I need is to disable the button from B.view when A button is pressed and vice versa
If the forms are part of separate taskflows and these taskflows are used on the page as regions, then you will need to enable inter-region communication, so that an action in one region can affect the data and behavior of other region:
http://www.oracle.com/technetwork/developer-tools/adf/adfregioninteraction-155145.html
For your use case, contextual events can serve the purpose:
http://rohanwalia.blogspot.com/2013/07/contextual-events-basic-step-by-step.html
http://www.awasthiashish.com/2013/05/using-contextual-event-in-oracle-adf.html
https://blogs.oracle.com/raghuyadav/entry/refresh_bounded_taskflows_acro
To implement your case, follow the tutorials provided above with following changes:
Pass a boolean value in the customPayLoad of event
<event name="DisableButtonEvent" customPayLoad="${'true'}"/>
In the event handler method assign the payLoad value to a scope variable:
public void handleDisableButtonEvent(String payLoad) {
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
Map pageFlowScope = adfFacesContext.getPageFlowScope();
pageFlowScope.put("disableButton", payLoad);
}
Use the scope variable for disabled property of button on second region
<af:commandButton text="EditButoonB" id="cb1"
disabled="#{pageFlowScope.disableButton ne null? pageFlowScope.disableButton : false}"/>

Single select Tag in Touch UI

OOTB Tag has multi select functionality, Is it possible to create single select Tag in Touch UI? If yes, can you point me which js file I need to modify?
The cq:tags property is rendered by CUI.TagList widget that can be found within /etc/clientlibs/granite/coralui2/js/coral.js script.
Reading it you can learn that the widget raises itemadded event which might be helpful for you to handle the singular tag handling. An example function that can catch the event might be placed in any clientlibs that will be attached to the admin interface such as cq.authoring.dialog clientlib.
$('*[data-fieldname="./cq:tags"]').on('itemadded', function(ev, value) {
var el = $(ev.target),
div = el.siblings('div'),
input = div.find('input'),
button = div.find('button');
input.prop('disabled', true);
button.remove();
}
To have the fully functional flow you need to handle the itemremoved event as well and make the input field enabled again as well as add the button back to the widget.

refresh vb6 form in background without losing user entered data

I'm working with some old VB6 code and have a scenario I'm trying to correct. I have a form that allows you to enter a person ID (use renters this in a textbox at the top) and click "show" it lists the appointment in the textbox on the same form. There is also a button that loads a new form that allows the user to edit the displayed data and save the change.
E.g. Change persons age from 65 to 64. I make this change, and save it. The save is successful and I unload the form to return to Form1. However, I must click "show" again to refresh the displayed data in the textbox to ensure the change is visible. I cannot figure out how to refresh this form, so the user doesn't have to click "show" to repopulate the textbox with the new value. Can anyone assist? I can't just create a new instance of Form1, because if I did that the person ID field would be blank.
Thanks!
Short version: How do I refresh a form to get latest data while still obtaining the relevant person ID.
There's not enough information here to answer your question. The general pattern you'd use in this situation is as follows:
SearchForm launches ViewForm.
ViewForm launches EditForm. When ViewForm constructs its instance of EditForm, it passes Me to EditForm (perhaps by setting EditForm.Parent).
When EditForm's Save button click event fires, it calls Parent.ReloadData (where Parent is the ViewForm that launched the EditForm).
Here is the approach that should work. In the editor have a public property that returns whether the form was cancelled or not. (.Cancelled). You'll have an object that carries attributes of the person that you are trying to change the age of. Then it's pretty simple. Code in the main form:
dim oPerson as clsPerson
dim oFrm as frmAgeEditor
set oPerson = GetCurrentPerson()
set oFrm = new frmAgeEditor
with oFrm
set .Person = oPerson
.Show vbModal
if not .Cancelled then
' Update Main form with the contents of oPerson
end if
end with
You can just call in "Show" function right after updating.
Call Me.frmParent.Refresh
I used this to refresh the screen without losing data.
I had to dig through a lot of old code to figure it out. This section had been written a long time ago, and worked well.
Public Sub Refresh()
Call cmdDetails_Click
If tvwScreeningSchedule.Nodes.Count > 0 Then
tvwScreeningSchedule.SelectedItem = tvwScreeningSchedule.Nodes(1)
Call tvwScreeningSchedule_Click
End If
End Sub
It's quite a specific function, and "cmdDetails_Click" contains alot of custom validation, but it's not too dis-similar to AngryHackers answer.

Delphi XE3 form Open and Close

Can someone help me with this:
I have form 1 and form 2
in form1 1 :use form2.
in form1 put a button with code Form2.Showmodal;
form2 is made invisible
form2 has one button:
form2.close = works but does not close just hides the form.
-form2.free - either access violation or closes and the form1 is frozen (taskmngr to kill it)
Form2. release - acccess viololation or closes..if I click the open button on form1 to reopen the form it give access violation..
Form2.close + onClose action :=cafree; - access violation..
Form2.closemodal - has no effect..
how can I dispose and reuse form2 which is shown as modal from form1 ?
thanks a bunch..it has to be something simple Im overlooking.
s
form2.close = works but does not close just hides the form.
Yes, it does close the form. That is what the default behavior of a closed form is - to hide itself. In the case of a modal form, Close() merely set's the form's ModalResult to a non-zero value, which causes ShowModal() to exit and close/hide the form.
form2.free - either access violation or closes and the form1 is frozen (taskmngr to kill it)
It is not safe to Free() a form from inside of an event handler belonging to the same form. The VCL still needs to access the form object after the event handler exits. To safely free the form, you have to use Release() instead, which signals the form to automatically free itself at a later time when it is safe to do so.
Form2. release - acccess viololation or closes..if I click the open button on form1 to reopen the form it give access violation..
The only way Release() can cause an AV is if you are calling it using an invalid form pointer. If re-opening a form causes an AV, then you have some serious bugs in your code.
Form2.close + onClose action :=cafree; - access violation..
caFree causes the form to call Release() on itself. See above.
Form2.closemodal - has no effect..
You are not supposed to call CloseModal() directly. Use Close() or set the ModalResult instead.
First, remove Form 2 from auto-creating.
Project > Options > Forms
Remove Form 2 from "Auto-create forms"
This makes sure that this form is not automatically created.
When you create an instance of it, do not refer to it by its name (such as Form2). Instead, create a temporary variable. If you want to show it in the modal state, do it something like this:
procedure Button1Click(Sender: TObject);
var
F: TForm2;
begin
F:= TForm2.Create(nil);
try
F.ShowModal;
finally
F.Free;
end;
end;
Don't refer to your form by any name you may have given it, such as Form2. If you instantiate it as another variable as demonstrated above (with F), then make sure all calls you make to it are through this variable. In fact, as long as you remove this form from the auto-created forms, you may completely remove the declaration to this form:
var
Form2: TForm2;
If you want it to show in a non-modal state, while the main form is still accessible, it has to be done quite differently. Let me know if that's what you need, and I'll adjust my answer.
//this script for showing Form through Button with position
//change position by changing left or top by changing 120 and 300
//in Delphi 10.3 and above
// add form2 unit name in main unit in implementation as uses
//example
//implementation
//uses main;
procedure Button1Click(Sender: TObject);
var
F: TForm2; // Desired Form for Calling or showing
begin
F:= TForm2.Create(nil);
try
F.Left :=left+120; //Left position of Desired Form
F.Top :=top+300; //Top position of Desired Form
F.ShowModal;
finally
F.Free;
end;
end;