#### Topic: Algorithm of operation of the timer

All greetings and happy New Year.
Question:
There is a record in a file in a type
timer1=ON/13:22/13:23/1/1/1/0/0/0/1
timer2=ON/13:03/13:04/1/1/1/1/1/1/1
timer3=ON/13:05/13:06/1/0/1/0/1/0/1
timer4=ON/13:07/13:08/1/0/0/0/1/0/0
timer5=ON/13:09/13:10/1/1/0/0/1/0/0
There is a function which checks system time, compares it to a file and includes/disconnects the relay. If to deliver single line handling all APPRX. And if to process all five lines it turns out that works only the fifth timer. I.e. if time corresponds timer1 the relay turnes on. Further the second line and if time does not correspond the relay is ungeared is checked.
The task - it is necessary to implement  function which switches on and off the relay depending on adjustments. (Type the multitask timer).

``````if Copy (f. Strings [strnum], posN (' = ', f. Strings [strnum], 1) +1, PosN (' / ', f. Strings [strnum], 1)-posN (' = ', f. Strings [strnum], 1)-1) = ' ON ' then
if (Copy (f. Strings [strnum], PosN (' / ', f. Strings [strnum], 2+day) +1,1) = ' 1 ') and
(StrToTime (Copy (f. Strings [strnum], posN (' / ', f. Strings [strnum], 1) +1, PosN (' / ', f. Strings [strnum], 2)-posN (' / ', f. Strings [strnum], 1)-1)) &lt;=Time) and
(StrToTime (Copy (f. Strings [strnum], posN (' / ', f. Strings [strnum], 2) +1, PosN (' / ', f. Strings [strnum], 3)-posN (' / ', f. Strings [strnum], 2)-1))&gt; Time) then
begin
result: = true;
end else
begin
result: = false;
end;``````

That it was more clear:
The first switching-on 1:00 - 2:00, the second 3:00 - 4:00
Now 1:30
The first line is checked - time corresponds a condition, the relay turnes on
The second line is checked - time does not correspond, the relay is ungeared (and it is necessary that worked till 2:00)
If it is not difficult, prompt, and that all head broke already

#### Re: Algorithm of operation of the timer

All thanks, already understood))

#### Re: Algorithm of operation of the timer

Dmitry_A123;

wrote:

If it is not difficult, prompt, and that all head broke already

Horror to throw out , normally to paint a condition, and more so not to write never. Otherwise you will be and to break further a head at any change or addition.

#### Re: Algorithm of operation of the timer

makhaon wrote:

Dmitry_A123;
it is passed...
Horror to throw out , normally to paint a condition, and more so not to write never. Otherwise you will be and to break further a head at any change or addition.

So you help business, instead of a word - write the not , on a personal example show, how it is possible and it is necessary to do.

#### Re: Algorithm of operation of the timer

So I do not know conditions   it is necessary. What here to do? ON/13:22/13:23/1/1/1/0/0/0/1 when what to include when to ungear? There can be OFF? The code I do not want to look, therefore as new year, laziness to think and generally brain demolition

wrote:

I.e. if time corresponds timer1 the relay turnes on

What relay turnes on? What is ungeared? 1 it is included, 0 it is disconnected? Or still as? Why it is specified two times? What will happen from 13:22 till?
To begin with it is possible SplitStr on ' / ' in arrays of structures.   .

#### Re: Algorithm of operation of the timer

I do not know, how much titles of fields I correspond , outlined, did not launch, it is necessary to drive:

``````procedure TForm2.Button1Click (Sender: TObject);
type
TRalayRec = record
OnFlag: boolean;
StartTime: TDateTime;
StopTime: TDateTime;
RalaysOn: array [0. 6] of boolean;
end;
var
i, j: integer;
SL: TStringList;
Arr: TStringDynArray;
Relays: array of TRalayRec;
begin
SL: = TStringList. Create;
try
SL.LoadFromFile (' timers.txt ');
SetLength (Relays, SL.Count);
for i: = 0 to SL.Count - 1 do
begin
Arr: = SplitString (SL [i], ' / ');
with Relays [i] do
begin
OnFlag: = Arr [0] = ' ON ';
TryStrToTime (Arr [1], StartTime);
TryStrToTime (Arr [2], StopTime);
for j: = 0 to 6 do
RalaysOn [j]: = Arr [j + 3];
end;
end;
finally
FreeAndNil (SL);
end;
end;``````

#### Re: Algorithm of operation of the timer

Distracted, )

``RalaysOn [j]: = Arr [j + 3] = ' 1 ';``

#### Re: Algorithm of operation of the timer

It is possible to overtake simply in an array of variants if records it is not pleasant.