Send messages from subform to parent form

azwierzchowski
Member Posts: 15
You can send message from subform to parent form using XMLDocument and events. When you call XMLDoc.LoadXML it fires OnreadyStateChanged event, so:
1. Declare "'Microsoft XML, v3.0'.DOMDocument" automation variable with events in parent form, and without events in subform
2. Create variable in OnOpen trigger in parent form, and pass it to subform
3. Handle OnReadyStateChanged event in parent form:
IF (XMLDOC.readyState = 4) THEN
ProcessXMLMessages();
and create procedure ProcessXMLMessages with your code
4. call XMLDoc.loadXML in subform every time, you want to notify parent form
1. Declare "'Microsoft XML, v3.0'.DOMDocument" automation variable with events in parent form, and without events in subform
2. Create variable in OnOpen trigger in parent form, and pass it to subform
3. Handle OnReadyStateChanged event in parent form:
IF (XMLDOC.readyState = 4) THEN
ProcessXMLMessages();
and create procedure ProcessXMLMessages with your code
4. call XMLDoc.loadXML in subform every time, you want to notify parent form
0
Comments
-
I know that this is an old post, but as it is directly showing what I want to do...
How are you passing the XMLDoc to your subform in step 2?
I am trying to use Sales Header and Sales line and keep a running total in the Header witout needing to select it everytime.
Could you please post a code example?
Thanks,
Joe0 -
Here it is:
OBJECT Form 50000 Parent
{
OBJECT-PROPERTIES
{
Date=07-08-30;
Time=15:14:11;
Modified=Yes;
Version List=;
}
PROPERTIES
{
Width=8000;
Height=4840;
OnOpenForm=BEGIN
CREATE(XmlDoc);
CurrForm.SubForm.FORM.SetXmlDoc(XmlDoc);
END;
OnCloseForm=BEGIN
CLEAR(XmlDoc);
END;
}
CONTROLS
{
{ 1000000000;TextBox;330 ;220 ;4290 ;440 ;Editable=No;
SourceExpr=TextVar }
{ 1000000001;SubForm;220 ;880 ;7480 ;2310 ;Name=SubForm;
SubFormID=Form50001 }
}
CODE
{
VAR
TextVar@1000000000 : Text[50];
XmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40" WITHEVENTS;
EVENT XmlDoc@1000000001::ondataavailable@198();
BEGIN
END;
EVENT XmlDoc@1000000001::onreadystatechange@-609();
BEGIN
IF (XmlDoc.readyState = 4) THEN BEGIN
TextVar := CurrForm.SubForm.FORM.GetText();
CurrForm.UPDATE(FALSE);
END;
END;
BEGIN
END.
}
}
OBJECT Form 50001 Child
{
OBJECT-PROPERTIES
{
Date=07-08-30;
Time=15:19:54;
Modified=Yes;
Version List=;
}
PROPERTIES
{
Width=8030;
Height=2420;
}
CONTROLS
{
{ 1000000000;TextBox;220 ;220 ;4180 ;440 ;SourceExpr=TextVar1;
OnAfterValidate=BEGIN
SendMessage();
END;
}
{ 1000000001;TextBox;220 ;770 ;4180 ;440 ;SourceExpr=TextVar2 }
}
CODE
{
VAR
TextVar1@1000000000 : Text[50];
TextVar2@1000000002 : Text[50];
XmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40";
PROCEDURE SetXmlDoc@1000000000(pXmlDoc@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40");
BEGIN
XmlDoc := pXmlDoc;
END;
PROCEDURE SendMessage@1000000004();
BEGIN
XmlDoc.loadXML('<root></root>');
END;
PROCEDURE GetText@1000000001() : Text[50];
BEGIN
EXIT(TextVar1);
END;
BEGIN
END.
}
}0 -
Thank you so very much.
This enabled me to do EXACTLY what I wanted.
=D>0 -
This is a replacement for the timer solution and the singleinstance codeunit to pass values from form to form?
Looks a bit technical...Does it work in a live situation?0 -
Yes, this replaces timer and singleinstance codeunit solutions.
It may seem complex at first, but it's only 6 lines of code in the Parent form and 4 lines of code (3 functions ) in the subform.
I didn't need it to pass back information like his example, so I got it down to 5 lines in the parent and 3 in the subform.
Then I decided I wanted two more fields to update the main form, so I added the "SendMessage();" to the "OnDeactivate" trigger of those fields of the subform and it worked great.
Yes it works live.
Definately a great tip (or trick).
Once again, Thank you azwierzchowski =D>0 -
Somehow I'm not convinced my user will have XMLDOM on the Win98 boxes they use for tills, so I think I'll just go with the timer trick. It all seems fine here but it's a powerful PC with a single-used DB. Has anybody found any performance problems with it in real life?0
-
OK I've did a bit of benchmarking on the timer-based solution, I've put it behind a button:
[code]
MESSAGE(FORMAT(TIME));
FOR i:=1 TO 100000 DO BEGIN
IF CurrForm.PaymentLines.FORM.NeedsUpdating THEN BEGIN
CurrForm.UPDATE(TRUE);
END;
END;
MESSAGE(FORMAT(TIME));
[code]
This takes 1 sec in my fast PC. Let's assume ten times slower PC's it means checking the subform and finding out that no, we don't need to update it right now takes 1/10000 of a second. Well that performance hit we can live with
The advantage is that I'm not sure they have XMLDOM in Win98. Though I think it's built into IE which is built into Windows but why risk it.0 -
azwierzchowski wrote:You can send message from subform to parent form using XMLDocument and events. When you call XMLDoc.LoadXML it fires OnreadyStateChanged event, so:
1. Declare "'Microsoft XML, v3.0'.DOMDocument" automation variable with events in parent form, and without events in subform
2. Create variable in OnOpen trigger in parent form, and pass it to subform
3. Handle OnReadyStateChanged event in parent form:
IF (XMLDOC.readyState = 4) THEN
ProcessXMLMessages();
and create procedure ProcessXMLMessages with your code
4. call XMLDoc.loadXML in subform every time, you want to notify parent form
Hi azwierzchowski ,
Till point 2 i can able to follow. Please explain Point 3 & 40 -
st0328 wrote:Hi azwierzchowski ,
Till point 2 i can able to follow. Please explain Point 3 & 4No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions