babbels4princess
asked on
calling procedures and getting results!
i have a very long piece of code in my program which calculates the values from addition of different boxes from an invoice. i've got this procedure on two forms, one to create an invoice and one to amend it. what i need to do is call the procedure which is on form3 from form20! help! here is basically what i have so far and it does nothing.
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, .....
type
TForm3 = class(TForm)
Label10: TLabel;
Label11: TLabel;
.....
procedure Timer1Timer(Sender: TObject);
procedure Calculate1Click(Sender: TObject);
procedure calculate;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses Unit2, Unit14, Unit17;
{$R *.dfm}
procedure tform3.calculate;
var
dedit1, dedit2, dedit3, dedit4, dedit5, dedit6, dedit7, dedit8, dedit9,
dedit10, dedit11, dedit12 :real;
dedit13: currency;.....
begin
if DBedit75.Text='' then ded1:= 0 else ded1:= strtoint(DBedit75.Text);
if DBedit99.Text='' then ded2......
..... DBEdit163.Text:= currtostr(dedit13);
end;
procedure TForm3.Calculate1Click(Sen der: TObject);
begin
calculate; <---- this is it called in form3
end;
....
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
unit Unit20;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, printers, Mask, DBCtrls, ExtCtrls, DB, ADODB, Menus;
type
TForm20 = class(TForm)
DBNavigator1: TDBNavigator;
procedure MenuItem5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form20: TForm20;
implementation
uses Unit14, unit3;
{$R *.dfm}
procedure TForm20.MenuItem10Click(Se nder: TObject);
begin
form3.calculate; <---- this is it called in form20
end;
.....
THANKYOU!!!!
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, .....
type
TForm3 = class(TForm)
Label10: TLabel;
Label11: TLabel;
.....
procedure Timer1Timer(Sender: TObject);
procedure Calculate1Click(Sender: TObject);
procedure calculate;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses Unit2, Unit14, Unit17;
{$R *.dfm}
procedure tform3.calculate;
var
dedit1, dedit2, dedit3, dedit4, dedit5, dedit6, dedit7, dedit8, dedit9,
dedit10, dedit11, dedit12 :real;
dedit13: currency;.....
begin
if DBedit75.Text='' then ded1:= 0 else ded1:= strtoint(DBedit75.Text);
if DBedit99.Text='' then ded2......
..... DBEdit163.Text:= currtostr(dedit13);
end;
procedure TForm3.Calculate1Click(Sen
begin
calculate; <---- this is it called in form3
end;
....
--------------------------
unit Unit20;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, printers, Mask, DBCtrls, ExtCtrls, DB, ADODB, Menus;
type
TForm20 = class(TForm)
DBNavigator1: TDBNavigator;
procedure MenuItem5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form20: TForm20;
implementation
uses Unit14, unit3;
{$R *.dfm}
procedure TForm20.MenuItem10Click(Se
begin
form3.calculate; <---- this is it called in form20
end;
.....
THANKYOU!!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, well i can call it but it doesn't seem to use the data of the second form. i call the procedure from form3 with this..
with form20 do form3.calculate;
but it uses the data from form3 instead of 'with form20'
with form20 do form3.calculate;
but it uses the data from form3 instead of 'with form20'
function TForm3.calculate(v1, v2, v3, v4: string) : double;
var netamt: double
begin
if v1 <> '' then netamt:= netamt + strtofloat(v1);
if v2 <> '' then netamt:= netamt + strtofloat(v2);
if v3 <> '' then netamt:= netamt + strtofloat(v3);
if v4 <> '' then netamt:= netamt + strtofloat(v4);
Result:=netamt;
end;
procedure TForm3.Calculate1Click(Sen
begin
edit5.text:=floattostr(cal
end;
Now in Form20, add the Form20 in the uses clause under implementation
procedure TForm20.MenuItem10Click(Se
begin
edit5.text:=floattostr(for
end;
considering that edit1, edit2, edit3, edit4, edit5 are TEdit components placed on both the forms.
if the above code works fine then you can replace the TEdits with TDBEdits.
var
dedit1, dedit2, dedit3, dedit4, dedit5, dedit6, dedit7, dedit8, dedit9,
dedit10, dedit11, dedit12 :real;
dedit13: currency;.....
before the implementation keywordof your unit 3
-> make it global
(currently it is local and is discarded,
if the scope comes out of this procedure)
meikl ;-)