Howdy, Stranger!

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

Categories

Procedures

Im New to Delphi, I just tried to create a small game.I created a new procedure, and i cant use my other objects(TImage) Within that procedure.Can anyone tell why its happening and the solution for that.ThankYou

Comments

  • pritaeaspritaeas Member Posts: 274
    Hi. Hard to say. Please show us some code.

    pritaeas

    : Im New to Delphi, I just tried to create a small game.I created a new
    : procedure, and i cant use my other objects(TImage) Within that
    : procedure.Can anyone tell why its happening and the solution for
    : that.ThankYou

  • pak77pak77 Member Posts: 28
    : Im New to Delphi, I just tried to create a small game.I created a new procedure, and i cant use my other objects(TImage) Within that procedure.Can anyone tell why its happening and the solution for that.ThankYou
    :
    Have you declared the form you are using within the procedure? Are you makin a call directly to the image object? Does it work if you type

    Form1.Image1.... within the procedure.
  • savi_bloodmarksavi_bloodmark Member Posts: 7
    : Hi. Hard to say. Please show us some code.
    :
    : pritaeas
    :
    : : Im New to Delphi, I just tried to create a small game.I created a new
    : : procedure, and i cant use my other objects(TImage) Within that
    : : procedure.Can anyone tell why its happening and the solution for
    : : that.ThankYou
    :
    :

    Yeap this is my whole code:

    unit Unit2;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, ExtCtrls;

    type
    TMainGame = class(TForm)
    GameBack: TImage;
    XBut: TImage;
    OBut: TImage;
    Button1: TImage;
    Button2: TImage;
    Button3: TImage;
    Button6: TImage;
    Button5: TImage;
    Button4: TImage;
    Button9: TImage;
    Button8: TImage;
    PlayerImage: TImage;
    Button7: TImage;
    Blank: TImage;

    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);

    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    MainGame: TMainGame;
    PlayerNo: Integer;

    implementation

    {$R *.dfm}

    procedure TMainGame.FormCreate(Sender: TObject);
    begin
    PLayerNo:=1;
    Button1.Picture := Blank.Picture ;
    Button2.Picture := Blank.Picture ;
    Button3.Picture := Blank.Picture ;
    Button4.Picture := Blank.Picture ;
    Button5.Picture := Blank.Picture ;
    Button6.Picture := Blank.Picture ;
    Button7.Picture := Blank.Picture ;
    Button8.Picture := Blank.Picture ;
    Button9.Picture := Blank.Picture ;

    end;

    Procedure FindOutGame();
    begin

    end;

    procedure TMainGame.Button1Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button1.Enabled:= false;
    button1.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button1.Enabled := false;
    button1.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.Button2Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button2.Enabled:= false;
    button2.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button2.Enabled := false;
    button2.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.Button3Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button3.Enabled:= false;
    button3.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button3.Enabled := false;
    button3.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.Button4Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button4.Enabled:= false;
    button4.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button4.Enabled := false;
    button4.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.button5Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button5.Enabled:= false;
    button5.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button5.Enabled := false;
    button5.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.button6Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button6.Enabled:= false;
    button6.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button6.Enabled := false;
    button6.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.button7Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button7.Enabled:= false;
    button7.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button7.Enabled := false;
    button7.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.button8Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button8.Enabled:= false;
    button8.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button8.Enabled := false;
    button8.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;

    procedure TMainGame.button9Click(Sender: TObject);
    begin
    if playerno=1 then
    begin
    button9.Enabled:= false;
    button9.Picture := Xbut.Picture;
    playerno:=2;
    end
    else
    begin
    button9.Enabled := false;
    button9.Picture := Obut.Picture;
    playerno:=1;
    end;
    FindOutGame();
    end;
    end.

    **** The Problem is i cant use the playerimage within the findoutgame Procedure.

    Thanx alot.

  • zibadianzibadian Member Posts: 6,349
    [b][red]This message was edited by zibadian at 2004-5-6 9:18:59[/red][/b][hr]
    : : Hi. Hard to say. Please show us some code.
    : :
    : : pritaeas
    : :
    : : : Im New to Delphi, I just tried to create a small game.I created a new
    : : : procedure, and i cant use my other objects(TImage) Within that
    : : : procedure.Can anyone tell why its happening and the solution for
    : : : that.ThankYou
    : :
    : :
    :
    : Yeap this is my whole code:
    :
    : unit Unit2;
    :
    : interface
    :
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, ExtCtrls;
    :
    : type
    : TMainGame = class(TForm)
    : GameBack: TImage;
    : XBut: TImage;
    : OBut: TImage;
    : Button1: TImage;
    : Button2: TImage;
    : Button3: TImage;
    : Button6: TImage;
    : Button5: TImage;
    : Button4: TImage;
    : Button9: TImage;
    : Button8: TImage;
    : PlayerImage: TImage;
    : Button7: TImage;
    : Blank: TImage;
    :
    : procedure FormCreate(Sender: TObject);
    : procedure Button1Click(Sender: TObject);
    : procedure Button2Click(Sender: TObject);
    : procedure Button3Click(Sender: TObject);
    : procedure Button4Click(Sender: TObject);
    : procedure Button5Click(Sender: TObject);
    : procedure Button6Click(Sender: TObject);
    : procedure Button7Click(Sender: TObject);
    : procedure Button8Click(Sender: TObject);
    : procedure Button9Click(Sender: TObject);
    :
    : private
    : { Private declarations }
    : public
    : { Public declarations }
    : end;
    :
    : var
    : MainGame: TMainGame;
    : PlayerNo: Integer;
    :
    : implementation
    :
    : {$R *.dfm}
    :
    : procedure TMainGame.FormCreate(Sender: TObject);
    : begin
    : PLayerNo:=1;
    : Button1.Picture := Blank.Picture ;
    : Button2.Picture := Blank.Picture ;
    : Button3.Picture := Blank.Picture ;
    : Button4.Picture := Blank.Picture ;
    : Button5.Picture := Blank.Picture ;
    : Button6.Picture := Blank.Picture ;
    : Button7.Picture := Blank.Picture ;
    : Button8.Picture := Blank.Picture ;
    : Button9.Picture := Blank.Picture ;
    :
    : end;
    :
    : Procedure FindOutGame();
    : begin
    :
    : end;
    :
    : procedure TMainGame.Button1Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button1.Enabled:= false;
    : button1.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button1.Enabled := false;
    : button1.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.Button2Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button2.Enabled:= false;
    : button2.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button2.Enabled := false;
    : button2.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.Button3Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button3.Enabled:= false;
    : button3.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button3.Enabled := false;
    : button3.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.Button4Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button4.Enabled:= false;
    : button4.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button4.Enabled := false;
    : button4.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.button5Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button5.Enabled:= false;
    : button5.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button5.Enabled := false;
    : button5.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.button6Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button6.Enabled:= false;
    : button6.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button6.Enabled := false;
    : button6.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.button7Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button7.Enabled:= false;
    : button7.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button7.Enabled := false;
    : button7.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.button8Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button8.Enabled:= false;
    : button8.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button8.Enabled := false;
    : button8.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    :
    : procedure TMainGame.button9Click(Sender: TObject);
    : begin
    : if playerno=1 then
    : begin
    : button9.Enabled:= false;
    : button9.Picture := Xbut.Picture;
    : playerno:=2;
    : end
    : else
    : begin
    : button9.Enabled := false;
    : button9.Picture := Obut.Picture;
    : playerno:=1;
    : end;
    : FindOutGame();
    : end;
    : end.
    :
    : **** The Problem is i cant use the playerimage within the findoutgame Procedure.
    :
    : Thanx alot.
    :
    :
    You can use it, but you need to specify the form on which the image is located. Like this:
    [code]
    Procedure FindOutGame();
    begin
    Form1.Caption := Form1.PlayerImage.Name;
    end;
    [/code]


  • savi_bloodmarksavi_bloodmark Member Posts: 7
    : : Im New to Delphi, I just tried to create a small game.I created a new procedure, and i cant use my other objects(TImage) Within that procedure.Can anyone tell why its happening and the solution for that.ThankYou
    : :
    : Have you declared the form you are using within the procedure? Are you makin a call directly to the image object? Does it work if you type
    :
    : Form1.Image1.... within the procedure.
    :
    Thanx Alot Its Working now.
  • savi_bloodmarksavi_bloodmark Member Posts: 7
    Thanx Alot Its Working now.
  • savi_bloodmarksavi_bloodmark Member Posts: 7
    Hi Im Still creating my small silly game.Im still stuck on it.
    I created These procedures.THe Order is

    Function Checkwin(A,B,C:Integer):Integer;
    Procedure DisWin();
    Procedure FindOutGame();
    procedure NewGame();

    The Problem is i cannot call the procedure NewGame within Diswin procedure.Can u please help me.!


    Thanx Alot
  • zibadianzibadian Member Posts: 6,349
    : Hi Im Still creating my small silly game.Im still stuck on it.
    : I created These procedures.THe Order is
    :
    : Function Checkwin(A,B,C:Integer):Integer;
    : Procedure DisWin();
    : Procedure FindOutGame();
    : procedure NewGame();
    :
    : The Problem is i cannot call the procedure NewGame within Diswin procedure.Can u please help me.!
    :
    :
    : Thanx Alot
    :
    You need to reorder the procedures, so that the called procedure is listed before the calling procedure. Remember that the compiler reads the file from top to bottom, and a each line only knows everything it has read before that line.
  • savi_bloodmarksavi_bloodmark Member Posts: 7
    : : Hi Im Still creating my small silly game.Im still stuck on it.
    : : I created These procedures.THe Order is
    : :
    : : Function Checkwin(A,B,C:Integer):Integer;
    : : Procedure DisWin();
    : : Procedure FindOutGame();
    : : procedure NewGame();
    : :
    : : The Problem is i cannot call the procedure NewGame within Diswin procedure.Can u please help me.!
    : :
    : :
    : : Thanx Alot
    : :
    : You need to reorder the procedures, so that the called procedure is listed before the calling procedure. Remember that the compiler reads the file from top to bottom, and a each line only knows everything it has read before that line.
    :

    Yeap But the problem is but im calling the procedure diswin within newgame and Checkwin within findoutgame. and i want to call newgame within diswin.
  • zibadianzibadian Member Posts: 6,349
    : : : Hi Im Still creating my small silly game.Im still stuck on it.
    : : : I created These procedures.THe Order is
    : : :
    : : : Function Checkwin(A,B,C:Integer):Integer;
    : : : Procedure DisWin();
    : : : Procedure FindOutGame();
    : : : procedure NewGame();
    : : :
    : : : The Problem is i cannot call the procedure NewGame within Diswin procedure.Can u please help me.!
    : : :
    : : :
    : : : Thanx Alot
    : : :
    : : You need to reorder the procedures, so that the called procedure is listed before the calling procedure. Remember that the compiler reads the file from top to bottom, and a each line only knows everything it has read before that line.
    : :
    :
    : Yeap But the problem is but im calling the procedure diswin within newgame and Checkwin within findoutgame. and i want to call newgame within diswin.
    :
    Then you can use the forward directive to declare the procedure without implementing it. Here's an example:
    [code]
    procedure NewGame(); forward;
    // From this point on the word NewGame exists as a procedure without parameters

    Function Checkwin(A,B,C:Integer):Integer;
    begin
    end;

    Procedure DisWin();
    begin
    ...
    NewGame();
    ...
    end;

    Procedure FindOutGame();
    begin
    end;

    procedure NewGame();
    // This declaration must precisely match the previous declaration
    begin
    ...
    DisWin();
    ...
    end;

    [/code]
Sign In or Register to comment.