Form with OLE control is unable to receive focus properly - focus

I have a form, which has 2 checkboxes, one of them is Ole Control :
Now, if I call them twice, there will be 2 instances of the form, the problem is :
Says the focus is now on form 1, and I click on the Ole Control (checkbox), I then can't click on form 2, meaning form 2 couldn't receive focus even I tried clicking many times on the form
Now, if I want to get focus of the other form, I'll have to click on the title bar or the ole control of the form
This won't happen if I don't click on the Ole Control of the form
If I set form.Desktop = .f., everything is fine, but I need desktop property to be true
EDIT : Here is the OLE control :
It's very simple to reproduce the error :
Create a blank form, set form.Desktop = .t., name it formOLE
insert an OLE checkbox, like the image above
insert a normal fox checkbox
Call the form twice do form formOLE

The OCX on foxpro forms it should be always the last remedy.
You are not the only one than can't access foxpro controls after a OCX control has got the focus. These are some solutions I've done throughout my projects:
Call a very small form just for readjust the foxpro focus, a form that on activate event there is a thisform.relase. This is called after use OCX. it is common issue to not be able to edit a text field after a OCX focus.
use OCX's visible properties
I recommend to use OCX on modal forms, if not, forms can be unaccessible.

Related

how to know which form called the fonction in delphi

I have a lot of Forms, and in one Form I use printing. All other Forms can call this printing Form.
In addition, every Form has different objects, some of them have TDBGrid and Filtered option, and some of them don't. I tried to check before printing if there's a Filter. I did some code and I get a result, but this didn't work with all Forms because every Form have a different name, as everyone knows.
My question is, how to know which Form clicked the printing button and use it?
//on form is 1
form1.dbgrid.somecode
for second form
form2.stringgrid.somecode
How can I know which Form, and can I save the object's name in a table in the database?

How to auto update many descendants forms after ancerstor form had an control deleted?

Suppose a TAncestorForm with an extra button (or any other control). If I remove the button, whenever I open a descendant of TAncestorForm the Delphi IDE shows a message "Ancestor component not found..." and let me choose:
Remove the reference;
Tell that the component was renamed and what is
it's new name;
Recreate the component;
I want the first option. There is any other option that would do this automatically instead of opening all descendants (like dozens of them) and clicking in each message?

delphi using dbgrid to view a record on a detail page

I have a form with a dbgrid and a second form with dbedits. My form with the dbgrid has a double click event(code below is the event) the dbedits on the second form has a data source that is connected to the first form's CDS and when I compile and run the program and open the form with db grid I can double click any record and it is display in the dbedits on the second form, but if I close the forms and reopen the form the only record that will display in the second form dbedits is the first record in the table. I have to open and close CDS and that is not working. what else would I need to do to correct this problem.
procedure TFRM_ADMIN.DBGrid1DblClick(Sender: TObject);
BEGIN
frm_LEADDETAILADMINLEAD := tfrm_LEADDETAILADMINLEAD.Create(FRM_ADMIN);
frm_LEADDETAILADMINLEAD.SHOW;
END;
The site will not allow me to add the dmf text. It is to large. I am using sqlconnection, sqlquery, data set provider, client data set, data source set up if this helps any.
This is a very wild quess, but I suspect the following at play:
You use the public variables for the forms that the IDE automatically has added to each unit.
You create FRM_ADMIN the way you create frm_LEADDETAILADMINLEAD, something like:
FRM_ADMIN := TFRM_ADMIN.Create(MainForm);
FRM_ADMIN.Show;
You don't close this form, but hide it (the default close action of a form).
The second time you create your second form, the designtime set DataSet property of the DataSource of your second form is automatically resolved to the ClientDataSet on the first instance of the first form.
So in the second run you are editing the record that was selected in the first run.
Solution and recommendations:
Destroy forms (set Action := caFree) in the OnClose event.
Do not use the public variables, remove them. Keep you form reference in a separate private field, unique to each instance.
Assign DataSource and/or DataSet properties at runtime explicitly.
Use DataModules.
Further reading:
Binding a second instance of a form to a second instance of a data module?
Will there be any detrimental effects if I accidentally remove something from a forms uses list which a control is referencing?
Separate DataSet instances using DataModules.
Show message when Tform2 is created?

A form that is able to be Modal after it is created

I have a PopForm that I want to stay over MainForm in any case.
The cases are:
PopForm.ShowModal and PopForm.Show.
Whilst ShowModal is completely works fine, the Show method is needed to interact with MainForm for doing 'drag-drop' things.
Main duty of the PopForm is to import data from some files to a dataset on the MainForm. There is two ways: drag-drop of the concrete data (selected rows while in Show-mode) and transfering all data from PopForm (while in ShowModal-mode). All data in the PopForm stored in something like ClientDataSet. I developed methods that are alike ClientDataSet's: First, Eof, FieldByName, Next, etc. and implemented them into PopForm.
After the PopForm is closed (after setting the ModalResult), the calling procedure uses a while not PopForm.eof do PopForm.Next... to import data into MainForm's dataset or whatever would be a user-programmers method.
For showing some progress I used to recreate PopForm with Show method and show a progress form above PopForm, while a cycle is being made in the calling procedure. After that - PopForm is closed.
This works fine, but the only problem is about a Show method - I need the PopForm to be over MainForm all the time. In most cases it is, but there are some applications, that somehow doesn't follow this rule. I've tried to use PopupParent & PopupMode properties, but they make popForm to recreate again on any assignment (and as I've just found - you need to assign a CustomForm on show and then - Nil it on close, because with common TForm.Close method it won't hide no way)
There would be no any problem about that, if there would be no need to Nil PopupParent on FormClose method. The other routine is to assign
...FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
...
end;
It would work if Assigned(PopForm) return false, but it returns true.
If there is any case to discover if the Form is Freed - that may help. What do you think?
If you set your form style to fsStayOnTop the form will always stay on top unles you there is another form with same property. In that case the active one of them will be on top.
As for moving data from your PopForm which you use for importing data you could folow similar approach as it is used in creating of custom Dialogs.
Custom dialogs are usually designed like so:
You have dialog class which contains fields for dialg settings (to change hoe the dialog woul look like), and even a field for dialog output (selected FileMame/s, etc.).
Within this class there is a dialog form class which esentially is a modal form. This dialog form uses its OnClose event to automatically feed necessary information into Dialog output field before closing.

Create Simple Component that cannot be added multiple times on a form

How to write a simple component that never allows it to drop multiple time on the form?
let say, I already drop my TMyComponent on the form and if i will drop another TMyComponent it notifies 'Component already exist!' and will cancel the dropping of the component on the form.
The components Constructor takes an Owner parameter: that'll normally be your Form (or DataModule). Simply walk the list of Owner.Components and see if there's an other one of yours. If there is, raise an Exception.
This would block your component from being added, both at design time and at runtime.

Resources