| |

VerySource

 Forgot password?
 Register
Search
View: 1133|Reply: 4

How to call other functions in the thread?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-24 15:00:01
| Show all posts |Read mode
such as
class t1: TThread
{
 void __fastcall Execute ();
}

class main: TControl
{
 void main_f1;
}

void __fastcall t1 :: Execute ()
{
// I want to call main_f1 here
}

Prompt cannot find the entire function, but using vcl function in Execute is OK.
Can anyone explain this?
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-11 16:15:01
| Show all posts
Of course, members of the class need to be called by an instance of the class, or a static function, which can be called by the class name.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-5-12 10:15:01
| Show all posts
Give a simple example
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-5-19 20:15:01
| Show all posts
You can pass a pointer to main in the TThread constructor

Then call
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-7-4 19:15:01
| Show all posts
__fastcall t1::t1(bool CreateSuspended, main *M)
        : TThread(CreateSuspended)

Add a main *m to the class;

Assign M to M in the constructor: m=M;

Call m->main_f1 like this in Excute;

If it still doesn't work, use Synchronize(FUNCTION)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list