Howdy, Stranger!

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

Categories

Call Statement

Hello, again.

The following code is ALL under the "onclick" of a single function:

procedure Tcontrol_panel.ButstartClick(Sender: TObject);

[code]var
coord:integer;
uname, buy, sell, spam :string;
begin
ShellExecute(Handle, 'open', 'magic1.exe', nil, 'C:Program FilesWizards of the CoastMagic Online', 10);
repeat coord:=AU3_pixelgetcolor (460,420);
sleep (500);
until
(coord=9802661);
AU3_WinSetState ('Magic Online V2.', '',SW_MAXIMIZE );
[color=Red]//login section[/color]
inifile:=Tinifile.Create('./OH_BOT.ini');
uname:=inifile.ReadString('UserInfo','Accountname','');
AU3_Send (uname,0);
sleep (500);
AU3_Send ('{TAB}',0);
AU3_Send (edipassword.Text,0);
sleep (500);
AU3_MouseClick ('left',500,440,1,5);
repeat coord:=AU3_pixelgetcolor (554,294);
sleep (500);
until
(coord=13620438);
[color=Red]//Message Board - Buying[/color]
Sleep (1000);
AU3_Send ('/join Message Board - Buying',0);
AU3_Send ('{ENTER}',0);
Sleep (300);
repeat AU3_MouseClick ('left',400,167,1,5);
coord:=AU3_pixelgetcolor (400,167);
sleep (1000);
until
(coord=8224125);
AU3_MouseClick ('left',200,455,1,5);
buy:=inifile.ReadString('Spam','MessageBoard-Buyers','');
AU3_Send (buy,0);
Sleep (300);
AU3_Send ('{ENTER}',0);
Sleep (300);
AU3_MouseClick ('left',744,150,1,10);
[color=Red]//Message Board - Selling[/color]
Sleep (1000);
AU3_Send ('/join Message Board - Selling',0);
AU3_Send ('{ENTER}',0);
Sleep (300);
repeat AU3_MouseClick ('left',400,167,1,5);
coord:=AU3_pixelgetcolor (400,167);
sleep (1000);
until
(coord=8224125);
AU3_MouseClick ('left',200,455,1,5);
sell:=inifile.ReadString('Spam','MessageBoard-Sellers','');
AU3_Send (sell,0);
Sleep (300);
AU3_Send ('{ENTER}',0);
Sleep (300);
AU3_MouseClick ('left',744,150,1,10);
[color=Red]//Spam Room[/color]
Sleep (1000);
spam:=inifile.ReadString('Spam','Room2Spam','');
AU3_Send ('/join '+ spam,0);
AU3_Send ('{ENTER}',0);
Sleep (300);
AU3_Send ('hello',0);
[color=Red]//message settings[/color]
IniFile.Free;

end;
[/code]

I would like to move [color=Red]sections[/color] into their own area:
and call them from another area.
can someone please explain how I can do this?
Thank you

ps. please dont laugh at my code, I am still learning :)

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello, again.
    :
    : The following code is ALL under the "onclick" of a single function:
    :
    : procedure Tcontrol_panel.ButstartClick(Sender: TObject);
    :
    : [code]: var
    : coord:integer;
    : uname, buy, sell, spam :string;
    : begin
    : ShellExecute(Handle, 'open', 'magic1.exe', nil, 'C:Program FilesWizards of the CoastMagic Online', 10);
    : repeat coord:=AU3_pixelgetcolor (460,420);
    : sleep (500);
    : until
    : (coord=9802661);
    : AU3_WinSetState ('Magic Online V2.', '',SW_MAXIMIZE );
    : [color=Red]//login section[/color]
    : inifile:=Tinifile.Create('./OH_BOT.ini');
    : uname:=inifile.ReadString('UserInfo','Accountname','');
    : AU3_Send (uname,0);
    : sleep (500);
    : AU3_Send ('{TAB}',0);
    : AU3_Send (edipassword.Text,0);
    : sleep (500);
    : AU3_MouseClick ('left',500,440,1,5);
    : repeat coord:=AU3_pixelgetcolor (554,294);
    : sleep (500);
    : until
    : (coord=13620438);
    : [color=Red]//Message Board - Buying[/color]
    : Sleep (1000);
    : AU3_Send ('/join Message Board - Buying',0);
    : AU3_Send ('{ENTER}',0);
    : Sleep (300);
    : repeat AU3_MouseClick ('left',400,167,1,5);
    : coord:=AU3_pixelgetcolor (400,167);
    : sleep (1000);
    : until
    : (coord=8224125);
    : AU3_MouseClick ('left',200,455,1,5);
    : buy:=inifile.ReadString('Spam','MessageBoard-Buyers','');
    : AU3_Send (buy,0);
    : Sleep (300);
    : AU3_Send ('{ENTER}',0);
    : Sleep (300);
    : AU3_MouseClick ('left',744,150,1,10);
    : [color=Red]//Message Board - Selling[/color]
    : Sleep (1000);
    : AU3_Send ('/join Message Board - Selling',0);
    : AU3_Send ('{ENTER}',0);
    : Sleep (300);
    : repeat AU3_MouseClick ('left',400,167,1,5);
    : coord:=AU3_pixelgetcolor (400,167);
    : sleep (1000);
    : until
    : (coord=8224125);
    : AU3_MouseClick ('left',200,455,1,5);
    : sell:=inifile.ReadString('Spam','MessageBoard-Sellers','');
    : AU3_Send (sell,0);
    : Sleep (300);
    : AU3_Send ('{ENTER}',0);
    : Sleep (300);
    : AU3_MouseClick ('left',744,150,1,10);
    : [color=Red]//Spam Room[/color]
    : Sleep (1000);
    : spam:=inifile.ReadString('Spam','Room2Spam','');
    : AU3_Send ('/join '+ spam,0);
    : AU3_Send ('{ENTER}',0);
    : Sleep (300);
    : AU3_Send ('hello',0);
    : [color=Red]//message settings[/color]
    : IniFile.Free;
    :
    : end;
    : [/code]:
    :
    : I would like to move [color=Red]sections[/color] into their own area:
    : and call them from another area.
    : can someone please explain how I can do this?
    : Thank you
    :
    : ps. please dont laugh at my code, I am still learning :)
    :
    Write a new method:
    [code]
    procedure TForm1.LogIn();
    begin
    Inifile := TInifile.Create('./OH_BOT.ini');
    Uname := Inifile.ReadString('UserInfo', 'Accountname' ,'');
    AU3_Send(Uname, 0);
    Sleep(500);
    AU3_Send('{TAB}',0);
    AU3_Send(edipassword.Text,0);
    Sleep(500);
    AU3_MouseClick('left',500,440,1,5);
    repeat
    coord := AU3_pixelgetcolor(554,294);
    sleep(500);
    until (coord = 13620438);
    end;
    [/code]
    Then you can call that method from the OnClick():
    [code]
    var
    coord: integer;
    uname, buy, sell, spam: string;
    begin
    ShellExecute(Handle, 'open', 'magic1.exe', nil, 'C:Program FilesWizards of the CoastMagic Online', 10);
    repeat
    coord := AU3_pixelgetcolor(460,420);
    Sleep(500);
    until (coord = 9802661);
    AU3_WinSetState('Magic Online V2.', '',SW_MAXIMIZE );
    LogIn();
    [/code]

    The other sections can be split in the same way.
  • caspert_ghostcaspert_ghost Member Posts: 53

    : Write a new method:
    : [code]:
    : procedure TForm1.LogIn();
    : begin
    : Inifile := TInifile.Create('./OH_BOT.ini');
    : Uname := Inifile.ReadString('UserInfo', 'Accountname' ,'');
    : AU3_Send(Uname, 0);
    : Sleep(500);
    : AU3_Send('{TAB}',0);
    : AU3_Send(edipassword.Text,0);
    : Sleep(500);
    : AU3_MouseClick('left',500,440,1,5);
    : repeat
    : coord := AU3_pixelgetcolor(554,294);
    : sleep(500);
    : until (coord = 13620438);
    : end;
    : [/code]:
    : Then you can call that method from the OnClick():
    : [code]:
    : var
    : coord: integer;
    : uname, buy, sell, spam: string;
    : begin
    : ShellExecute(Handle, 'open', 'magic1.exe', nil, 'C:Program FilesWizards of the CoastMagic Online', 10);
    : repeat
    : coord := AU3_pixelgetcolor(460,420);
    : Sleep(500);
    : until (coord = 9802661);
    : AU3_WinSetState('Magic Online V2.', '',SW_MAXIMIZE );
    : LogIn();
    : [/code]:
    :
    : The other sections can be split in the same way.
    :

    [Pascal Error] OH_Bot.pas(314): E2003 Undeclared identifier: 'LogIn'

    obviously it needs declared..
    do I declar it as a "type" procedure, as a var, uses clause, or ??
    thank you again
  • zibadianzibadian Member Posts: 6,349
    :
    : : Write a new method:
    : : [code]: :
    : : procedure TForm1.LogIn();
    : : begin
    : : Inifile := TInifile.Create('./OH_BOT.ini');
    : : Uname := Inifile.ReadString('UserInfo', 'Accountname' ,'');
    : : AU3_Send(Uname, 0);
    : : Sleep(500);
    : : AU3_Send('{TAB}',0);
    : : AU3_Send(edipassword.Text,0);
    : : Sleep(500);
    : : AU3_MouseClick('left',500,440,1,5);
    : : repeat
    : : coord := AU3_pixelgetcolor(554,294);
    : : sleep(500);
    : : until (coord = 13620438);
    : : end;
    : : [/code]: :
    : : Then you can call that method from the OnClick():
    : : [code]: :
    : : var
    : : coord: integer;
    : : uname, buy, sell, spam: string;
    : : begin
    : : ShellExecute(Handle, 'open', 'magic1.exe', nil, 'C:Program FilesWizards of the CoastMagic Online', 10);
    : : repeat
    : : coord := AU3_pixelgetcolor(460,420);
    : : Sleep(500);
    : : until (coord = 9802661);
    : : AU3_WinSetState('Magic Online V2.', '',SW_MAXIMIZE );
    : : LogIn();
    : : [/code]: :
    : :
    : : The other sections can be split in the same way.
    : :
    :
    : [Pascal Error] OH_Bot.pas(314): E2003 Undeclared identifier: 'LogIn'
    :
    : obviously it needs declared..
    : do I declar it as a "type" procedure, as a var, uses clause, or ??
    : thank you again
    :
    You need to add it to the form's type declaration:
    [code]
    type
    TForm1 = class(TForm)
    ... // Components & methods added by compiler
    private
    // User added private methods
    public
    // User added private methods
    procedure LogIn();
    end;
    [/code]
    The code above is an example of how to add it as a public method. See help files for differences between public and private methods.
    Note: fields should always be private and properties always public or protected.
  • caspert_ghostcaspert_ghost Member Posts: 53
    : You need to add it to the form's type declaration:
    : [code]:
    : type
    : TForm1 = class(TForm)
    : ... // Components & methods added by compiler
    : private
    : // User added private methods
    : public
    : // User added private methods
    : procedure LogIn();
    : end;
    : [/code]:
    : The code above is an example of how to add it as a public method.
    : See help files for differences between public and private methods.
    : Note: fields should always be private and properties always public
    : or protected.

    Thank you so very much.

    one final question on this topic.
    During the login, msg, spm etc. etc. sections I want to do a if color change statement...

    ANYTIME during ANY of these procedures if color= "color" (which will be either disconect box or trade request box) I want it to stop ALL procedures
    and go directly to "named procedure"
    is this possible?
  • zibadianzibadian Member Posts: 6,349
    : : You need to add it to the form's type declaration:
    : : [code]: :
    : : type
    : : TForm1 = class(TForm)
    : : ... // Components & methods added by compiler
    : : private
    : : // User added private methods
    : : public
    : : // User added private methods
    : : procedure LogIn();
    : : end;
    : : [/code]: :
    : : The code above is an example of how to add it as a public method.
    : : See help files for differences between public and private methods.
    : : Note: fields should always be private and properties always public
    : : or protected.
    :
    : Thank you so very much.
    :
    : one final question on this topic.
    : During the login, msg, spm etc. etc. sections I want to do a if
    : color change statement...
    :
    : ANYTIME during ANY of these procedures if color= "color" (which will
    : be either disconect box or trade request box) I want it to stop ALL
    : procedures
    : and go directly to "named procedure"
    : is this possible?
    :
    Of course. Anything is possible. The easiest way to code this is to let each method call the next one at its end. Thus:
    [code]
    procedure Login();
    begin
    ...
    if color=white then
    Buying()
    else if color=blue then
    Selling();
    end;
    [/code]
    Another way is to make each method a function, which returns a color:
    [code]
    function TForm1.LogIn(): integer;
    begin
    ...
    if wantToSell then
    Result := Blue
    else
    Result := White;
    end;
    [/code]
    In your OnClick() you can then do the following:
    [code]
    ColorState = LogIn();
    repeat
    case ColorState of
    White: ColorState := Buying();
    Blue: ColorState := Selling();
    end;
    until ColorState = red;
    [/code]
    This makes the flow much more flexible, but more difficult to debug.
  • caspert_ghostcaspert_ghost Member Posts: 53
    : Of course. Anything is possible. The easiest way to code this is to
    : let each method call the next one at its end. Thus:
    : [code]:
    : procedure Login();
    : begin
    : ...
    : if color=white then
    : Buying()
    : else if color=blue then
    : Selling();
    : end;
    : [/code]:
    : Another way is to make each method a function, which returns a color:
    : [code]:
    : function TForm1.LogIn(): integer;
    : begin
    : ...
    : if wantToSell then
    : Result := Blue
    : else
    : Result := White;
    : end;
    : [/code]:
    : In your OnClick() you can then do the following:
    : [code]:
    : ColorState = LogIn();
    : repeat
    : case ColorState of
    : White: ColorState := Buying();
    : Blue: ColorState := Selling();
    : end;
    : until ColorState = red;
    : [/code]:
    : This makes the flow much more flexible, but more difficult to debug.

    Would a ttimer continuasly looking for color change be better?
    its not for "buy/sell" its looking if connection has been lost or not (which is a pop up box) this needs to see if the box is there from start of program to end (the close) of program.
Sign In or Register to comment.