How to call a set focus on a form creation - pascal

I'm creating a small application with some 'Search' hotkeys, F1 to F4 to search into different tables of a database, so I've created a TPageControl to hold the search fields and also display the results, so I have 1 PageControl and 4 tab sheets, but I'm trying to put one if statement to set the focus on the proper search field and I'm calling it on the OnShow event of the TPageControl, but I'm getting a error message: Form:TForm cannot focus
If I didnt got it all wrong, it's because the text field cannot be found, considering I'm showing the page before the application can create the elements inside of this page, so, how can I edit this code or where can I use it to make it works, just remembering that I need to call this procedures with the hotkeys later on.
The procedure I'm using to set the focus is just a simple IF with 4 conditions in my real case:
procedure TForm.searchFocus; begin
if pgcSearches.TabIndex=0 then begin
editFieldNames.SetFocus;
end
else if pgcSearches.TabIndex=1 then begin
editFieldAdresses.SetFocus
end;
end;

A more 'explicit' help from another forum:
procedure TfrmMain.pcSearchesChange;
begin
case pcSearches.TabIndex of
0: ActiveControl:=edtSearchSongs;
1: ActiveControl:=edtSearchBibles;
2: ActiveControl:=edtSearchWarning;
end;
if Visible then
ActiveControl.SetFocus;
end;

Related

How to solve FRM:40105- Unabel to resolve reference to item problem?

I am new in Oracle forms and reports. I am facing this error.
I have created Employees data block and displaying it to the canvas. I triggered my module as new form instance with execute_query. Then took one display text item and set it's database as no and set this name as search_box and another one is push button, I set it's name as search.
In search block button I have triggered this When button pressed and wrote this code.
begin
set_block_property('EMPLOYEES',default_where,'EMPLOYEE_ID='||':search.search_box');
go_block('EMPLOYEES');
execute_query;
set_block_property('EMPLOYEES',default_where,'');
end;
My Employee_Id is one of my block item but still i can't understand where should I fix to solve this problem.
Please help!
Should be like this - based on Forms Help which says:
Set_Block_Property('emp', ONETIME_WHERE, 'deptno <= :dept.deptno');
Also, you'd rather use onetime_where.
Therefore:
begin
set_block_property('EMPLOYEES', onetime_where, 'EMPLOYEE_ID = :search.search_box');
go_block('EMPLOYEES');
execute_query;
end;
Saying that you can't make it work ... well, I can. Here's a demo.

How to highlight specific record using SET_BLOCK_PROPERTY

I have form in which when open form then all records shown on the block. User enter number on search option and specific record shown on the block. Now I want when search then all records remain on the block and highlight searched data.
BEGIN
SET_BLOCK_PROPERTY('block',default_where,'column= '||:block2.column);
GO_BLOCK ('block');
EXECUTE_QUERY;
END;
How to achieve this target in oracle forms 11g
Thanks
Please refer below link . This will solve your problem.
You need to create a visual attribute and need to assign at item_instance_property level.
http://www.orafaq.com/forum/t/171952/
Firstly, set Current Record Visual Attribute Group property of block to a spesific Visual Attribute which you'd like to highlight to the visited row of the block.
Then, provided the records are already queried and appears on the screen, a text field( :block2.column ) with a
WHEN-BUTTON-PRESSED trigger with the below code might be used to search among those records by entering the desired value and pressing enter :
go_block('block');
first_record;
while :block2.column != :block.column
loop
next_record;
end loop;

Search records on block very slow oracle forms

I have procedure in which enter Visit Number and search records on block. But this procedure search records take some time 3 to 4 minutes and block have 12672 records. How to optimize procedure to search records fast.
CODE:
DECLARE
BEGIN
IF :CTRL_BLOCK.SRCH_VISITNO IS NULL THEN
MESSAGE('Please enter Visit No...');
GO_ITEM('SRCH_VISITNO');
ELSE
BEGIN
GO_BLOCK('cpvdtl');
FIRST_RECORD;
LOOP
IF :cpvdtl.visitno = :CTRL_BLOCK.srch_visitno THEN
exit;
ELSE
NEXT_RECORD;
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD='TRUE';
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
MESSAGE('No Data found...!');
END;
END IF;
:CTRL_BLOCK.srch_visitno := null;
go_item('cpvdtl.visitno');
END;
Why reinventing the wheel?
Default Forms functionality works perfectly well, as simple as:
create a block on a table
run the form
enter query mode
enter search criteria into any column (wildcards included)
execute query
If any record matches criteria, it will be displayed on the screen.
If you insist on your own search field, create it (which is what you already did). Then:
I'd suggest you to create a push button
create a WHEN-BUTTON-PRESSED trigger which will
utilize SET_BLOCK_PROPERTY built-in, using the ONETIME_WHERE (or DEFAULT_WHERE; see which fits better) property, by setting the search field's value into the block's where clause
EXECUTE_QUERY
Why button and not only the search field? Because you'd then use WHEN-VALIDATE-ITEM trigger to SET_BLOCK_PROPERTY, but you couldn't EXECUTE_QUERY in that trigger as it is a restricted procedure. Yes, you could use KEY-NEXT-ITEM trigger, but - what if user navigates out of the search field using the mouse? That trigger wouldn't fire. I'd say that button is a simpler choice.

Oracle forms: Rollback an item to database value without changing form

Let's say if some condition is fullfilled, it shouldn't be possible to make any change to my entire block. I've found a simple way to do this:
In the 'WHEN-VALIDATE-ITEM' trigger on blocklevel, I've written this statement:
begin
if (-- custom statement --
and :system.record_status <> 'QUERY'
and get_item_property(:system.current_item,DATABASE_VALUE) <> name_in(:system.current_item)) then
msgbox('Can''t change');
copy(get_item_property(:system.current_item,DATABASE_VALUE), :system.current_item);
raise form_trigger_failure;
end if;
end;
The copy statement sets the item value back to database value. But the problem is, that the status of my form will go to 'CHANGED', while there actually is not really a change visible, since the item got rollbacked to the database value. So when I try to exit the form, the system asks me if I want to save my changes. And I don't want that to happen. How can I change this?
To avoid asking to User if want to save or not values, you can perform Key-Commit
BEGIN
EXECUTE_TRIGGER('KEY-COMMIT');
standard.commit;
END;

FRM-40401 no changes to save after WHEN-CREATE-RECORD trigger

I googled this but, unfortunately, could not find any solution.
I have a simple form (Oracle Forms Builder 10g) with a single block. The form is written in Oracle EBS style, that is, the block is based on a view that fetches the base table fields together with the rowid and DML events (on-insert, on-update etc. triggers) are handled by a table handler package.
The functionality I wanted to add was the following: when a user creates a new record, the form automatically suggests values for all fields in the form. So, I created a WHEN-CREATE-RECORD trigger that calculates the field values and assigns them. All, except the primary key wich is based on a Sequence and is handled by the package.
Everything runs OK when I create the new record but when I attempt to save it, all I get is a FRM-40401 "no changes to save" error and nothing happens.
I tried to trace the error and it seems like the form considers the record as NEW with no changes on it. This happens even if I try to explicitly alter the record status to INSERT.
I already tried to change the default behaviour to STANDARD.COMMIT (created an ON-COMMIT trigger for that) but this did not dfix anything.
For the record, I tried to make the form table-based, getting rid of table handlers and leaving all DML to Forms. I still get FRM-40401.
I can't understand what is going wrong, any ideas please?
The record status is reset to NEW after the when-create-record trigger completes. This normally makes sense, since you are effectively setting the default values for items, but the user hasn't actually entered any data yet.
You need something to mark the record for insert after the trigger has finished - normally the user would do this when they enter some data into the record. If you want the user to be able to save the record without changing anything in it, you could perhaps add something to the save button to do a no-change assignment, e.g.
:MYBLOCK.ANYITEM := :MYBLOCK.ANYITEM;
This would cause the record to be marked for insert.
OK, for the time being I used the classic TIMER workaround and everything works as it should:
PACKAGE body form_timers IS
PROCEDURE CREATE_NEW_RECORD;
procedure do_create(name varchar2) is
timer_id TIMER;
Begin
timer_id := CREATE_TIMER(name,1,NO_REPEAT);
End;
procedure expired is
expired_timer CHAR(20);
BEGIN
expired_timer:=GET_APPLICATION_PROPERTY(TIMER_NAME);
IF expired_timer='CREATE_NEW_RECORD' THEN
CREATE_NEW_RECORD;
-- ELSIF expired_timer='T2' THEN
-- /* handle timer T2 */ NULL;
ELSE
NULL;
END IF;
END;
PROCEDURE CREATE_NEW_RECORD IS
/* create record logic goes here */
END;
END;
... but still, I'd like to know why this behaviour occurs.

Resources