Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Delphi]Suspending A Thread (class(TThread))

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Dec 28, 2007 9:39 am    Post subject: [Delphi]Suspending A Thread (class(TThread)) Reply with quote

While i had no internet (connection problem with ISP) i didn't know how to use threads, so i opend up delphi's 7e help topic and searched for "TThread", i found many intresting topics about it, well i just wanted to know how to declare a thread class and use it, and i did (i memorized some of db's code too), anyways when i'm suspending a thread i get an access violation error, why ?

my code:

Code:
unit Unit1;

interface

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

type
 TMyThread = class(TThread)
  private
  {Private Dec}
  protected
  Procedure RunApp;
  Procedure Increase;
  Procedure Exit;
  end;

type
 TMyThreadTwo = class(TThread)
  private
  {Private Dec}
  protected
  Procedure Suspendit;
  Procedure Resumeit;
  End;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  MyThread: TMyThread;
  MyThreadTwo: TMyThreadTwo;
 
implementation

{$R *.dfm}
Procedure TMyThreadTwo.Resumeit;
begin
MyThread.Resume;
End;

Procedure TMyThreadTwo.Suspendit;
begin
MyThread.Suspend;
end;

Procedure TMyThread.Increase;
var i:integer;
begin
for i:=1 to 90 do
begin
Form1.Edit1.Text:=IntToStr(StrToInt(Form1.Edit1.Text)+1);
End;
end;

Procedure TMyThread.Exit;
begin
application.Terminate;
end;

Procedure TMyThread.RunApp;
var
X:integer;Y:integer;
begin
Y:=StrToInt(Form1.Edit1.Text);
for X:=1 to Y do begin ShowMessage('Hi');
if ((X mod 4)= 0) then MyThread.Suspend; //ShowMessage(IntToStr(X));
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
MyThread.RunApp;
//MyThread.Increase;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
{MyThreadTwo.Suspendit;}
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
MyThreadTwo.Resumeit;
end;

end.
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Fri Dec 28, 2007 1:40 pm    Post subject: Reply with quote

Add this code in FormCreate:
Code:
MyThread:=TMyThread.Create(true);
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Dec 28, 2007 3:54 pm    Post subject: Reply with quote

HolyBlah wrote:
Add this code in FormCreate:
Code:
MyThread:=TMyThread.Create(true);


ok, thanks this solve my error.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites