Howdy, Stranger!

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

Categories

Function or Procedure?

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

when you look at the code above ,would you rather use a function or a procedure and why? , could you please just demonstate how with this example please , thanks in advance , i need the subroutine and the call please help i wanna understand.

Comments

  • zibadianzibadian Member Posts: 6,349
    : procedure TfrmBursary.btnCategoryClick(Sender: Tobject);
    : : var
    : : CategoryStr : String;
    : : begin
    : : CategoryStr := // subroutine call
    : : lblCategory.Caption := 'Bursary: ' + CategoryStr;
    : : end; // end procedure TfrmRoadRace.btnCategoryClick
    : :
    :
    : when you look at the code above ,would you rather use a function or a procedure and why? , could you please just demonstate how with this example please , thanks in advance , i need the subroutine and the call please help i wanna understand.
    :
    :
    I get the feeling, that you already asked this question and I answered: http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=4&MsgID=309485&Setting=A9999F0001

    As for the why: a function doesn't need an intermediate results variable. This means that you can use a function as a kind of variable and don't need the CategoryStr variable:
    [code]
    function CategoryStrFunc: string;
    begin
    Result := 'My Category';
    end;

    procedure TfrmBursary.btnCategoryClick(Sender: Tobject);
    begin
    lblCategory.Caption := 'Bursary: ' + CategoryStrFunc;
    end; // end procedure TfrmRoadRace.btnCategoryClick
    [/code]
Sign In or Register to comment.