home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / MapQuest / ClientMain.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-10-22  |  24.7 KB  |  663 lines

  1. unit ClientMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   System.Drawing, System.Collections, System.ComponentModel, 
  7.   System.Windows.Forms, System.Data, System.Resources;
  8.  
  9. type
  10.   TMainForm = class(System.Windows.Forms.Form)
  11.   {$REGION 'Designer Managed Code'}
  12.   strict private
  13.     /// <summary>
  14.     /// Required designer variable.
  15.     /// </summary>
  16.     components: System.ComponentModel.IContainer;
  17.     GroupBoxFrom: System.Windows.Forms.GroupBox;
  18.     GroupBoxTo: System.Windows.Forms.GroupBox;
  19.     TextBoxAddressFrom: System.Windows.Forms.TextBox;
  20.     TextBoxCityFrom: System.Windows.Forms.TextBox;
  21.     TextBoxStateFrom: System.Windows.Forms.TextBox;
  22.     TextBoxAddressTo: System.Windows.Forms.TextBox;
  23.     TextBoxCityTo: System.Windows.Forms.TextBox;
  24.     TextBoxStateTo: System.Windows.Forms.TextBox;
  25.     MainMenu: System.Windows.Forms.MainMenu;
  26.     MenuItem1: System.Windows.Forms.MenuItem;
  27.     MenuItemExit: System.Windows.Forms.MenuItem;
  28.     Label1: System.Windows.Forms.Label;
  29.     Label2: System.Windows.Forms.Label;
  30.     Label3: System.Windows.Forms.Label;
  31.     Label4: System.Windows.Forms.Label;
  32.     Label5: System.Windows.Forms.Label;
  33.     Label6: System.Windows.Forms.Label;
  34.     StatusBar: System.Windows.Forms.StatusBar;
  35.     MenuItem2: System.Windows.Forms.MenuItem;
  36.     MenuItem3: System.Windows.Forms.MenuItem;
  37.     MenuItemAbout: System.Windows.Forms.MenuItem;
  38.     TabControl1: System.Windows.Forms.TabControl;
  39.     TabPageDirections: System.Windows.Forms.TabPage;
  40.     TabPageSoap: System.Windows.Forms.TabPage;
  41.     TextBoxDirection: System.Windows.Forms.TextBox;
  42.     MenuItem4: System.Windows.Forms.MenuItem;
  43.     MenuItemDirection: System.Windows.Forms.MenuItem;
  44.     TextBoxRequest: System.Windows.Forms.TextBox;
  45.     TextBoxResponse: System.Windows.Forms.TextBox;
  46.     ToolTip: System.Windows.Forms.ToolTip;
  47.     Splitter2: System.Windows.Forms.Splitter;
  48.     ImageList: System.Windows.Forms.ImageList;
  49.     StatusBarPanel1: System.Windows.Forms.StatusBarPanel;
  50.     MenuItemCopy: System.Windows.Forms.MenuItem;
  51.     ToolBar1: System.Windows.Forms.ToolBar;
  52.     ToolBarButton1: System.Windows.Forms.ToolBarButton;
  53.     ToolBarButtonDirection: System.Windows.Forms.ToolBarButton;
  54.     ToolBarButton3: System.Windows.Forms.ToolBarButton;
  55.     ToolBarButtonCopy: System.Windows.Forms.ToolBarButton;
  56.     /// <summary>
  57.     /// Required method for Designer support - do not modify
  58.     /// the contents of this method with the code editor.
  59.     /// </summary>
  60.     procedure InitializeComponent;
  61.     procedure TMainForm_Load(sender: System.Object; e: System.EventArgs);
  62.     procedure MenuItemExit_Click(sender: System.Object; e: System.EventArgs);
  63.     procedure MenuItemDirection_Click(sender: System.Object; e: System.EventArgs);
  64.     procedure MenuItemCopy_Click(sender: System.Object; e: System.EventArgs);
  65.     procedure MenuItemAbout_Click(sender: System.Object; e: System.EventArgs);
  66.     procedure ToolBar1_ButtonClick(sender: System.Object; e: System.Windows.Forms.ToolBarButtonClickEventArgs);
  67.   {$ENDREGION}
  68.   strict protected
  69.     /// <summary>
  70.     /// Clean up any resources being used.
  71.     /// </summary>
  72.     procedure Dispose(Disposing: Boolean); override;
  73.   private
  74.     type
  75.       TTextBoxTextDelegate = procedure (Control: TextBox; Content: string) of object;
  76.       TExceptionHandlerDelegate = procedure (E: Exception) of object;
  77.   private
  78.     FSyncTextBoxes: TTextBoxTextDelegate;
  79.     FWaitingForResult: Boolean;
  80.     procedure SetWaitingForResult(const Value: Boolean);
  81.     procedure Sync_TextBoxText(Control: TextBox; Content: string);
  82.   public
  83.     constructor Create;
  84.     procedure GetDirectionsCallBack(Ar: IAsyncResult);
  85.     procedure HandleException(E: Exception);
  86.     procedure FindDirection;
  87.     procedure MonitorSoapRequest(Sender: TObject; const Xml: string);
  88.     procedure MonitorSoapResponse(Sender: TObject; const Xml: string);
  89.     procedure UpdateStatusBar(const Text: string = '');
  90.     property WaitingForResult: Boolean read FWaitingForResult write SetWaitingForResult;
  91.   end;
  92.  
  93. implementation
  94.  
  95. uses
  96.   System.Globalization, PetrVones.Utils.SoapTrace, borland.IMapQuestservice, AboutBox;
  97.  
  98. resourcestring
  99.   RsConnecting  = 'Connecting to the server ...';
  100.   RsError       = 'There was an error during the call';
  101.   RsGettingData = 'Getting the direction ...';
  102.   RsInfo        = 'Press F9 to get the directions';
  103.  
  104.  
  105. {$REGION 'Windows Form Designer generated code'}
  106. /// <summary>
  107. /// Required method for Designer support - do not modify
  108. /// the contents of this method with the code editor.
  109. /// </summary>
  110. procedure TMainForm.InitializeComponent;
  111. type
  112.   TSystem_Windows_Forms_MenuItemArray = array of System.Windows.Forms.MenuItem;
  113.   TSystem_Windows_Forms_StatusBarPanelArray = array of System.Windows.Forms.StatusBarPanel;
  114.   TSystem_Windows_Forms_ToolBarButtonArray = array of System.Windows.Forms.ToolBarButton;
  115. var
  116.   resources: System.Resources.ResourceManager;
  117. begin
  118.   Self.components := System.ComponentModel.Container.Create;
  119.   resources := System.Resources.ResourceManager.Create(TypeOf(TMainForm));
  120.   Self.GroupBoxFrom := System.Windows.Forms.GroupBox.Create;
  121.   Self.Label3 := System.Windows.Forms.Label.Create;
  122.   Self.Label2 := System.Windows.Forms.Label.Create;
  123.   Self.Label1 := System.Windows.Forms.Label.Create;
  124.   Self.TextBoxStateFrom := System.Windows.Forms.TextBox.Create;
  125.   Self.TextBoxCityFrom := System.Windows.Forms.TextBox.Create;
  126.   Self.TextBoxAddressFrom := System.Windows.Forms.TextBox.Create;
  127.   Self.GroupBoxTo := System.Windows.Forms.GroupBox.Create;
  128.   Self.Label4 := System.Windows.Forms.Label.Create;
  129.   Self.Label5 := System.Windows.Forms.Label.Create;
  130.   Self.Label6 := System.Windows.Forms.Label.Create;
  131.   Self.TextBoxStateTo := System.Windows.Forms.TextBox.Create;
  132.   Self.TextBoxCityTo := System.Windows.Forms.TextBox.Create;
  133.   Self.TextBoxAddressTo := System.Windows.Forms.TextBox.Create;
  134.   Self.MainMenu := System.Windows.Forms.MainMenu.Create;
  135.   Self.MenuItem1 := System.Windows.Forms.MenuItem.Create;
  136.   Self.MenuItemDirection := System.Windows.Forms.MenuItem.Create;
  137.   Self.MenuItem4 := System.Windows.Forms.MenuItem.Create;
  138.   Self.MenuItemExit := System.Windows.Forms.MenuItem.Create;
  139.   Self.MenuItem2 := System.Windows.Forms.MenuItem.Create;
  140.   Self.MenuItemCopy := System.Windows.Forms.MenuItem.Create;
  141.   Self.MenuItem3 := System.Windows.Forms.MenuItem.Create;
  142.   Self.MenuItemAbout := System.Windows.Forms.MenuItem.Create;
  143.   Self.StatusBar := System.Windows.Forms.StatusBar.Create;
  144.   Self.StatusBarPanel1 := System.Windows.Forms.StatusBarPanel.Create;
  145.   Self.ImageList := System.Windows.Forms.ImageList.Create(Self.components);
  146.   Self.TabControl1 := System.Windows.Forms.TabControl.Create;
  147.   Self.TabPageDirections := System.Windows.Forms.TabPage.Create;
  148.   Self.TextBoxDirection := System.Windows.Forms.TextBox.Create;
  149.   Self.TabPageSoap := System.Windows.Forms.TabPage.Create;
  150.   Self.TextBoxRequest := System.Windows.Forms.TextBox.Create;
  151.   Self.Splitter2 := System.Windows.Forms.Splitter.Create;
  152.   Self.TextBoxResponse := System.Windows.Forms.TextBox.Create;
  153.   Self.ToolTip := System.Windows.Forms.ToolTip.Create(Self.components);
  154.   Self.ToolBar1 := System.Windows.Forms.ToolBar.Create;
  155.   Self.ToolBarButton1 := System.Windows.Forms.ToolBarButton.Create;
  156.   Self.ToolBarButtonDirection := System.Windows.Forms.ToolBarButton.Create;
  157.   Self.ToolBarButton3 := System.Windows.Forms.ToolBarButton.Create;
  158.   Self.ToolBarButtonCopy := System.Windows.Forms.ToolBarButton.Create;
  159.   Self.GroupBoxFrom.SuspendLayout;
  160.   Self.GroupBoxTo.SuspendLayout;
  161.   (System.ComponentModel.ISupportInitialize(Self.StatusBarPanel1)).BeginInit;
  162.   Self.TabControl1.SuspendLayout;
  163.   Self.TabPageDirections.SuspendLayout;
  164.   Self.TabPageSoap.SuspendLayout;
  165.   Self.SuspendLayout;
  166.   // 
  167.   // GroupBoxFrom
  168.   // 
  169.   Self.GroupBoxFrom.Controls.Add(Self.Label3);
  170.   Self.GroupBoxFrom.Controls.Add(Self.Label2);
  171.   Self.GroupBoxFrom.Controls.Add(Self.Label1);
  172.   Self.GroupBoxFrom.Controls.Add(Self.TextBoxStateFrom);
  173.   Self.GroupBoxFrom.Controls.Add(Self.TextBoxCityFrom);
  174.   Self.GroupBoxFrom.Controls.Add(Self.TextBoxAddressFrom);
  175.   Self.GroupBoxFrom.Location := System.Drawing.Point.Create(0, 32);
  176.   Self.GroupBoxFrom.Name := 'GroupBoxFrom';
  177.   Self.GroupBoxFrom.Size := System.Drawing.Size.Create(360, 72);
  178.   Self.GroupBoxFrom.TabIndex := 3;
  179.   Self.GroupBoxFrom.TabStop := False;
  180.   Self.GroupBoxFrom.Text := 'Fro&m';
  181.   // 
  182.   // Label3
  183.   // 
  184.   Self.Label3.AutoSize := True;
  185.   Self.Label3.Location := System.Drawing.Point.Create(264, 24);
  186.   Self.Label3.Name := 'Label3';
  187.   Self.Label3.Size := System.Drawing.Size.Create(31, 16);
  188.   Self.Label3.TabIndex := 5;
  189.   Self.Label3.Text := 'State';
  190.   // 
  191.   // Label2
  192.   // 
  193.   Self.Label2.AutoSize := True;
  194.   Self.Label2.Location := System.Drawing.Point.Create(136, 24);
  195.   Self.Label2.Name := 'Label2';
  196.   Self.Label2.Size := System.Drawing.Size.Create(24, 16);
  197.   Self.Label2.TabIndex := 4;
  198.   Self.Label2.Text := 'City';
  199.   // 
  200.   // Label1
  201.   // 
  202.   Self.Label1.AutoSize := True;
  203.   Self.Label1.Location := System.Drawing.Point.Create(8, 24);
  204.   Self.Label1.Name := 'Label1';
  205.   Self.Label1.Size := System.Drawing.Size.Create(46, 16);
  206.   Self.Label1.TabIndex := 3;
  207.   Self.Label1.Text := 'Address';
  208.   // 
  209.   // TextBoxStateFrom
  210.   // 
  211.   Self.TextBoxStateFrom.Location := System.Drawing.Point.Create(264, 40);
  212.   Self.TextBoxStateFrom.Name := 'TextBoxStateFrom';
  213.   Self.TextBoxStateFrom.Size := System.Drawing.Size.Create(88, 20);
  214.   Self.TextBoxStateFrom.TabIndex := 2;
  215.   Self.TextBoxStateFrom.Text := 'NY';
  216.   // 
  217.   // TextBoxCityFrom
  218.   // 
  219.   Self.TextBoxCityFrom.Location := System.Drawing.Point.Create(136, 40);
  220.   Self.TextBoxCityFrom.Name := 'TextBoxCityFrom';
  221.   Self.TextBoxCityFrom.Size := System.Drawing.Size.Create(120, 20);
  222.   Self.TextBoxCityFrom.TabIndex := 1;
  223.   Self.TextBoxCityFrom.Text := 'New York';
  224.   // 
  225.   // TextBoxAddressFrom
  226.   // 
  227.   Self.TextBoxAddressFrom.Location := System.Drawing.Point.Create(8, 40);
  228.   Self.TextBoxAddressFrom.Name := 'TextBoxAddressFrom';
  229.   Self.TextBoxAddressFrom.Size := System.Drawing.Size.Create(120, 20);
  230.   Self.TextBoxAddressFrom.TabIndex := 0;
  231.   Self.TextBoxAddressFrom.Text := '39th and 11th';
  232.   // 
  233.   // GroupBoxTo
  234.   // 
  235.   Self.GroupBoxTo.Controls.Add(Self.Label4);
  236.   Self.GroupBoxTo.Controls.Add(Self.Label5);
  237.   Self.GroupBoxTo.Controls.Add(Self.Label6);
  238.   Self.GroupBoxTo.Controls.Add(Self.TextBoxStateTo);
  239.   Self.GroupBoxTo.Controls.Add(Self.TextBoxCityTo);
  240.   Self.GroupBoxTo.Controls.Add(Self.TextBoxAddressTo);
  241.   Self.GroupBoxTo.Location := System.Drawing.Point.Create(376, 32);
  242.   Self.GroupBoxTo.Name := 'GroupBoxTo';
  243.   Self.GroupBoxTo.Size := System.Drawing.Size.Create(360, 72);
  244.   Self.GroupBoxTo.TabIndex := 4;
  245.   Self.GroupBoxTo.TabStop := False;
  246.   Self.GroupBoxTo.Text := '&To';
  247.   // 
  248.   // Label4
  249.   // 
  250.   Self.Label4.AutoSize := True;
  251.   Self.Label4.Location := System.Drawing.Point.Create(264, 24);
  252.   Self.Label4.Name := 'Label4';
  253.   Self.Label4.Size := System.Drawing.Size.Create(31, 16);
  254.   Self.Label4.TabIndex := 8;
  255.   Self.Label4.Text := 'State';
  256.   // 
  257.   // Label5
  258.   // 
  259.   Self.Label5.AutoSize := True;
  260.   Self.Label5.Location := System.Drawing.Point.Create(136, 24);
  261.   Self.Label5.Name := 'Label5';
  262.   Self.Label5.Size := System.Drawing.Size.Create(24, 16);
  263.   Self.Label5.TabIndex := 7;
  264.   Self.Label5.Text := 'City';
  265.   // 
  266.   // Label6
  267.   // 
  268.   Self.Label6.AutoSize := True;
  269.   Self.Label6.Location := System.Drawing.Point.Create(8, 24);
  270.   Self.Label6.Name := 'Label6';
  271.   Self.Label6.Size := System.Drawing.Size.Create(46, 16);
  272.   Self.Label6.TabIndex := 6;
  273.   Self.Label6.Text := 'Address';
  274.   // 
  275.   // TextBoxStateTo
  276.   // 
  277.   Self.TextBoxStateTo.Location := System.Drawing.Point.Create(264, 40);
  278.   Self.TextBoxStateTo.Name := 'TextBoxStateTo';
  279.   Self.TextBoxStateTo.Size := System.Drawing.Size.Create(80, 20);
  280.   Self.TextBoxStateTo.TabIndex := 2;
  281.   Self.TextBoxStateTo.Text := 'NY';
  282.   // 
  283.   // TextBoxCityTo
  284.   // 
  285.   Self.TextBoxCityTo.Location := System.Drawing.Point.Create(136, 40);
  286.   Self.TextBoxCityTo.Name := 'TextBoxCityTo';
  287.   Self.TextBoxCityTo.Size := System.Drawing.Size.Create(120, 20);
  288.   Self.TextBoxCityTo.TabIndex := 1;
  289.   Self.TextBoxCityTo.Text := 'New York';
  290.   // 
  291.   // TextBoxAddressTo
  292.   // 
  293.   Self.TextBoxAddressTo.Location := System.Drawing.Point.Create(8, 40);
  294.   Self.TextBoxAddressTo.Name := 'TextBoxAddressTo';
  295.   Self.TextBoxAddressTo.Size := System.Drawing.Size.Create(120, 20);
  296.   Self.TextBoxAddressTo.TabIndex := 0;
  297.   Self.TextBoxAddressTo.Text := '1535 Broadway';
  298.   // 
  299.   // MainMenu
  300.   // 
  301.   Self.MainMenu.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItem1, Self.MenuItem2, Self.MenuItem3));
  302.   // 
  303.   // MenuItem1
  304.   // 
  305.   Self.MenuItem1.Index := 0;
  306.   Self.MenuItem1.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItemDirection, Self.MenuItem4, Self.MenuItemExit));
  307.   Self.MenuItem1.Text := '&File';
  308.   // 
  309.   // MenuItemDirection
  310.   // 
  311.   Self.MenuItemDirection.Index := 0;
  312.   Self.MenuItemDirection.Shortcut := System.Windows.Forms.Shortcut.F9;
  313.   Self.MenuItemDirection.Text := 'Get &directions';
  314.   Include(Self.MenuItemDirection.Click, Self.MenuItemDirection_Click);
  315.   // 
  316.   // MenuItem4
  317.   // 
  318.   Self.MenuItem4.Index := 1;
  319.   Self.MenuItem4.Text := '-';
  320.   // 
  321.   // MenuItemExit
  322.   // 
  323.   Self.MenuItemExit.Index := 2;
  324.   Self.MenuItemExit.Text := 'E&xit';
  325.   Include(Self.MenuItemExit.Click, Self.MenuItemExit_Click);
  326.   // 
  327.   // MenuItem2
  328.   // 
  329.   Self.MenuItem2.Index := 1;
  330.   Self.MenuItem2.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItemCopy));
  331.   Self.MenuItem2.Text := 'Edit';
  332.   // 
  333.   // MenuItemCopy
  334.   // 
  335.   Self.MenuItemCopy.Index := 0;
  336.   Self.MenuItemCopy.Shortcut := System.Windows.Forms.Shortcut.CtrlC;
  337.   Self.MenuItemCopy.Text := 'Copy to clipboard';
  338.   Include(Self.MenuItemCopy.Click, Self.MenuItemCopy_Click);
  339.   // 
  340.   // MenuItem3
  341.   // 
  342.   Self.MenuItem3.Index := 2;
  343.   Self.MenuItem3.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MenuItemAbout));
  344.   Self.MenuItem3.Text := 'Help';
  345.   // 
  346.   // MenuItemAbout
  347.   // 
  348.   Self.MenuItemAbout.Index := 0;
  349.   Self.MenuItemAbout.Text := 'About';
  350.   Include(Self.MenuItemAbout.Click, Self.MenuItemAbout_Click);
  351.   // 
  352.   // StatusBar
  353.   // 
  354.   Self.StatusBar.Location := System.Drawing.Point.Create(0, 628);
  355.   Self.StatusBar.Name := 'StatusBar';
  356.   Self.StatusBar.Panels.AddRange(TSystem_Windows_Forms_StatusBarPanelArray.Create(Self.StatusBarPanel1));
  357.   Self.StatusBar.ShowPanels := True;
  358.   Self.StatusBar.Size := System.Drawing.Size.Create(736, 22);
  359.   Self.StatusBar.TabIndex := 5;
  360.   // 
  361.   // StatusBarPanel1
  362.   // 
  363.   Self.StatusBarPanel1.AutoSize := System.Windows.Forms.StatusBarPanelAutoSize.Spring;
  364.   Self.StatusBarPanel1.Width := 720;
  365.   // 
  366.   // ImageList
  367.   // 
  368.   Self.ImageList.ColorDepth := System.Windows.Forms.ColorDepth.Depth4Bit;
  369.   Self.ImageList.ImageSize := System.Drawing.Size.Create(16, 16);
  370.   Self.ImageList.ImageStream := (System.Windows.Forms.ImageListStreamer(resources.GetObject('ImageList.ImageStream')));
  371.   Self.ImageList.TransparentColor := System.Drawing.Color.White;
  372.   // 
  373.   // TabControl1
  374.   // 
  375.   Self.TabControl1.Anchor := (System.Windows.Forms.AnchorStyles((((System.Windows.Forms.AnchorStyles.Top 
  376.       or System.Windows.Forms.AnchorStyles.Bottom) or System.Windows.Forms.AnchorStyles.Left) 
  377.       or System.Windows.Forms.AnchorStyles.Right)));
  378.   Self.TabControl1.Controls.Add(Self.TabPageDirections);
  379.   Self.TabControl1.Controls.Add(Self.TabPageSoap);
  380.   Self.TabControl1.Location := System.Drawing.Point.Create(0, 112);
  381.   Self.TabControl1.Name := 'TabControl1';
  382.   Self.TabControl1.SelectedIndex := 0;
  383.   Self.TabControl1.Size := System.Drawing.Size.Create(736, 512);
  384.   Self.TabControl1.TabIndex := 7;
  385.   // 
  386.   // TabPageDirections
  387.   // 
  388.   Self.TabPageDirections.Controls.Add(Self.TextBoxDirection);
  389.   Self.TabPageDirections.Location := System.Drawing.Point.Create(4, 22);
  390.   Self.TabPageDirections.Name := 'TabPageDirections';
  391.   Self.TabPageDirections.Size := System.Drawing.Size.Create(728, 486);
  392.   Self.TabPageDirections.TabIndex := 0;
  393.   Self.TabPageDirections.Text := 'Directions';
  394.   // 
  395.   // TextBoxDirection
  396.   // 
  397.   Self.TextBoxDirection.Dock := System.Windows.Forms.DockStyle.Fill;
  398.   Self.TextBoxDirection.Location := System.Drawing.Point.Create(0, 0);
  399.   Self.TextBoxDirection.Multiline := True;
  400.   Self.TextBoxDirection.Name := 'TextBoxDirection';
  401.   Self.TextBoxDirection.ScrollBars := System.Windows.Forms.ScrollBars.Vertical;
  402.   Self.TextBoxDirection.Size := System.Drawing.Size.Create(728, 486);
  403.   Self.TextBoxDirection.TabIndex := 0;
  404.   Self.TextBoxDirection.Text := '';
  405.   // 
  406.   // TabPageSoap
  407.   // 
  408.   Self.TabPageSoap.Controls.Add(Self.TextBoxRequest);
  409.   Self.TabPageSoap.Controls.Add(Self.Splitter2);
  410.   Self.TabPageSoap.Controls.Add(Self.TextBoxResponse);
  411.   Self.TabPageSoap.Location := System.Drawing.Point.Create(4, 22);
  412.   Self.TabPageSoap.Name := 'TabPageSoap';
  413.   Self.TabPageSoap.Size := System.Drawing.Size.Create(728, 486);
  414.   Self.TabPageSoap.TabIndex := 1;
  415.   Self.TabPageSoap.Text := 'SOAP monitor';
  416.   // 
  417.   // TextBoxRequest
  418.   // 
  419.   Self.TextBoxRequest.Dock := System.Windows.Forms.DockStyle.Fill;
  420.   Self.TextBoxRequest.Font := System.Drawing.Font.Create('Courier New', 8.25, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (Byte(238)));
  421.   Self.TextBoxRequest.Location := System.Drawing.Point.Create(0, 0);
  422.   Self.TextBoxRequest.Multiline := True;
  423.   Self.TextBoxRequest.Name := 'TextBoxRequest';
  424.   Self.TextBoxRequest.ScrollBars := System.Windows.Forms.ScrollBars.Both;
  425.   Self.TextBoxRequest.Size := System.Drawing.Size.Create(728, 200);
  426.   Self.TextBoxRequest.TabIndex := 1;
  427.   Self.TextBoxRequest.Text := '';
  428.   Self.ToolTip.SetToolTip(Self.TextBoxRequest, 'Request');
  429.   Self.TextBoxRequest.WordWrap := False;
  430.   // 
  431.   // Splitter2
  432.   // 
  433.   Self.Splitter2.Dock := System.Windows.Forms.DockStyle.Bottom;
  434.   Self.Splitter2.Location := System.Drawing.Point.Create(0, 200);
  435.   Self.Splitter2.Name := 'Splitter2';
  436.   Self.Splitter2.Size := System.Drawing.Size.Create(728, 8);
  437.   Self.Splitter2.TabIndex := 3;
  438.   Self.Splitter2.TabStop := False;
  439.   // 
  440.   // TextBoxResponse
  441.   // 
  442.   Self.TextBoxResponse.Dock := System.Windows.Forms.DockStyle.Bottom;
  443.   Self.TextBoxResponse.Font := System.Drawing.Font.Create('Courier New', 8.25, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (Byte(238)));
  444.   Self.TextBoxResponse.Location := System.Drawing.Point.Create(0, 208);
  445.   Self.TextBoxResponse.Multiline := True;
  446.   Self.TextBoxResponse.Name := 'TextBoxResponse';
  447.   Self.TextBoxResponse.ScrollBars := System.Windows.Forms.ScrollBars.Both;
  448.   Self.TextBoxResponse.Size := System.Drawing.Size.Create(728, 278);
  449.   Self.TextBoxResponse.TabIndex := 2;
  450.   Self.TextBoxResponse.Text := '';
  451.   Self.ToolTip.SetToolTip(Self.TextBoxResponse, 'Response');
  452.   Self.TextBoxResponse.WordWrap := False;
  453.   // 
  454.   // ToolBar1
  455.   // 
  456.   Self.ToolBar1.Buttons.AddRange(TSystem_Windows_Forms_ToolBarButtonArray.Create(Self.ToolBarButton1, Self.ToolBarButtonDirection, Self.ToolBarButton3, Self.ToolBarButtonCopy));
  457.   Self.ToolBar1.DropDownArrows := True;
  458.   Self.ToolBar1.ImageList := Self.ImageList;
  459.   Self.ToolBar1.Location := System.Drawing.Point.Create(0, 0);
  460.   Self.ToolBar1.Name := 'ToolBar1';
  461.   Self.ToolBar1.ShowToolTips := True;
  462.   Self.ToolBar1.Size := System.Drawing.Size.Create(736, 28);
  463.   Self.ToolBar1.TabIndex := 8;
  464.   Self.ToolBar1.Wrappable := False;
  465.   Include(Self.ToolBar1.ButtonClick, Self.ToolBar1_ButtonClick);
  466.   // 
  467.   // ToolBarButton1
  468.   // 
  469.   Self.ToolBarButton1.Style := System.Windows.Forms.ToolBarButtonStyle.Separator;
  470.   // 
  471.   // ToolBarButtonDirection
  472.   // 
  473.   Self.ToolBarButtonDirection.ImageIndex := 1;
  474.   Self.ToolBarButtonDirection.ToolTipText := 'Get directions';
  475.   // 
  476.   // ToolBarButton3
  477.   // 
  478.   Self.ToolBarButton3.Style := System.Windows.Forms.ToolBarButtonStyle.Separator;
  479.   // 
  480.   // ToolBarButtonCopy
  481.   // 
  482.   Self.ToolBarButtonCopy.ImageIndex := 0;
  483.   Self.ToolBarButtonCopy.ToolTipText := 'Copy to clipboard';
  484.   // 
  485.   // TMainForm
  486.   // 
  487.   Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  488.   Self.ClientSize := System.Drawing.Size.Create(736, 650);
  489.   Self.Controls.Add(Self.ToolBar1);
  490.   Self.Controls.Add(Self.TabControl1);
  491.   Self.Controls.Add(Self.StatusBar);
  492.   Self.Controls.Add(Self.GroupBoxTo);
  493.   Self.Controls.Add(Self.GroupBoxFrom);
  494.   Self.Menu := Self.MainMenu;
  495.   Self.MinimumSize := System.Drawing.Size.Create(744, 500);
  496.   Self.Name := 'TMainForm';
  497.   Self.Text := 'MapQuest web service client';
  498.   Include(Self.Load, Self.TMainForm_Load);
  499.   Self.GroupBoxFrom.ResumeLayout(False);
  500.   Self.GroupBoxTo.ResumeLayout(False);
  501.   (System.ComponentModel.ISupportInitialize(Self.StatusBarPanel1)).EndInit;
  502.   Self.TabControl1.ResumeLayout(False);
  503.   Self.TabPageDirections.ResumeLayout(False);
  504.   Self.TabPageSoap.ResumeLayout(False);
  505.   Self.ResumeLayout(False);
  506. end;
  507. {$ENDREGION}
  508.  
  509. procedure TMainForm.Dispose(Disposing: Boolean);
  510. begin
  511.   if Disposing then
  512.   begin
  513.     if Components <> nil then
  514.       Components.Dispose();
  515.   end;
  516.   inherited Dispose(Disposing);
  517. end;
  518.  
  519. constructor TMainForm.Create;
  520. begin
  521.   inherited Create;
  522.   //
  523.   // Required for Windows Form Designer support
  524.   //
  525.   InitializeComponent;
  526.   //
  527.   // TODO: Add any constructor code after InitializeComponent call
  528.   //
  529. end;
  530.  
  531. // Reference:
  532. // http://bdn.borland.com/article/0,1410,28835,00.html
  533.  
  534. procedure TMainForm.FindDirection;
  535. var
  536.   MapQuest: IMapQuestservice;
  537.   Ar: IAsyncResult;
  538. begin
  539.   TextBoxRequest.Text := '';
  540.   TextBoxResponse.Text := '';
  541.   TextBoxDirection.Text := '';
  542.   WaitingForResult := True;
  543.   UpdateStatusBar(RsConnecting);
  544.   Update;
  545.   try
  546.     MapQuest := IMapQuestservice.Create;
  547.     UpdateStatusBar(RsGettingData);
  548.     Ar := MapQuest.BeginGetDirections(TextBoxAddressFrom.Text, TextBoxCityFrom.Text, TextBoxStateFrom.Text, 'US',
  549.       TextBoxAddressTo.Text, TextBoxCityTo.Text, TextBoxStateTo.Text, 'US', GetDirectionsCallBack, MapQuest);
  550.     Assert(not Ar.CompletedSynchronously);
  551.   except
  552.     on E: Exception do
  553.       HandleException(E);
  554.   end;
  555. end;
  556.  
  557. procedure TMainForm.GetDirectionsCallBack(Ar: IAsyncResult);
  558. var
  559.   MapQuest: IMapQuestservice;
  560.   Direction: string;
  561. begin
  562.   MapQuest := IMapQuestservice(Ar.AsyncState);
  563.   try
  564.     Direction := MapQuest.EndGetDirections(Ar);
  565.     Invoke(Delegate(@FSyncTextBoxes), [TextBoxDirection, Direction.Replace(#10, #13#10)]);
  566.   except
  567.     on E: Exception do
  568.       HandleException(E);
  569.   end;
  570. end;
  571.  
  572. procedure TMainForm.HandleException(E: Exception);
  573. var
  574.   Sync: TExceptionHandlerDelegate;
  575. begin
  576.   if not InvokeRequired then
  577.   begin
  578.     WaitingForResult := False;
  579.     UpdateStatusBar(RsError);
  580.     MessageBox.Show(E.Message, 'Error', MessageBoxButtons.OK, MessageBoxIcon.Error);
  581.   end
  582.   else
  583.   begin
  584.     Sync := HandleException;
  585.     Invoke(Delegate(@Sync), [E]);
  586.   end;  
  587. end;
  588.  
  589. procedure TMainForm.SetWaitingForResult(const Value: Boolean);
  590. begin
  591.   FWaitingForResult := Value;
  592.   MenuItemDirection.Enabled := not Value;
  593.   ToolBarButtonDirection.Enabled := not Value;
  594.   if not Value then
  595.     UpdateStatusBar('');
  596. end;
  597.  
  598. procedure TMainForm.Sync_TextBoxText(Control: TextBox; Content: string);
  599. begin
  600.   Control.Text := Content;
  601.   Control.Update;
  602.   if Control = TextBoxDirection then
  603.     WaitingForResult := False;
  604. end;
  605.  
  606. procedure TMainForm.MonitorSoapRequest(Sender: TObject; const Xml: string);
  607. begin
  608.   Invoke(Delegate(@FSyncTextBoxes), [TextBoxRequest, TSoapMonitor.FormatXmlData(Xml)]);
  609. end;
  610.  
  611. procedure TMainForm.MonitorSoapResponse(Sender: TObject; const Xml: string);
  612. begin
  613.   Invoke(Delegate(@FSyncTextBoxes), [TextBoxResponse, TSoapMonitor.FormatXmlData(Xml)]);
  614. end;
  615.  
  616. procedure TMainForm.UpdateStatusBar(const Text: string);
  617. begin
  618.   StatusBarPanel1.Text := Text;
  619.   StatusBar.Update;
  620. end;
  621.  
  622. procedure TMainForm.ToolBar1_ButtonClick(sender: System.Object; e: System.Windows.Forms.ToolBarButtonClickEventArgs);
  623. begin
  624.   if e.Button = ToolBarButtonDirection then
  625.     MenuItemDirection_Click(sender, e)
  626.   else
  627.   if e.Button = ToolBarButtonCopy then
  628.     MenuItemCopy_Click(sender, e);
  629. end;
  630.  
  631. procedure TMainForm.MenuItemAbout_Click(sender: System.Object; e: System.EventArgs);
  632. begin
  633.   TAboutBox.ShowAboutBox;
  634. end;
  635.  
  636. procedure TMainForm.MenuItemCopy_Click(sender: System.Object; e: System.EventArgs);
  637. begin
  638.   Clipboard.SetDataObject(TextBoxDirection.Text, True);
  639. end;
  640.  
  641. procedure TMainForm.TMainForm_Load(sender: System.Object; e: System.EventArgs);
  642. begin
  643.   FSyncTextBoxes := Sync_TextBoxText;
  644.   Include(SoapMonitor.OnRequest, MonitorSoapRequest);
  645.   Include(SoapMonitor.OnResponse, MonitorSoapResponse);
  646.   UpdateStatusBar(RsInfo);
  647. end;
  648.  
  649. procedure TMainForm.MenuItemDirection_Click(sender: System.Object; e: System.EventArgs);
  650. begin
  651.   FindDirection;
  652. end;
  653.  
  654. procedure TMainForm.MenuItemExit_Click(sender: System.Object; e: System.EventArgs);
  655. begin
  656.   Application.Exit;
  657. end;
  658.  
  659. end.
  660.  
  661.  
  662.  
  663.