51

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

Why you so are afraid of code simplification?

YuRock , what for this question?
I after all am technically competent like set the task on the Test example?
Or you want to hear - that becomes in Real procedure, or even to see?
I after all wrote about it already a little!
There 2 files are opened on reading, there is a cycle of their byte comparing (automatic machine), and at special situations the Decision of the operator is required, results get to 3rd file, on the form - 4 text  with the intermediate results and still a type Window as in the Hex-editor (Offsety, Neh-values and literal correspondence).
And you want these open files and procedures to take and close and then again them to pull opening-closing and transmission of variables between procedures?
Is not present!!!
By the way - there is similar and Automatic a procedure which fulfills from the beginning and up to the end without "" the operator.
Manual procedure has been simply copied with Automatic and added by the Dialog box and handling of its results.
(It will be probably possible in the future both variants (the Car and Manual) to make for saving in one procedure, but it now is not important.)

52

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

Thanks, certainly. But this "extreme" code is not efficient. After all TestCode () it is not caused at all anywhere.

TestCode () it is caused by the unique button on the form SButton: TButton ;
It is really difficult to see or guess, time is One procedure it needs to be launched!
The Test code - is completely efficient!!! - I not on a piece of paper draw, as Njashik with errors!?.)))
( Here the link to the full source code of the Test )
And it is the Form:
[spoiler the Text of a file of the form "Main_Module.dfm":]

object MainForm: TMainForm
Left = 0
Top = 0
Caption = ' MainForm'
ClientHeight = 77
ClientWidth = 281
Color = clAppWorkSpace
Font. Charset = DEFAULT_CHARSET
Font. Color = clWindowText
Font. Height =-11
Font. Name = ' Tahoma'
Font. Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object MLabel: TLabel
Left = 139
Top = 8
Width = 7
Height = 25
Font. Charset = DEFAULT_CHARSET
Font. Color = clAqua
Font. Height =-21
Font. Name = ' Tahoma'
Font. Style = []
ParentFont = False
end
object SButton: TButton
Left = 102
Top = 40
Width = 75
Height = 25
Caption = #1047#1072#1087#1091#1089#1090#1080#1090#1100
TabOrder = 0
OnClick = TestCode
end
end

[/spoiler]

YuRock wrote:

I already 2 times asked to explain the task, instead of to show "test code". Russian to explain that to you the customer (or the teacher or who there) ordered to make. Your "test codes" only withdraw all further and further from understanding of the task not only associates, but also you.

Personally anybody anywhere does not withdraw me, and you too do not escape!.)))
I delivered the Task - if want, solve it with my delivered conditions!
Cannot understand or do not want to waste time - as you please!
Short: the Task, simply to get rid in a loop body of the Dialog box with 3-mja buttons, creating similar buttons on the form, thus not to divide a cycle into parts (procedure). Where already easier to describe without test code?

53

Re: Handling of pushing of three buttons in a parallel flow

wrote:

That hinders to open a file in one place - to hold on it the link???
Even if we also close a file, we can remember on what position of reading has been closed. And at discovery to make offset....
Or you read a file entirely????

it is possible to remember all and it is not important as the file (in Memory, TByte is read... Or FileStream) - I already wrote that the task "to get rid of the Dialog box", without altering all procedure... Read above!

54

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

I after all am technically competent like set the task on the Test example?

To me already so bothered that became interesting smile)). Here it - what is necessary for you?
Yours a test example on a flow (probably there are bugs, but approximately I do not see):
[spoiler]

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
Dialogs, SyncObjs, StdCtrls;
const
WM_THREAD_UPDATE = WM_USER + 1;
WM_THREAD_REQUEST = WM_USER + 2;
WM_THREAD_STOP = WM_USER + 3;
type
TTestThread = class (TThread)
private
FWindowHandle: HWND;
FWaitEvent: TSimpleEvent;
FContinueFunc: TMsgDlgBtn;
protected
procedure Execute; override;
public
constructor Create (AWindowHandle: HWND);
destructor Destroy; override;
procedure ContinueCommand (AContinueFlag: TMsgDlgBtn);
end;
TForm1 = class (TForm)
btnRestart: TButton;
btnContinue: TButton;
btnStop: TButton;
Label1: TLabel;
btnSkip: TButton;
procedure FormCreate (Sender: TObject);
procedure FormDestroy (Sender: TObject);
procedure btnRestartClick (Sender: TObject);
procedure btnContinueClick (Sender: TObject);
procedure btnStopClick (Sender: TObject);
procedure btnSkipClick (Sender: TObject);
private
FThread: TTestThread;
procedure OnThreadUpdate (var Msg: TMessage); message WM_THREAD_UPDATE;
procedure OnThreadRequest (var Msg: TMessage); message WM_THREAD_REQUEST;
procedure OnThreadStop (var Msg: TMessage); message WM_THREAD_STOP;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate (Sender: TObject);
begin
btnRestart. Enabled: = True;
btnContinue. Enabled: = False;
btnSkip. Enabled: = False;
btnStop. Enabled: = False;
end;
procedure TForm1.FormDestroy (Sender: TObject);
begin
FThread. Free;
end;
procedure TForm1.OnThreadUpdate (var Msg: TMessage);
begin
Label1.Caption: = IntToStr (Msg. WParam);
end;
procedure TForm1.OnThreadRequest (var Msg: TMessage);
begin
btnContinue. Enabled: = True;
btnSkip. Enabled: = True;
btnStop. Enabled: = True;
end;
procedure TForm1.OnThreadStop (var Msg: TMessage);
begin
FreeAndNil (FThread);
btnRestart. Enabled: = True;
end;
procedure TForm1.btnRestartClick (Sender: TObject);
begin
btnRestart. Enabled: = False;
FThread. Free;
FThread: = TTestThread. Create (Handle);
end;
procedure TForm1.btnContinueClick (Sender: TObject);
begin
btnContinue. Enabled: = False;
btnSkip. Enabled: = False;
btnStop. Enabled: = False;
FThread. ContinueCommand (mbYes);
end;
procedure TForm1.btnSkipClick (Sender: TObject);
begin
btnContinue. Enabled: = False;
btnSkip. Enabled: = False;
btnStop. Enabled: = False;
FThread. ContinueCommand (mbNo);
end;
procedure TForm1.btnStopClick (Sender: TObject);
begin
btnContinue. Enabled: = False;
btnSkip. Enabled: = False;
btnStop. Enabled: = False;
FThread. ContinueCommand (mbCancel);
end;
constructor TTestThread. Create (AWindowHandle: HWND);
begin
FWindowHandle: = AWindowHandle;
FWaitEvent: = TSimpleEvent. Create;
inherited Create (False);
end;
destructor TTestThread. Destroy;
begin
Terminate;
FWaitEvent. SetEvent;
inherited;
FWaitEvent. Free;
end;
procedure TTestThread. ContinueCommand (AContinueFlag: TMsgDlgBtn);
begin
FContinueFunc: = AContinueFlag;
FWaitEvent. SetEvent;
end;
procedure TTestThread. Execute;
var
i: Integer;
begin
try
repeat
for i: = 0 to 1000 do begin
SendMessage (FWindowHandle, WM_THREAD_UPDATE, i, 0);
FWaitEvent. WaitFor (5);
if Terminated then
Exit;
if i = 500 then begin
SendMessage (FWindowHandle, WM_THREAD_REQUEST, 0, 0);
FWaitEvent. WaitFor (INFINITE);
if Terminated then
Exit;
FWaitEvent. ResetEvent;
case FContinueFunc of
mbYes: Continue;//we Continue the account from 500 (actually from 501) to 1000
mbNo: Break;//It is passed and begun with the beginning
else {mbCancel}//we Interrupt the account
Exit;
end;
end;
end;
until Terminated;
finally
PostMessage (FWindowHandle, WM_THREAD_STOP, 0, 0);
end;
end;
end.

(In nesting - the project. Be played.)
[/spoiler]

55

Re: Handling of pushing of three buttons in a parallel flow

wrote:

FROM the hardware draw out  force, extorting - and it puts the test codes where there are no information particulars.... And he thinks that all should understand its thought - which it and itself cannot implement

You know, there are similar to the king from the Animated cartoon "Bremen musicians" which simply wanted to eat an oil slice for a breakfast, and court of this desire made a problem!
I result to All of you the simple Task ( as simply slice of Oil ), and you demand what that particulars ( it can be necessary  after Fat content of oil, date of its manufacture, working life or the vendor? ) which bring still   both to you and me!  it is asked?
Or you simply sneer over me?

56

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

To me already so bothered that became interesting smile)). Here it - what is necessary for you?
Yours a test example on a flow (probably there are bugs, but approximately I do not see):

at discovery on absence "Project.res", but  it...)
All works for me, according to "Task"... The Class!!! But personally to me still "" it is all it is necessary!
The only thing by sight - many procedures was added, but it is not critical, I do not carp!
Well and the question - basically, whether was mandatory here the Flow?
Without it - what variants still are?

57

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

many procedures were added

Procedures btnContinueClick, btnSkipClick, btnStopClick easily turn to one by means of Tag

Bellic wrote:

Well and the question - basically, whether was mandatory here the Flow?

Any task can be solved in one flow. Sometimes it is an ideal variant. But you store a statement of the problem in a secret, whence I know.

Bellic wrote:

Without it - what variants still are?

Only such which will brake the interface.

58

Re: Handling of pushing of three buttons in a parallel flow

Bellic;
Here so I   back also was not soared years:
[spoiler]

unit Unit1;
interface
uses
Winapi. Windows, Winapi. Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics;
Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls;
type
TForm1 = class (TForm)
bnRun: TButton;
MLabel: TLabel;
bnContinue: TButton;
bnReRun: TButton;
bnCancel: TButton;
procedure bnRunClick (Sender: TObject);
procedure FormCreate (Sender: TObject);
procedure bnContinueClick (Sender: TObject);
procedure bnReRunClick (Sender: TObject);
procedure bnCancelClick (Sender: TObject);
procedure FormCloseQuery (Sender: TObject; var CanClose: Boolean);
private
FProcessing: Boolean;
FProcessIndex: Integer;
{Private declarations}
{
AFlag
0 - Run
1 - Continue
2 - ReRun
3 - Cancel
}
procedure Processing (AFlag: Integer);
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.bnCancelClick (Sender: TObject);
begin
Processing (3);
end;
procedure TForm1.bnContinueClick (Sender: TObject);
begin
Processing (1);
end;
procedure TForm1.bnReRunClick (Sender: TObject);
begin
Processing (2);
end;
procedure TForm1.bnRunClick (Sender: TObject);
begin
Processing (0);
end;
procedure TForm1.FormCloseQuery (Sender: TObject; var CanClose: Boolean);
begin
CanClose: = not FProcessing;
end;
procedure TForm1.FormCreate (Sender: TObject);
begin
bnContinue. Enabled: = False;
bnReRun. Enabled: = False;
bnCancel. Enabled: = False;
end;
procedure TForm1.Processing (AFlag: Integer);
var
i: Integer;
begin
{
AFlag
0 - Run
1 - Continue
2 - ReRun
3 - Cancel
}
case AFlag of
0,2:
begin
FProcessIndex: = 0;
bnRun. Enabled: = False;
bnContinue. Enabled: = False;
bnReRun. Enabled: = False;
bnCancel. Enabled: = False;
end;
1:
begin
bnContinue. Enabled: = False;
bnReRun. Enabled: = False;
bnCancel. Enabled: = False;
end;
3:
begin
bnRun. Enabled: = True;
bnContinue. Enabled: = False;
bnReRun. Enabled: = False;
bnCancel. Enabled: = False;
Exit;
end;
end;
FProcessing: = True;
try
for i: = FProcessIndex to 1000 do
begin
FProcessIndex: = i + 1;
MLabel. Caption: = IntToStr (i);
//These two operators - it is pure for account deceleration!
Application. ProcessMessages;
Sleep (5);
if i = 500 then
begin
bnContinue. Enabled: = True;
bnReRun. Enabled: = True;
bnCancel. Enabled: = True;
flashwindow (Handle, true);
Exit;
end;
end;
finally
FProcessing: = False;
end;
if i = 1000 then
begin
bnRun. Enabled: = True;
bnContinue. Enabled: = False;
bnReRun. Enabled: = False;
bnCancel. Enabled: = False;
end;
end;
end.

[/spoiler] until users would not began to complain.
And now something as at

59

Re: Handling of pushing of three buttons in a parallel flow

Bellic, on the form you throw  with three (or how many it is necessary buttons), you do it not by active, in  you declare a variable, for example FRes: integer, and instead of Rez: = MessageDlg you interpose the code

Panel. Enable: = True;
FRes: = 0;
while FRes = 0 do Application. ProcessMessages;
Panel. Enable: = False;

Thus in output agents of buttons FRes you appropriate the necessary value.

60

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

Procedures btnContinueClick, btnSkipClick, btnStopClick easily turn to one by means of Tag

It is clear:
[spoiler]

procedure TForm1.ContinueSkipStopClick (Sender: TObject);
begin
btnContinue. Enabled: = False;
btnSkip. Enabled: = False;
btnStop. Enabled: = False;
case (Sender as TComponent).Tag of
1: FThread. ContinueCommand (mbYes);
2: FThread. ContinueCommand (mbNo);
3: FThread. ContinueCommand (mbCancel);
end;
end;

[/spoiler]

61

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

Can shoot me, but It perfectly works!.)))

Try, while it works, to push, say, a dagger in right upper to a corner.

62

Re: Handling of pushing of three buttons in a parallel flow

Freedoom , is very interesting it turned out! A class!
(There is no explicit wait loop, . and TAG is used according to the advice of guys!)
the project Archive is applied ...)

63

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

Freedoom , is very interesting it turned out! A class!
(There is no explicit wait loop, . and TAG is used according to the advice of guys!)

It is a pity only to the electric power for processor loading in 100 % and brakes of the computer because of it.

64

Re: Handling of pushing of three buttons in a parallel flow

softwarer wrote:

Try, while it works, to push, say, a dagger in right upper to a corner.

happened Nothing, and at least I will get rid of the Dagger generally!
Well it is impossible to close a window in the middle of an open cycle!
But it already trifles and another story altogether...

65

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

Well it is impossible to close a window in the middle of an open cycle!

Even if the user decided not to wait for the termination of your cycle?

66

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

It is a pity only to the electric power for processor loading in 100 % and brakes of the computer because of it.

Brakes it is not watched, and loading races on CPU - c 25 to 50 %. It is a lot of?
It is possible if it wants - as the timer a raven on branches to count!.)))

67

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

Even if the user decided not to wait for the termination of your cycle?

the Output from procedure will be possible only by the button the Output, with correct actions.
And calculation (in the Test variant is an account from 0 to 500 and from 501 to 1000 etc.) in the Real cycle is fulfilled quickly enough so the user and has not time visit a mouse on the Dagger (If he still manages to find it on the form)!.)

68

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

and loading races on CPU - c 25 to 50 %. It is a lot of?

4 processors (kernel) mean at you. On one similar "program" already "worked", and this was launched on other.
And if there was one kernel - loading would be 100.
But do not despair, and on the multinuclear computers, all programs, which GUI-stream worked on that processor which you sent in whom, will brake.
It is a lot of it or not much - to users of your program to solve.

69

Re: Handling of pushing of three buttons in a parallel flow

YuRock wrote:

4 processors (kernel) Mean at you. On one similar "program" already "worked", and this was launched on other.
And if there was one kernel - loading would be 100.
But do not despair, and on the multinuclear computers, all programs, which GUI-stream worked on that processor which you sent in whom, will brake.
It is a lot of it or not much - to users of your program to solve.

Yes, truly, at me 4 kernels!.)
With One kernel - whether it Pentium-1 that? So my already such for a long time on a dump!.))
And the program real - for  a circle of users is written - for itself, well the maximum still can for 2 other friends!
Well and there will be brakes - it is possible to use your Stream variant also! - it judging by the indicator - at all does not load the processor!.)
I hope problems, call from Stream procedure to other functions and procedures, should not be?!

70

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

With One kernel - whether it Pentium-1 that?

In your case if you have 2 kernels, both would become occupied (since 1 already someone occupied).
Not, if it is not a pity the electric power and nerves, to spit on  grateful users - I not against.

Bellic wrote:

Stream procedure to other functions and procedures, should not be

To functions and procedures, as well as storage, do not belong to any flow. They can be used from any.
Only the code flow will be though is identical if to cause one function in different flows, but them will be a little, and here storage - one on all.

71

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

loading races on CPU - c 25 to 50 %. It is a lot of?

It is the full Item At correctly written program in rest there should be zero consumption .

72

Re: Handling of pushing of three buttons in a parallel flow

YuRock , By the way - added Sleep (1); in THIS CODE , and the congestion percent generally fell, check up:

while FRes = 0 do
begin
>>> Sleep (1); <<<
Application. ProcessMessages;
end;

- Without Sleep (1) - 25-27 % in expectation of pushing of keys;
- With Sleep (1) - loading pending practically did not increase (1-5 %)!

73

Re: Handling of pushing of three buttons in a parallel flow

Bellic;
And now try to close the program a dagger.

74

Re: Handling of pushing of three buttons in a parallel flow

Bellic wrote:

YuRock , By the way - added Sleep (1); in THIS CODE , and the congestion percent generally fell, check up:

while FRes = 0 do
begin
>>> Sleep (1); <<<
Application. ProcessMessages;
end;

- Without Sleep (1) - 25-27 % in expectation of pushing of keys;
- With Sleep (1) - loading pending practically did not increase (1-5 %)!

I do not want to try smile))
It is a gloom. That with  that without.

75

Re: Handling of pushing of three buttons in a parallel flow

rgreat wrote:

Bellic, And now try to close the program a dagger.

rgreat , you at all do not read similar Subject!?
HERE I already answered this question!
Well is not present at me on the Real form of the DAGGER!!! On the test form it certainly is available, but I will not push there!
I created the form at once without daggers, tags of swerving and minimization! That then questions would not be!.)