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
0
Comments
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,
Joe
http://www.interdynbmi.com
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.
}
}
This enabled me to do EXACTLY what I wanted.
=D>
http://www.interdynbmi.com
Looks a bit technical...Does it work in a live situation?
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>
http://www.interdynbmi.com
[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.
Hi azwierzchowski ,
Till point 2 i can able to follow. Please explain Point 3 & 4