OnChange event vs. OnExit Event and data passing

Perhaps if I ask my question in a different manner it might be more clear.

I am coding an application that creates a financial analysis of several persons’ income, adjustments to income, and expenses.  It is on a form with twenty three tab sheets.  Each tab sheet is a different facet of the financial picture.  Each tab sheet has five columns of between eight and fifteen floatedit boxes to input data.  Each tab sheet has a summation in a label at the bottom of the column, and each floatedit box’s data is to be printed on a individual sheet with the same five columns. 

So it appears as such for the Income sheet:

Source of income		Party One   Party Two   Party Three   Party Four   Party Five
Regular W-2 Income	Floatedit1	Floatedit16	Floatedit31	Floatedit46 and on
Overtime Income		Floatedit2
Bonus Income		Floatedit3

      And on

Royalty Income		Floatedit15	Floatedit30	Floatedit45	Floatedit60 and on
_____________________________________________________________________
	Total Gross Income Label1.Caption	and on 		Label4.caption


I had originally had an “OnChange” event on each floatedit box, that assigned the value of the box to a data passing variable, and summed up all of the values for the column, then converted it to a string for the label.caption.  I found that the data passing variable was not visible outside of the OnChange event procedure; the updated label displayed from inside the procedure.  Consequently, I was unable to either write or save to a file any of the values for the float edit boxes.

I am now in the process of implementing “OnExit” events for each float edit box and deleting the “OnChange” events and removing the reference to each.

My question is “Will the use of an “OnExit” event solve my problem or is there another way to design this to do all of the following: read and write the values to a stream, update the summation labels, and print the values.

Any suggestions would be greatly appreciated.  Thank you in advance, John Shyer
0
John
7/7/2015 10:55:26 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

5 Replies
1970 Views

Similar Articles

[PageSpeed] 55
Get it on Google Play
Get it on Apple App Store

John wrote:

> I had originally had an “OnChange” event on each floatedit box, that
> assigned the value of the box to a data passing variable, and summed
> up all of the values for the column, then converted it to a string for
> the label.caption.

I would not have used the OnChange event for that.  OnChange is triggered 
on every keystroke, etc.  It would be better to use a button or menu or something 
to tally up the values once the user has finished entering them all.  Using 
OnChange in this manner would only make sense if you need the UI to reflect 
the current values in real-time as the user is still typing them.  But if 
you switch to the OnExit event, you will lose that to some extent.  Also, 
what if the user makes a mistake, a finger slips, etc? Do you really want 
to pop up an error message right away, or give the user time to realize the 
problem and fix it before you process it?

> I found that the data passing variable was not visible outside of the
> OnChange event procedure; the updated label displayed from inside
> the procedure.  Consequently, I was unable to either write or save
> to a file any of the values for the float edit boxes.

Then you did not code your logic correctly.  For example, are you storing 
your values in local variables instead of in global/member variables?  How 
exactly are you trying to write your values to a file, and what problem are 
you having with it exactly?

> I am now in the process of implementing “OnExit” events for each float
> edit box and deleting the “OnChange” events and removing the reference
> to each.

That will not solve your problem.  All that will do is change the sematics 
of *when* the code is called, but not *what* the code does when it is called. 
 So you still have to solve the original problem.

> My question is “Will the use of an “OnExit” event solve my problem

No.

> or is there another way to design this to do all of the following: read
> and write the values to a stream, update the summation labels, and
> print the values.

What problem exactly are you having with doing all of that inside your event 
handler(s)?

-- 
Remy Lebeau (TeamB)
0
Remy
7/7/2015 11:07:53 PM
Remy,

	Thank you for your very quick and detailed answer.

First, I am setting the value equal to a variable named in a global data unit, e.g.,

Unit UnitGlobalFinancialDataContainerJune302015:
interface
Var
  p1i1, p1i2, p1i3, p1i4, p1i5, p1i6, p1i7, p1i8, p1i9, p1i10 : Double;
  p1i11, p1i12 : double;

            And so on for a lot of variables
  //
  //
implementation
end.

Then this unit is in the uses section of my financial information form:

e.g.,
unit FormDetailedFinancialInformationInputFormMarch292015;
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, NumEdit, ComCtrls, ElastFrm, Printers,
  UnitGlobalARRAYDataHoldingUnitMarch262015,
  UnitGlobalFinancialDataContainerJune302015,
and on for several more units and forms
Menus;


type
  TFormDetailedFinancialInformationInputForm = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TtabSheet;

    And on for over eight hundred floatedit boxes definitons and procedured

   private
    { Private declarations }
    public
    { Public declarations }
     FinancialMainRec : TFinancialMainRec;
     RecordStream1 : TRecordStream1;
    end;

var
    FormDetailedFinancialInformationInputForm:TFormDetailedFinancialInformationInputForm;
    //
    R : TRect;
    //
implementation

uses FormBasicInputOutputRoutinesONEMarch302015;

{$R *.DFM}

all of the OnExit Procedures, then the form activate procedure

procedure TFormDetailedFinancialInformationInputForm.FormActivate(Sender: TObject);
begin
    //
    // Fill edit boxes with data from file
    //
    Label829.Caption    := CaseName;
    //
    FloatEdit1.value    := PartyONERegW2Income;
    FloatEdit2.value    := PartyONEOvertime;
    FloatEdit3.value    := PartyONECommissionsBonus;
end;
and on and on to the input procedure

procedure TFormDetailedFinancialInformationInputForm.OpenExistingCaseFile1Click(
  Sender: TObject);
begin
    //
    FormBasicInputOutputRoutinesForm.inputfromfile;
    //
    //
    // Fill edit boxes with data from file
    //
    Label829.Caption    := CaseName;
    //
    FloatEdit1.value    := PartyONERegW2Income;
    FloatEdit2.value    := PartyONEOvertime;
    FloatEdit3.value    := PartyONECommissionsBonus;


end;
and on and on to the save file procedure

procedure TFormDetailedFinancialInformationInputForm.Save1Click(Sender: TObject);
begin
    //
    FormBasicInputOutputRoutinesForm.outputtofile;
    //
end;

Then I moved the print procedure from a separate unit to this form:

procedure TFormDetailedFinancialInformationInputForm.Print2Click(
  Sender: TObject);

Var
    //  Set up date/time stamp
     Present : TDateTime;
     Year, Month, Day, Hour, Min, Sec, MSec: Word;
     Mnth, indicator, minute, DateTimeStr : string;
     //
     R : TRect;
     //
     // Calculate date and time code
     //
     UnitPrintMetricsUnit2May132015.PrinterLandscape;
     //
     //printer.begindoc;
     //
     // Print Page Header
          //
          Printer.Canvas.Font.Size := 14;
          Printer.Canvas.Font.Style := [fsBold];
          Printer.Canvas.Font.Name := 'Arial';
          TempStr1 := 'CaseName';
          Printer.Canvas.TextOut(XLPos05, YLPos03, TempStr1);
          TempStr2 := 'CaseCourtNumber';
          Printer.Canvas.TextOut(XLPos87, YLPos03, TempStr2);
 
  And on and on for a LOT of print commands such as:

Printer.Canvas.Font.Size := 11;
          //
          // First Column "A" variables
          //
          R := Rect(XLPos40, YLPOs18, XLPos40 + 500, YLPOs18 + 100);
          TempStr1 := '$' + FloatToStrF(p1AllSourcesTotal, ffNumber, 12, 0);
          printer.Canvas.TextRect(R, TempStr1, [tfRight]);
	
{where the XLPosxx and YLPosyy are calculated in a unit called UnitPrinterMetrics and is in the uses section of the form.
          //
          //
      Printer.NewPage;
          //
          //
Twenty two more pages then

        //
    Printer.enddoc:
end;

The code in this form exceeds 35,000 lines, so it is big and cumbersome.  Should I take the print code back out and put it in a separate unit?

The variable above p1AllSourcesTotal (and all variables are printed as ZERO) the values do not get received by the print section, even though they are in the “UnitGlobalARRAYDataHoldingUnitMarch262015,” unit.

I thought about using a button to do the addition into the summation label, but that seemed unlike all accounting forms I have seen wherein the sum is automatically updated as the user inputs new values.  Are there any other options?

Finally, I very much appreciate your taking the time to help me.  Thank you, John


> {quote:title=John Shyer wrote:}{quote}
> Perhaps if I ask my question in a different manner it might be more clear.
> 
> I am coding an application that creates a financial analysis of several persons’ income, adjustments to income, and expenses.  It is on a form with twenty three tab sheets.  Each tab sheet is a different facet of the financial picture.  Each tab sheet has five columns of between eight and fifteen floatedit boxes to input data.  Each tab sheet has a summation in a label at the bottom of the column, and each floatedit box’s data is to be printed on a individual sheet with the same five columns. 
> 
> So it appears as such for the Income sheet:
> 
> Source of income		Party One   Party Two   Party Three   Party Four   Party Five
> Regular W-2 Income	Floatedit1	Floatedit16	Floatedit31	Floatedit46 and on
> Overtime Income		Floatedit2
> Bonus Income		Floatedit3
> 
>       And on
> 
> Royalty Income		Floatedit15	Floatedit30	Floatedit45	Floatedit60 and on
> _____________________________________________________________________
> 	Total Gross Income Label1.Caption	and on 		Label4.caption
> 
> 
> I had originally had an “OnChange” event on each floatedit box, that assigned the value of the box to a data passing variable, and summed up all of the values for the column, then converted it to a string for the label.caption.  I found that the data passing variable was not visible outside of the OnChange event procedure; the updated label displayed from inside the procedure.  Consequently, I was unable to either write or save to a file any of the values for the float edit boxes.
> 
> I am now in the process of implementing “OnExit” events for each float edit box and deleting the “OnChange” events and removing the reference to each.
> 
> My question is “Will the use of an “OnExit” event solve my problem or is there another way to design this to do all of the following: read and write the values to a stream, update the summation labels, and print the values.
> 
> Any suggestions would be greatly appreciated.  Thank you in advance, John Shyer
0
John
7/7/2015 11:49:02 PM
John wrote:

> The code in this form exceeds 35,000 lines, so it is big and
> cumbersome.

It also does not really deomnstrate the problem you are trying to solve.

> The variable above p1AllSourcesTotal (and all variables are printed as
> ZERO) the values do not get received by the print section, even though
> they are in the “UnitGlobalARRAYDataHoldingUnitMarch262015,” unit.

For that to happen, given the code you have shown, FloatEdit1Change() and 
Print2Click() would have to be accessing a different set of variables in 
memory, or you are doing something to corrupt memory in code you have not 
shown.  Have you tried using the debugger, or debug output statements, to 
validate that the variables FloatEdit1Change() is assigning are the same 
physical variables that Print2Click() is reading from?  If you make a change 
to an edit box, then do a print, and then make another edit box change, does 
the second change event still see the original values OK, or does it now 
see zeros as well?

-- 
Remy Lebeau (TeamB)
0
Remy
7/8/2015 12:13:16 AM
I will go back and examine all occurrences of the variables by doing a search on the variable name.  Hopefully, I will be able to find out where either the variable changes or where it is being corrupted.
Thank you again.  BTW the 35k lines of code was only meant to show that it was big and cumbersome, not to help solve the problem.  John 


> {quote:title=John Shyer wrote:}{quote}
> Perhaps if I ask my question in a different manner it might be more clear.
> 
> I am coding an application that creates a financial analysis of several persons’ income, adjustments to income, and expenses.  It is on a form with twenty three tab sheets.  Each tab sheet is a different facet of the financial picture.  Each tab sheet has five columns of between eight and fifteen floatedit boxes to input data.  Each tab sheet has a summation in a label at the bottom of the column, and each floatedit box’s data is to be printed on a individual sheet with the same five columns. 
> 
> So it appears as such for the Income sheet:
> 
> Source of income		Party One   Party Two   Party Three   Party Four   Party Five
> Regular W-2 Income	Floatedit1	Floatedit16	Floatedit31	Floatedit46 and on
> Overtime Income		Floatedit2
> Bonus Income		Floatedit3
> 
>       And on
> 
> Royalty Income		Floatedit15	Floatedit30	Floatedit45	Floatedit60 and on
> _____________________________________________________________________
> 	Total Gross Income Label1.Caption	and on 		Label4.caption
> 
> 
> I had originally had an “OnChange” event on each floatedit box, that assigned the value of the box to a data passing variable, and summed up all of the values for the column, then converted it to a string for the label.caption.  I found that the data passing variable was not visible outside of the OnChange event procedure; the updated label displayed from inside the procedure.  Consequently, I was unable to either write or save to a file any of the values for the float edit boxes.
> 
> I am now in the process of implementing “OnExit” events for each float edit box and deleting the “OnChange” events and removing the reference to each.
> 
> My question is “Will the use of an “OnExit” event solve my problem or is there another way to design this to do all of the following: read and write the values to a stream, update the summation labels, and print the values.
> 
> Any suggestions would be greatly appreciated.  Thank you in advance, John Shyer
0
John
7/8/2015 12:19:19 AM
John wrote:

> I will go back and examine all occurrences of the variables
> by doing a search on the variable name.

It is not enough to just look for the names.  Examine the actual memory addresses 
of the variables.  Take note of the addresses for the variables that FloatEdit1Change() 
is assigning to, and then make sure that Print2Click() is reading values 
from the same memory addresses.

-- 
Remy Lebeau (TeamB)
0
Remy
7/8/2015 12:35:53 AM
Reply:

Similar Artilces:

How do I pass Event Args in an OnClick Event?
I am trying to use the OnClick call to a method to pass a parameter (an image URL in this case). Basically, I want this image button (ASP 2.0)<asp:ImageButton ID="btnUpdate" runat="server"  ImageUrl ="~/images/mikey.jpg" OnClick = "btnUpdate_Click" CommandName = "passUrl" CommandArgument = "ImageButton2.ImageUrl.ToString()"/>to pass its own ImageUrl to the following methodprotected void btnUpdate_Click(object sender, EventArgs e)    {       ImageButton1.ImageUrl = e.ToString();...

To implement an event with event-specific data
I would like to know how to implement an event with event-specific data.  Any insight on this would be a great help.  Joe JohnstonIf a picture is worth a 1000 words, a sample application is worth a 1000 blog entries Remember the Constitution!Dont forget to mark posts answered and resolved (if they are) Like this:  1 public class MyClass 2 { 3 public event EventHandler<MyCustomEventArgs> MyEvent; 4 } 5 6 // The custom event args class 7 public class MyCustomEventArgs : EventArgs 8 { 9 private readonly string _myStringProperty;...

C++ Events like Delphi events
Hello everyone, This is not exactly a doubt about Delphi programming, it is more related to C++ programming, but, as I´m used to Delphi programming, I´m a little confused with some aspects of C++ Programming.. The problem that I have is with object events on C++, for example, I have the simple classes: TMyObject = class private FEvent: TNotifyEvent; procedure TriggerEvent; public OnEvent: TNotifyEvent read FOnEvent write FOnEvent; end; OK, This is a simple class that I want to use on several different places in my program, inside several differ...

events: override Onxxxx vs .Event +=
if i want to respond to an event, is there a reason to use: control.Event += new EventHandler(control_Event); private void control_Event(object sender, Event~ e) { do things; } vs. protected override OnEvent(Event~ e) { base.Event(e); do things; } i see these used one way or another in all sorts of sample code, but i cannot find a reason to use one over the other. are they effectly the same? In the end, they do the same basic thing. In essence though, they are different depending on where they are used and for what re...

Onchange event being triggered during the onload event
For some reason the onChange event has just decided to trigger 3 times in my onLoad. I'm not sure what I've changed to make this happen. I've tried disabling the onChange event handler for the element by setting it to null but this doesn't help. Where are the onChange event handlers set for form fields? -- sue_lam ------------------------------------------------------------------------ Found it. After much searching. The onChange event is fired manually from the setValues and select functions. Shouldn't this be left up to the element's event ...

Mouse gesture events vs. touch events
Whats the difference between the Mouse gesture events [1] and the Touch events [2]? I read that touch-events (2) are for trackpads and screen touches, while mouse gestures (1) detect trackpad actions and mouse movements. My main goal is to detect a trackpad zoom gesture on OSX in a XULRunner App. I tried it with MozMagnifyGesture, but it does not get fired. I also changed the prefs according to the hints in [3], but the commands assigned never execute. Whats the recommended way of detecting trackpad "pinch" (zoom) gestures? [1]: https://developer.mozilla.org/En/Mouse_gestu...

button event vs masterpage Page_Load event
Hi, I'm updating a customer profile in an .aspx page and then click Update. In my Master Page, I want to refresh the customer infos when I click on the update button of the .aspx page. The problem is that I refresh my Master page BEFORE the button event is called so the master page customer's informations is a click behind. How can I force the page load event of the master page to be called AFTER I have updated my customer account information ? P.S. The customer account information is kept in a dictionnary in an Util class. Thanks ! Not sure if I follow correctly, you want ...

Passing value from one event to another event
I have Button One that when "on click" will perform some calculations based on user input within the form.  I have Button Two that, when "on click" I perform another calculation.  I need Button Two to use the value calculated in the Button One on-click event.  How do I pass this value to my Button Two on-click event?  For example: -----------------------------------------------------------------------publicInt32 intX;Int32 intY;Int32 intResultOne;Int32 intResultTwo; protected void btnOne_ClickintResultOne = intX + intY;lblResultOne.text = intResultO...

How to pass return value from one event to other event
Hi, I am developing the NVOs as Jaguar componets in which all the methods are created as a user defined events (no functions). This is because, i want to trigger a event by a variable referencing the event name, ie., the event names and paramaters are passed as a argument to the calling component ( say component one). The method in component one will trigger the event in another component (say component two) with the argument. Now I want to getback the event return value from the component two in the component one method. How to do this. Thanks in advance ...

Events and Event handlers
 Hi ,What are the Events and Event Handlers and How we create events and events handlers in asp.netand where we use .   adilahmed Hi, You can find a video about Events http://www.asp.net/learn/videos/ "Lesson 3" In general , an Event is fired when some thing [an event] happens and then you should choose your Event Handler [a function that is executed when the Event is fired]. In C#, to know about Events I think you should start with delegates [they simply points to the Event Handler fn.] and then go to Events and Event Handlers. In ASP.NET , the ...

FormView.ItemInserting Event vs. ObjectDataSource.Inserting Event
ObjectDataSource.Inserting EventFormView.ItemInserting Event which one is the appropriate one to use, and why?I have a FileUpload control inbedded in InsertItemTemplate in a FormView control and I want to be able to send a reference to a file to my business object. Fist I have to use row.FindControl so I can get hold of the FileUpload control, so that I can access its properties. Second, I want to add fileUpload.HttpPostedFile to the dictionary parameter collection (or any other FileUpload property that I would like to use). But in the first case (FormView.ItemInserting Event) I receive an e...

timepicker onchange event fires twice for single event
I have the following control in my XUL application: <timepicker id="time-picker" onchange="alert('time-picker: onchange');"/> When I run my application and click the up/down arrows of the control, the alert appears twice. For some reason the change event is firing twice for a single click on the up/down arrow. Am I doing something wrong, or is this a bug? Or is there a way to work around it? Thanks, -- Greg ...

Button click event vs button command event
Hi, Can any one tell me whats the difference between the two events, and when to use which one? Thanks. Check out this article on event bubbling: Bubbling Events Up the Control Hierarchy Summary: The DataGrid control, as you likely know, can easily be configured to add a column of buttons. By adding a ButtonColumn, whenever one of the DataGrid's buttons in the column is clicked, the Web page posts back and the DataGrid's ItemCommand event fires. In fact, the same behavior can be noted if you manually add a Button or LinkButton control into a DataGrid TemplateColum...

fireing event from event !!
When clicking the calendar controls I fire an event.. in that code I create another event from a linkbutton, but when clicking that event button nothing happends. I think its becausae the webform has forgotten all its variables or something... My Q: How can I fire an event from an event ??Jesus Loves You Hi, could you provide the code you already have in your experiment so we can see what you mean exactly? Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons. Here's my code.. I just posted the most relevant. not all ...

Web resources about - OnChange event vs. OnExit Event and data passing - embarcadero.delphi.general

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

OnFocus! OnBlur! OnChange! How I am going to learn how to code
I've been meaning to learn how to code beyond HTML for years now, but never have managed to do much more than borrow other people's cryptic code ...

CBC Television Series 1952 to 1982, A
A Is For Aardvark Wed 10:00-10:30 p.m., 7 Jul- 22 Sep 1954 Thu 10:30-11:00 p.m., 30Sep- 21 Oct 1954 A half- hour summer series, created, produced,and ...

DOTA2国际邀请赛全程比赛视频_新浪游戏看游戏_新浪游戏_新浪网
对抗游戏巨制Dota2于八月举行了国际邀请赛,邀请世界上各支著名Dota战队上演了精彩的Dota2大战,新浪看游戏特别推出Dota2邀请赛视频库,让你一次看个够。

閲嶈淇℃伅-閲嶅簡浜哄彛缃?/title>
鏈珯鎼滅储 浣滆€?/Option> 鏍囬 鍐呭 绠€浣?/A> 绻佷綋 璁句负棣栭〉 鍔犲叆鏀惰棌 鏀垮姟淇℃伅 鏈烘瀯鑱岃矗 淇℃伅鍏紑 閲嶈淇℃伅 宸ヤ綔淇℃伅 鍖哄幙淇℃伅 娉曞緥娉曡 閫氱煡鍏憡 澶т簨璁?/A> 鍔炰簨澶у巺 涓嬭浇涓績 璇佷欢鍔炵悊 琛屾斂瀹℃壒 ...

婀栧寳鐪佸叕瀹夊巺闂ㄦ埛缃戠珯骞冲畨鑽嗘缃?/title>
鐑偣鎺掕 鍏ㄧ渷487鍚嶆柊鐗硅缁撴潫鍩硅濂旇荡鍚勮嚜宀椾綅 鐪佸叕瀹夊巺鍓巺闀跨幇鍦烘寚鎸ラ珮绌烘晳浜?/a> 瀛熷缓鏌卞湪瑙傛懇鍏ㄥ浗鍏畨鐗硅澶х粌鍏垫垚鏋滄眹鎶ユ紨缁冨苟鍑哄腑鍏ㄥ浗鍏畨鐗硅闃熷缓璁惧骇璋堜細鏃跺己璋冩€荤粨缁忛獙鎶婃彙瑙勫緥 涓嶆柇鎻愬崌 ...

缃戜笂淇¤
... 蹇樿瀵嗙爜 鎮ㄥ綋鍓嶇殑浣嶇疆锛? 淇¤涓婚〉 淇¤鍏紑 鏍囬 鐣欒█鏃ユ湡 鎬绘暟 0 涓? - 棣?椤?涓婁竴椤? 涓嬩竴椤?鏈?椤点€€椤垫锛?font color=red> 0 /0椤点€€10鏉?椤点€€绗?select name='pagerNo' on ...

灞辫タ路楂樺钩-鍏紬鏈嶅姟
灞辫タ鏀垮簻缃?/a> 涓浗鏀垮簻缃?/a> 棣栥€€銆€椤?/a> 璧拌繘楂樺钩 璧勮涓績 缁勭粐鏈烘瀯 鍏氭斂棰嗗 鏀垮姟鍏紑 鎶曡祫鍒涗笟 楂樺钩鏃呮父 鍏紬鏈嶅姟 澶╂皵锛?/div> 11鏈?6鏃ュぉ姘斻€佺┖姘旀棩鎶?/a> 绔欏唴鎼滅储锛?/font> 棰嗗鑷磋緸 ...

2003 Acura CL Classifieds
To find a large selection of 2003 Acura CL used cars in the Automobile Magazine auto classifieds. Browse our vast inventory of used 2003 CL vehicles ...

Used Car Advanced Search - Automotive.com
Use our advanced search tool to view the used car classifieds at Automotive.com.

Resources last updated: 1/19/2016 4:59:22 AM