lazarus form creation - forms

The following code is from http://wiki.freepascal.org/MySQLDatabases
procedure TFormTryMySQL.OpenQueryButtonClick(Sender: TObject);
begin
ShowQueryForm := TShowQueryForm.Create(self);
ShowQueryForm.Datasource1.DataSet := SQLQuery1;
SQLQuery1.SQL.Text := CommandEdit.Text;
SQLQuery1.Open;
ShowQueryForm.ShowModal;
ShowQueryForm.Free;
SQLQuery1.Close;
end;
I'm new to Lazarus. Can someone please explain the line ShowQueryForm := TShowQueryForm.Create(self);? I'm particularly curious about:
Why do we need to CREATE a form programmatically?
What is the TShowQueryForm?
My form is without a T. How come the SQLQuery1
control can access the data on the new form?
I'm sorry if this is not a well-phrased question but I AM confused here :(
Thanks!

1. Why do we need to CREATE a form programmatically?
It's optional. You can let forms autocreate, as vfclists says, in which the designer adds the form creation to the LPR. (just like Delphi btw).
2. What is the TShowQueryForm? My form is without a T.
The type of the form. So you have a variable name xxxsomeForm with Txxxsomeform as its specific type.
3. How come the SQLQuery1 control can access the data on the new form?
Other way around. The grids, or whatever db aware controls are in showqueryform get their data from a datasource object. In the 2nd line:
ShowQueryForm.Datasource1.DataSet := SQLQuery1;
the sqlquery component of the current form is assigned to the dataset on the newly created form.

If the form is automatically created in the Project | Forms Auto-Create sas one which is automatically created when the application starts there is no need to create it.
The fact that the form being displayed is a Modal form, means it is like a dialog which is not created automatically, but only on demand.

Related

how to initialize a form created with designer in delphi?

how to initialize a form if for example i have one form created with designer and i want a second form that would be seperate but work as my full screen. the second form also has parameters that i want to write to but i get access violation.
Im currently trying to access these second form variables in first form's formcreate method. but like i said i get access violation so im guessing i need to initialize the second form to access variables in that form but i dont know how to do it, and where is the appriopriate way to do it
You're doing it wrong. You should not have one form's initialization be dependent on another form's existence. You should do one of three things:
1) (Preferred) Move the fields out from TForm2 to a non-form CLASS defined in a UNIT that you include in both Form1.PAS and Form2.PAS, and that you then create from within your TForm1.FormCreate
2) (Only if you can't do 1) Delay accessing Form2's fields until Form1's OnActivate, and ensure that OnActivate is only called once:
PROCEDURE TForm1.OnActivate(Sender : TObject);
BEGIN
OnActivate:=NIL;
<Access Form2.Field>
END;
3) (Only if 1 or 2 is undoable) Instantiate Form2 wihtin Form1's FormCreate (and remove it from auto-created forms):
PROCEDURE TForm1.FormCreate(Sender : TObject);
BEGIN
Application.CreateForm(Form2,TForm2); // Or Form2:=TForm2.Create(Application);
<Access Form2.Field>
END;
Of these three options, 1) is absolutely preferable...

Do you want to made changes in oracle forms

I trying to update the existing fields through the forms and click on the SAVE(from the Main Menu), that time i want to show Alerts/Messages 'Do you want to made changes? Yes or No?" Can you please help me, how to use this ? What triggers to use , i set the properties of the Updated Items , Values are getting effected into the Table, But i want a messages please help
I checked all code like :System.Message_Level := '20';
My Database tables data are effected,I don't want any button,i want triggers to save the records
You need to have Key-Commit form level trigger. In that trigger you write logic to show alert. The built in is Show_Alert(), if I remember this correctly. You need to create alerts under Alert(s) node in Forms builder. The alert can have one or up to 3 buttons. Check Show_Alert() in Forms help - Forms Builder -> Help. You can copy paste code from there. It is very easy to figure out. I do not remember exact syntax...
Declare
al_button number;
Begin
IF :System.Form_Status = 'CHANGED' THEN
al_button := Show_alert('SAVE');
IF al_button = alert_button1 THEN
Commit_Form;
END IF;
END IF;
End;
I have written in the KEY-COMMIT Trigger at the Form Level...

Reusing the CQ5 Form into the mywebsite components is not showing up the End of the Form section

I am trying to reuse the Form into my project components.
I have copy pasted the entire form folder from "/libs/foundation/components/form" to my project "/apps/mywebsite/components/form".
But when i am trying to use the form from mywebsite in the parsys the from shows only Start of the from.
Where as when i tried to use the form from the foundation in the same page parsys it shows both Start and End of the form.
Observation:
From the content, when i am using the foundation form the in the page content i can see the start and end nodes. where as when i am using the mywebsite form start node alone is created.
The form end is added/deleted by the fixStructure() method of the FormParagraphPostProcessor class. This post processor listens for creation and deletion of form start and form end paragraph and creates/removes the other paragraphs accordingly.
if ( ResourceUtil.isA(res, FormsConstants.RT_FORM_BEGIN)
|| ResourceUtil.isA(res, FormsConstants.RT_FORM_END)) {
if ( FormsHelper.checkFormStructure(res) != null ) {
logger.debug("Fixed forms structure at {}", contentResource.getPath());
}
}else {
fixStructure(res);
}
This class depends on the FormConstants.java where the form start(RT_FORM_BEGIN) and the form end(RT_FORM_END) are defined as "foundation/components/form/start" and "foundation/components/form/end" respectively. Due to this the post processor doesn't process the form start / end that is present within your project.
To make your custom form component working you may consider one of the following possible options:
Add the sling:resourceSuperType property for your project form start as "foundation/components/form/start". This would create a form end, but it would be of type foundation/components/form/end and not your project form end.
In case you do not want the default form end but your custom form end, then you may need to create a custom post processor which listens to your form start and end and fix the structure accordingly. This requires modifying few other java classes like FormsHelper.java etc, as they are also dependent on the FormConstants.java. Also make sure that the imports in the start.jsp are changed accordingly.
Finally, if you do not want to create custom classes, you can copy the default form start to "/apps/foundation/components/form/start" and make your modifications on top of it. But you need to be careful while using this approach as this is a global change and would affect the other projects that are using the default foundation form start.

Delphi: positioning a form in a dll

I am creating a form in a dll. No packages. The form in the dll is called by using the exported procedure:
procedure ShowAbout(const AppHandle: THandle); stdcall;
var
aHandle: THandle;
form: TfrmAbout; / my form in some other unit in the dll
begin
aHandle:= Application.Handle;
Application.Handle:= AppHandle;
form :=TfrmAbout.Create(Application);
form.ShowModal;
form.Free;
Application.Handle:= aHandle;
end;
The form displays well and there are no problems. Now, the only thing I would like it to do is to behave positioning as poMainFormCenter (I want it to display always over the main form (the form that is calling the dll).
I have tried using form :=TfrmAbout.Create(Application.MainForm); etc but no luck.
Any tricks which would help here?
The VCL Position mechanism relies on the other forms in the application all running with the same version of the VCL. This is clearly not the case here and you will have to position the form manually.
Find out the position of the main form by calling GetWindowRect() passing the main form handle. Then you need to work out where your form needs to go to be in the center of that form.
procedure PositionForm(Form: TForm; MainWindow: HWND);
var
MainBounds: TRect;
MainWidth, MainHeight: Integer;
begin
if GetWindowRect(MainWindow, MainBounds) then
begin
MainWidth := MainBounds.Right-MainBounds.Left;
MainHeight := MainBounds.Bottom-MainBounds.Top;
Form.Left := MainBounds.Left + (MainWidth - Form.Width) div 2;
Form.Top := MainBounds.Top + (MainHeight - Form.Height) div 2
end;
By the way, the handle you are passing is an HWND rather than a THandle. You should change you code accordingly. It won't change behaviour, but it is logically correct to do so.
Since you don't use pacakges, your EXE and your DLL both have a seperate TApplication instance. TApplication.MainForm in your EXE is not seen in your DLL. Changeing TApplication.Handle does not make the MainForm change. Find other ways to position the form right, but better yet: Use packages, you will run into more problems if you don't.
Have you tried setting form.ParentWindow to the handle of the parent window? You should pass it as a param to ShowAbout, or you could dig it up from Application object (something like Application.ActiveForm) but I'm not sure it would work.
Calling TfrmAbout.Create(Application.MainForm) just specifies that Application.MainForm is responsible for destruction of the form, it should have nothing to do with window hierarchy, also I'm not sure you should be using auto destruction if you create form in a separate dll.

Get form field value via module [VBA]

I have a program built with VBA, in access.
I have a form with the field chDate and I need to get the value of the field in a module file named Global (not class module).
I tried to access it but I think I get empty value, string. not error.
I'm no expert with VBA, its new to me (I have experience with VBS).
Can someone please help me and tell me how can I access the value of a form field via module file?
Thanks!
If you can provide some sample code, it might help us in trying to get you a solution.
Here's what might work:
Dim an object as an instance of your form, and set the instance to a new instance. These two lines will do that (assuming the form is called frmForm)
Dim theForm as frmForm
Set theForm = new frmForm
then Show that Form:
theForm.show
The form will get the focus, so you can populate the fields. At that point, once the form is hidden, your code should be able to pull the field as such:
var1 = theForm.txtFormField.Text
However, if you unload the form in code, all variables directly tied to the form will be lost. In that case, you might want to follow Oneide's example, and set a global variable to the value of the form field. You can do this in one of the form's event handlers.
Let me see if I can recall my Access days. In your global module you should access the form field be prefixing the form name i.e.
var1 = Form1.txtFirmField.Text
As far as I know, you're trying to get the data the wrong way.
Anytime you would try to get your form data, from a standard module, your form probably will already be closed or, if you're not opening it as a restricted window, the value will not be ready yet.
Anyway, if you could get pass through all the difficulties above, you're probably coding in a not standard / right way.
Remember that VBA is an event driven language, and you would be better using it's strenghts rather than fighting against them.
As a final word, if this is just a casual coding, I suggest you using a global variable and make de Code Behind Form have set it up on control's change event.
If you're not sure what I mean, please leave a comment and I'll try to explain it better.
And, if you don't mind, let us know more about your starting code to get better answers.