Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 4 Jahren, 12 Monaten
Letzter Beitrag:
vor 4 Jahren, 11 Monaten
Beteiligte Autoren:
Yogi Yang, Paulo Oliveira, Peter Holemans, Piet van Zanten, Bart VDE, Al, Markus K., Fabrice Harari

How to access controls of a Window from another Window

Startbeitrag von Yogi Yang am 23.07.2013 14:58

Hi all,

As the subject says.

I have two windows/forms in my app - WinA and WinB.

I need to access controls of WinB and set their values based on certain criteria and user selection in WinA at the time when WinA is opening WinB.

I have spent most of my day trying to achieve this. But have not been able to achieve this.I also tried to declare variables in the Global Declaration of Window but I am not able to access them! If I could be able to access them then I would be able to create a work around of populating controls of WinB.

Any ideas as to who we can achieve this?

TIA

Yogi Yang

Antworten:

Hi YY,

You need to indicate the full path name of the controls.
You can get this with either the ..fullname attribute of the control or by typing it yourself: e.g.: windowname.tabcontrolname.controlname.

Anyway, if you do a simple trace(controlname..fullname) you will see how this works.

Aside of that: If you plan on doing this with variables to make the code generic (one code block to assign any control in any other window), make sure you do a ControlExists(Variable) before assigning anything to the variable (=control) in order to prevent a runtime failure.

Cheers,

Peter H.

von Peter Holemans - am 23.07.2013 15:25
Hi,
if WinA opens WinB, then you can use in WinB:

if WinA.edt_Value = "xy" then (WinB.)Edt_Value1 = "ab"

WinA has to be open of course or it throws an error.

von Markus K. - am 23.07.2013 15:27
Hello Yogi

In addition to the other posts, you can use Winstatus() to test for the existence of a window before you refer to its controls.

Regards
Al

von Al - am 23.07.2013 15:34
If WinA opens WinB you can access WinA controls in WinB just using WinA.ControlName

Bu if WinB can be opened also from WinC the best way i know is passing the values as parameters from WinA to WinB or from WinC to WinB: In this case you can use optional parameters (default values) and pass them only when needed.

von Paulo Oliveira - am 23.07.2013 16:44
Hi everybody

it seems to me that a very important information is missing here...

Is the window MODAL or not?

If A is opening B as a modal window (OPEN), then the code in A is stopped while B is open and A cannot therefore access the code in B (except by jumping through hoops, like with a timer), but B can read fields from A by using windowA.FieldOfWindowA

If, on the contrary, A is opening B as NON modal (openCHild), then in the lines following the openchild, A can write data in B using windowB.FieldOfB

That was to answer the original question... But there is no doubt in my mind that the preferred way of doing things should be via parameters send to B in the OPENxxx function (and that B is getting via its "PROCEDURE" first line

Best regards

von Fabrice Harari - am 24.07.2013 12:48
It seems there is some confusion here.

I do not want to access WinA from WinB. It is the other way around.

I have tried accessing WinA controls from WinB and that works fine.

I want to access WinB from WinA. At this stage WinB is not opened using Open function.

Here is sample 2 lines of code:

//Open Bank Master Windows and set is default value
WIN_B.EDT_CustName = "Yogi Test"
Open(WIN_B)


TIA

Yogi Yang

von Yogi Yang - am 29.07.2013 05:17
Hi,

I think you have to forget the "Delphi-way" of programming, where you first create a form object (after that you can assign fields of that form) before actually opening the form.

In WD, the best way of working is like Fabrice said, i.e. passing the neccessary values as a parameter :

In WinA:
Open (WinB, 10)

And in WinB:

Procedure WinB(aCustomerNumber)
hreadseekfirst(Customer,CustomerNumber, aCustomerNumber)
FileToScreen(WinB, Customer

von Bart VDE - am 29.07.2013 07:32
Hi Yogi,

As an addition to Bart's remarks it's good to know that you CAN use files and queries in another window. (unless you set the window to independent hyperfile context)
Global project variables will always be accessible.
So if you open a form window you can simply use FiletoScreen to display the current record of a file.
But you can never assign values to objects belonging to a window that has not yet been opened.
It's very straightforward.

Regards,
Piet

von Piet van Zanten - am 29.07.2013 09:53
Thanks everyone for helping me out.

So finally we come to the conclusion that it is not possible to load a windows in memory using some means and then setting required controls and after that showing the window to user.

So I will have to rely on Global variables for passing necessary data. I will give Bart's idea a try tomorrow.

Regards,

Yogi Yang

von Yogi Yang - am 29.07.2013 15:39
You don't need to define global variables, just use OPEN with parameters.

von Paulo Oliveira - am 29.07.2013 16:17
pffff...

RTFM (Check: Open, OpenSister) and use parameters/objects to pass to it...
If you would pass an object you can bind the controls even directly to it, so you don't even have to set anything.
### WINDOW CODE
//e.g. Target window declaration code:
PROCEDURE MyWindowName(pObjectPassed is aCustomerClassForExample)
//Next: initialisation code of window:
SourceToScreen("",pObjectPassed)
//Note that your window controls can directly be linked to the members of the object

### OUTSIDE WINDOW CODE
//The call to this window could than be:
SampleCust is aCustomerClassForExample
SampleCust.Member1 = X
SampleCust:Member2 = Y
OpenSister(MyWindowName,SampleCust)

-->And I even believe that the object to the window is passed by reference and not by value. So you can change this again from outside just by changing the initial object.
e.g. from the initial outside window:
IF WinStatus(MyWindowName) NotFound THEN
SampleCust.Member1 = NewX
SampleCust:Member2 = NewY
ExecuteProcess(MyWindowName, trtInit)
END

But... if you really want to persist in proceeding with bad design you can:
1) Open the new window : Opensister(windowname)
2) Set it off-screen: Winstatus(windowname, outsidescreen)
3) Set the controls (e.g. windowname.controlname = X)
4) Set it back on-screen: Winstatus(windowname, active)

But then again: the last is really, really, bad software design in general...

Cheers, P.

von Peter Holemans - am 29.07.2013 19:53
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.