Problem:
You may want to use a Programmed Text Entry instead of the standard Dialog System entry field or MLE control because you need some special characteristic like an MLE without a scrollbar (see knowledge base article 20465).
There is a sample for Programmed Text Entry controls under DialogSystem\\CommonControls\\TextEntry (in your Net Express installation directory) that shows you how to use them.
But in this demo the Programmed Text Entry controls gets updated with the value within the associated field in the Data Block only get they get focus.
This knowledgebase article shows you how you can get your Programmed Text Entry to show the value in the associated field in the Data Block at creation time.
Resolution:
I will explain what needs to be done by showing what changes would be needed to the product demo at DialogSystem\\CommonControls\\TextEntry (in your Net Express installation directory) so both Text Entry Programmed controls show the value that the associated Data Block fields have been initialized with.
The final updated versions of the product demo's COBOL programs has been attached to this knowledge base article.
First of all, we need to initialize both Data Block fields in the main COBOL program, efdemo.cbl. The most adequate place seems to be the Program-Initialize SECTION:
Program-Initialize SECTION.
INITIALIZE Ds-Control-Block
INITIALIZE Data-block
MOVE Data-block-version-no
TO Ds-Data-Block-Version-No
MOVE Version-no TO Ds-Version-No
MOVE Ds-New-Set TO Ds-Control
MOVE "efdemo" TO Ds-Set-Name
MOVE "Hello" to IO-FIELD-1
MOVE "Hola" to IO-FIELD-2
Next we need to update the generated control program, efdemoTxtFld.cbl in the product demo for both Text Entry controls.
If you look at the code generated, you will be able to see that there are 9 entry points to the program (the main entry point PROCEDURE DIVISION, and 8 more entries), but the entry points that interest us for this particular are the entry point called at creation time:
Create-Entry-Point Section.
Entry "C" & ProgramID USING EntryPoint-Data.
and the entry point called when one of the Text Entry controls gaines focus:
EfGainFocus Section.
Entry ProgramID & "EfGainFocus" USING anEvent.
The first one will be the one that we want to update to get the controls initialized to a value when they are created, and the second one to see how it is done in this section so we can "copy" it (no need to reinvent the wheel).
First of all, notice that the USING clause in both entries is different, they receive different parameters, so we will have to be carefull when we copy things from one entry to the other because we don't have access to the same data to start with.
If we look at the ProgramID & "EfGainFocus" entry point, the first PERFORM that is called, GetObjectAndEventData, it is setting some data based on the parameter received, anEvent. As at creation time we don't have an event yet, we need to set the data that GetObjectAndEventData is setting some other way. GetObjectAndEventData is setting the following data:
aTextEntry - with the object reference to the Text Entry control
aWindow - with the object reference to the parent window
FieldCount - the index of the control (used to distinguish between controls when the same control program controls more than one control, like it is done in the demo). It will be 1 for the first control and 2 for the second control.
Data-Block - it obtains the address of the data block and it sets Data-Block defined in Linkage section to that address.
So we need to ensure that we have those variables correctly set before the other 2 PERFORMs are called in Create-Entry-Point Section (Setup-Field-Data & SetEntryFieldText):
aTextEntry: set in the called Create-Entry-Field section when the object is created.
aWindow: set in the GetWindow-Instance-Routine section called at the beginning.
FieldCount: set at the end of AddEntryFieldToDictionary Section.
Data-Block address: is not set! we need to ensure that the address of Data-Block is set before we can do anything. Fortunately, in the structure that the create entry point receives as parameter (EntryPoint-Data) there is a pointer to the data block: EntryDatablock-pointer.
Finally, the best place to update would be the end of the create entry point, before the EXIT PROGRAM sentence:
* Refresh the programmed control with the value in a field within the
* data block.
SET ADDRESS OF DATA-BLOCK TO EntryDatablock-pointer
PERFORM Setup-Field-Data
PERFORM SetEntryFieldText
Note: In the demo, Setup-Field-Data has been correctly updated so for FieldCount 1 and 2, the correct data block field is being used. But as you will be using a generated program for your own program, ensure that you have this ******TO DO correctly defined in a similar fashion that it is done in the demo program.
Attachments:
#AcuCobol
#COBOL
#ServerExpress
#RMCOBOL
#netexpress
