Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help subroutines!!!!

jvosjvos Posts: 10Member
Hi there im wanting to understand subroutines , here is my code:

procedure TfrmCompareUpgrades.btnScoreClick(Sender: TObject);
const
SpeedFactor = 2.0;
MemoryFactor = 3.5;
VideoFactor = 4.5;
PriceFactor = -0.75;
var
Score : Double;
begin
Score:=(sedSpeed1.Value * SpeedFactor) +
(sedMem1.Value * MemoryFactor) +
(sedVid1.Value * VideoFactor) +
(StrToFloat(edtPrice.Text)*PriceFactor);
lblScore1.Caption := FloatToStrF(Score, ffFixed , 7 , 2);
end;

I need to write a function with a function call for lines 10-14.

procedure TWhileLoopDemo.btnTransferClick(Sender: TObject);
var
strOutput: string;
begin
strOutput := edtInput.Text;
while (Length(strOutput) < 8) do
strOutput := strOutput + strOutput;
lblOutput.Caption := strOutput;
end;

I need to write a procedure with a procedure call for lines 6-7.

// a subroutine to evaluate the applicant

procedure TfrmBursary.btnCategoryClick(Sender: Tobject);
var
CategoryStr : String;
begin
CategoryStr := // subroutine call
lblCategory.Caption := 'Bursary: ' + CategoryStr;
end; // end procedure TfrmRoadRace.btnCategoryClick

I need to write a subroutine and subroutine call

Please have a look and see if anyone can help with creating these subroutines , i dont know if its possible but if it is please help so that i can go through it to try and understand how they work
Thanks in advance
Kind regards
jv

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi there im wanting to understand subroutines , here is my code:
    :
    : procedure TfrmCompareUpgrades.btnScoreClick(Sender: TObject);
    : const
    : SpeedFactor = 2.0;
    : MemoryFactor = 3.5;
    : VideoFactor = 4.5;
    : PriceFactor = -0.75;
    : var
    : Score : Double;
    : begin
    : Score:=(sedSpeed1.Value * SpeedFactor) +
    : (sedMem1.Value * MemoryFactor) +
    : (sedVid1.Value * VideoFactor) +
    : (StrToFloat(edtPrice.Text)*PriceFactor);
    : lblScore1.Caption := FloatToStrF(Score, ffFixed , 7 , 2);
    : end;
    :
    : I need to write a function with a function call for lines 10-14.
    :
    : procedure TWhileLoopDemo.btnTransferClick(Sender: TObject);
    : var
    : strOutput: string;
    : begin
    : strOutput := edtInput.Text;
    : while (Length(strOutput) < 8) do
    : strOutput := strOutput + strOutput;
    : lblOutput.Caption := strOutput;
    : end;
    :
    : I need to write a procedure with a procedure call for lines 6-7.
    :
    : // a subroutine to evaluate the applicant
    :
    : procedure TfrmBursary.btnCategoryClick(Sender: Tobject);
    : var
    : CategoryStr : String;
    : begin
    : CategoryStr := // subroutine call
    : lblCategory.Caption := 'Bursary: ' + CategoryStr;
    : end; // end procedure TfrmRoadRace.btnCategoryClick
    :
    : I need to write a subroutine and subroutine call
    :
    : Please have a look and see if anyone can help with creating these subroutines , i dont know if its possible but if it is please help so that i can go through it to try and understand how they work
    : Thanks in advance
    : Kind regards
    : jv
    :
    :
    A subroutine is called a procedure in Delphi. It is defined by using the [b]procedure[/b] reserved word. Here is a sample of a very simple one:
    [code]
    procedure ShowMyMessage(Message: string);
    begin
    ShowMessage('Me: '+Message);
    end;
    [/code]
    You call your own defined procedure like any other "standard" Delphi procedures, as long as it's defined before the calling code.

    A function is a procedure, which returns a result, and is defined using the [b]function[/b] reserved word. The following example adds two integers together:
    [code]
    function AddIntegers(A, B: integer): integer;
    begin
    Result := A + B;
    end;
    [/code]
    As before, a custom-designed function is called the same way as "standard" Delphi functions, like FloatToStrF().
    For more info on the words [b]procedure[/b] and [b]function[/b] read the help files.
Sign In or Register to comment.