Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am trying to convert a simple method to a procedure with parameters, I need help with the calling statement as it is giving errors when i try to compile.

Code below:

unit Ass13;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin,
Vcl.Buttons;

type
TfrmFee = class(TForm)
btnLoss: TButton;
sedCycle: TSpinEdit;
sedRun: TSpinEdit;
gpbLossResults: TGroupBox;
lblFee: TLabel;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
procedure btnLossClick(Sender: TObject);
private
procedure GramsOff(HourRun, HourCycle : Integer; var GramOff : String);
public
{ Public declarations }
end;

var
frmFee: TfrmFee;

implementation

{$R *.dfm}

procedure TfrmFee.GramsOff(HourRun, HourCycle : Integer; var GramOff : String);
Var
TotalCal, GramsLost : Integer;
Begin
HourRun := (sedRun.Value * 475);
HourCycle := (sedCycle.Value * 200);
TotalCal := (HourRun + HourCycle);
GramsLost := (TotalCal * 10 DIV 77);
GramOff := 'Weight loss: ' + IntToStr(GramsLost) + ' grams';
end;

procedure TfrmFee.btnLossClick(Sender: TObject);
var
GramsOff : string;
begin
GramsOff (HourRun, HourCycle: Integer; GramOff : String);
lblResults.Caption := GramOff;

end;
end.



Working simple Method that I am trying to convert to a procedure/ function:

procedure TfrmBurningCalories.btnLossClick(Sender: TObject); var
TotalCal, GramsLost : Integer; begin
TotalCal := (sedCycle.Value * 200) + (sedRun.Value * 475);
Gramslost := TotalCal * 10 DIV 77;
lblLoss.Caption := 'Weight loss: ' + IntToStr(GramsLost) + ' grams';
end;
Posted
Updated 5-May-14 15:12pm
v2
Comments
Sergey Alexandrovich Kryukov 5-May-14 18:51pm    
What's the use of showing the code sample this way?! At least show the whole class. The question is way too trivial. Why not reading a regular language manual, to learn at least the basics?
So far, this is not code at all, just a work salad...
—SA
Member 10796847 5-May-14 19:22pm    
Hello, Thank you for the reply :)


I have created my own method which receives values from 2 spin edits but for some reason program is not compiling, when I am unable to call my procedure form the button.

Error messages I receive:
[dcc32 Error] Ass13.pas(50): E2066 Missing operator or semicolon
[dcc32 Error] Ass13.pas(50): E2003 Undeclared identifier: 'GramOff'
[dcc32 Error] Ass13.pas(51): E2003 Undeclared identifier: 'lblResults'
[dcc32 Error] Ass13.pas(51): E2066 Missing operator or semicolon
[dcc32 Hint] Ass13.pas(22): H2219 Private symbol 'GramsOff' declared but never used
[dcc32 Fatal Error] LstAss13.dpr(5): F2063 Could not compile used unit 'Ass13.pas'
Failed
Elapsed time: 00:00:02.2

_Please see code below:_

unit Ass13;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin,
Vcl.Buttons;

type
TfrmFee = class(TForm)
btnLoss: TButton;
sedCycle: TSpinEdit;
sedRun: TSpinEdit;
gpbLossResults: TGroupBox;
lblFee: TLabel;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
procedure btnLossClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure GramsOff(HourRun, HourCycle : Integer; var GramOff : String);
public
{ Public declarations }
end;

var
frmFee: TfrmFee;

implementation

{$R *.dfm}

procedure TfrmFee.FormCreate(Sender: TObject);
begin

end;

procedure TfrmFee.GramsOff(HourRun, HourCycle : Integer; var GramOff : String);
Var
TotalCal, GramsLost : Integer;
Begin
HourRun := (sedRun.Value * 475);
HourCycle := (sedCycle.Value * 200);
TotalCal := (HourRun + HourCycle);
GramsLost := (TotalCal * 10 DIV 77);
GramOff := 'Weight loss: ' + IntToStr(GramsLost) + ' grams';
end; //proc CalcFee

procedure TfrmFee.btnLossClick(Sender: TObject);
var
HourRun, HourCycle : integer;
GramsOff : string; //Declare a local varicable FeeStr
begin
GramsOff (HourRun, HourCycle, GramOff);
lblResults.Caption := GramOff;

end;
end.

Sergey Alexandrovich Kryukov 5-May-14 20:44pm    
What are you doing? Please move it to the question, using "Improve question". Put error messages in comments to relevant lines...
—SA
[no name] 5-May-14 19:56pm    
Just a quick look and digging through the cobwebs but doesn't "HourRun, HourCycle : Integer; var GramOff : String", HourRun need some sort of data type declaration?
Member 10796847 5-May-14 20:25pm    
I have declared them as follows but still receive errors..
The question is how do I call procedure GramsOff?
procedure TfrmFee.btnLossClick(Sender: TObject);
var
HourRun, HourCycle : integer;
GramsOff : string;
begin
GramsOff (HourRun, HourCycle: Integer; GramOff : String);
lblResults.Caption := GramOff;

end;

Errors received:
[dcc32 Error] Ass13.pas(50): E2066 Missing operator or semicolon
[dcc32 Error] Ass13.pas(50): E2029 ':=' expected but ':' found
[dcc32 Error] Ass13.pas(50): E2010 Incompatible types: 'string' and 'Integer'
[dcc32 Error] Ass13.pas(50): E2029 '(' expected but ')' found
[dcc32 Error] Ass13.pas(51): E2003 Undeclared identifier: 'lblResults'
[dcc32 Error] Ass13.pas(51): E2029 ')' expected but identifier 'Caption' found
[dcc32 Hint] Ass13.pas(22): H2219 Private symbol 'GramsOff' declared but never used
[dcc32 Fatal Error] LstAss13.dpr(5): F2063 Could not compile used unit 'Ass13.pas'
Failed
Elapsed time: 00:00:00.3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900