Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2006, 11:18 PM
Nakrom Nakrom is offline
Senior Member
 
Join Date: Feb 2006
Location: Cape Twon
Posts: 118
Send a message via MSN to Nakrom Send a message via Skype™ to Nakrom
Default Stack overflow error

Hi

i get a stack overflow error and i've tried to fix it, but it eludse me as to why this is happening.
Here is the code:

[DELPHI]
procedure TDMKP.ADOTableReceivingCountSheetLinesCalcFields(D ataSet: TDataSet);
var
TotalQuantity, NoPallets: Integer;
Tare, GrossMass, NetMass, UnitMass, TotalMass, AveUnitMass: real;
begin

GrossMass := 0;
Tare := 0;
NetMass := 0;
UnitMass := 0;
TotalQuantity := 0;
TotalMass := 0;
NoPallets := 0;
AveUnitMass := 0;

GrossMass := ADOTableReceivingCountSheetLines.fieldbyname('Gros sMass').AsFloat;
Tare := ADOTableReceivingCountSheetLines.fieldbyname('Tare ').AsFloat;
NetMass := GrossMass - Tare;
UnitMass := NetMass / ADOTableReceivingCountSheetLines.fieldbyname('Quan tity').AsFloat;

ADOTableReceivingCountSheetLines.First; // this is where the stack over flow error happens
while not ADOTableReceivingCountSheetLines.Eof do
begin
TotalQuantity := TotalQuantity + ADOTableReceivingCountSheetLines.fieldbyname('Quan tity').AsInteger;
ADOTableReceivingCountSheetLines.Next;
end;


// TotalMass := =Nz(Sum([Quantity]),0)
// AverageUnitMass := =IIf([TotalQuantity],Round([TotalMass]/[TotalQuantity],1))
// NoPallets := Count([PalletID])

ADOTableReceivingCountSheetLines['NetMass'] := FormatFloat('0.0', NetMass);
ADOTableReceivingCountSheetLines['UnitMass'] := FormatFloat('0.0', UnitMass);
ADOTableReceivingCountSheetLines['TotalQuantity'] := FormatFloat('0', TotalQuantity);
ADOTableReceivingCountSheetLines['TotalMass'] := FormatFloat('0.0', TotalMass);
ADOTableReceivingCountSheetLines['NoPallets'] := FormatFloat('0', NoPallets);
ADOTableReceivingCountSheetLines['AveUnitMass'] := FormatFloat('0', AveUnitMass);

end;
[/DELPHI]


Thanks

Markus

Loyalty is everything, except Honor.
Reply With Quote
  #2  
Old 11-21-2006, 11:54 PM
MerijnB MerijnB is offline
Senior Member
 
Join Date: Mar 2001
Posts: 452
Default RE: Stack overflow error

when you call ADOTableReceivingCountSheetLines.First;

doesn't that call trigger a new OnCalcFields event?

(which calls .First, which triggers a new event... thus stack overflow).
Reply With Quote
  #3  
Old 11-22-2006, 12:17 AM
Nakrom Nakrom is offline
Senior Member
 
Join Date: Feb 2006
Location: Cape Twon
Posts: 118
Send a message via MSN to Nakrom Send a message via Skype™ to Nakrom
Default RE: Stack overflow error

Then how can I do this? How can i get this calculation done?


Thanks

Markus

Loyalty is everything, except Honor.
Reply With Quote
  #4  
Old 11-22-2006, 12:48 AM
MerijnB MerijnB is offline
Senior Member
 
Join Date: Mar 2001
Posts: 452
Default RE: Stack overflow error

I think the problem lies somewhere else... how is it possible that for calculations of one record you need to know data from all other records?
Reply With Quote
  #5  
Old 11-22-2006, 02:33 AM
daltamira daltamira is offline
Senior Member
 
Join Date: Aug 2006
Location: Argentina
Posts: 959
Default RE: Stack overflow error

Create an ADOQuery for that calculation:
[delphi]
with ADOQueryGetTotalQuantity do begin
Close;
SQL.Clear;
SQL.Add('SELECT SUM(Quantity) AS TotalQuantity FROM TheTableName');
Open;
TotalQuantity := FieldByName('TotalQuantity').Value;
end;
[/delphi]

Replace this code when you do a loop over the Table, as MerijnB says, you cannot do it, every time you move the record point an OnCalcFields event is triggiered.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:18 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.