Home > Back-end >  Delphi senior legacy applications questionable warrior advice please
Delphi senior legacy applications questionable warrior advice please

Time:09-24

/======================the Timer======================================
Procedure TForm1. Timer1Timer (Sender: TObject);
Var
Afile: TFileStream;
STR, da, StrToWrite: string;

The begin
//=============write TXT=====================
If Txt_Flag=true then
The begin
StrToWrite:=';
StrToWrite:=StrToWrite + output_X. Text + ', '+ output_Ang. Text +', '+ output_l. The Text;
STR:=TimeToStr (Time);
Da:=DateToStr (Date);
StrToWrite:=da + ', '+ STR +', '+ StrToWrite + # 13 # 10;
If not FileExists (SaveDialog1 FileName + '. TXT ') then//if the file does not exist, create to write
The begin
Try
Afile:=TFileStream. Create (SaveDialog1 FileName + '. TXT ', fmCreate);
Afile. WriteBuffer (PChar (StrToWrite) ^, Length (StrToWrite));
The finally
Afile. Free;
end;
End
The else begin//
Try
Afile:=TFileStream. Create (SaveDialog1 FileName + '. TXT ', fmOpenWrite);
Afile. Seek (0, soEnd);
Afile. WriteBuffer (PChar (StrToWrite) ^, Length (StrToWrite));
The finally
Afile. Free;
end;
end;
end;

end;
//==================save==============================
Procedure TForm1. SaveClick (Sender: TObject);
The begin
If SaveDialog1. Execute then//SaveDialog1 is a component TSaveDialog
The begin
Txt_Flag:=True;
end;
end;
Programming problems in the experiment, the main of this part of the program to see don't understand, hope warrior can explain in detail,
Write regularly, mainly collected data after excitation timer can be specific as to what this code?

CodePudding user response:

 
//timing save text file
Procedure TForm1. Timer1Timer (Sender: TObject);
Var
Afile: TFileStream;//file stream
STR, da, StrToWrite: string;//string type
The begin
//write TXT
If Txt_Flag=true then//file name set complete
The begin
StrToWrite:=';
StrToWrite:=StrToWrite + output_X. Text + ', '+ output_Ang. Text +', '+ output_l. The Text; 3//Edit or Combobox
STR:=TimeToStr (Time);//Time Time values, convert character type
Da:=DateToStr (Date);//Date Date values, convert character type
StrToWrite:=da + ', '+ STR +', '+ StrToWrite + # 13 # 10;//generate a line of string, including time, date + newline
If not FileExists (SaveDialog1 FileName + '. TXT ') then//if the file does not exist, create to write
The begin
Try
Afile:=TFileStream. Create (SaveDialog1 FileName + '. TXT ', fmCreate);//use the document flow create
Afile. WriteBuffer (PChar (StrToWrite) ^, Length (StrToWrite));//write to the file a line
The finally
Afile. Free;//release document flow
end;
End
The else begin//file name is not set
Try
Afile:=TFileStream. Create (SaveDialog1 FileName + '. TXT ', fmOpenWrite);//open SaveDialog1 specified filename, and through the flow to create file
Afile. Seek (0, soEnd);//the length of the Settings file
Afile. WriteBuffer (PChar (StrToWrite) ^, Length (StrToWrite));//write file
The finally
Afile. Free;//release document flow
end;
end;
end;
end;

//set the file name
Procedure TForm1. SaveClick (Sender: TObject);
The begin
If SaveDialog1. Execute then//SaveDialog1 is a component TSaveDialog
The begin
Txt_Flag:=True;//the name set Txt_Flag is true
end;
end;


That clear? Should understand,

CodePudding user response:

Can use the line

If later to join our company, you also understand other people's code, it need not work

Unless it's leadership call you find bugs, or a senior specially arranged, otherwise no need to worry so much

Personal opinion only

Hilti, if willing to study, that natural is better

CodePudding user response:

On total code is easier than writing code, I came to a lot of effort,

CodePudding user response:

On the first floor, where are you, are you,
Me a bit more what,
Txt_Flag:=True; Marks will be set to true, the effect of open timer, don't know how long it will take your timer performs a ah, but I think its execution time, after open timer effect or turn off the timer open sign Txt_Flag:=false, or the stream (the output of the three east) to empty, otherwise it is not cycle to save,

CodePudding user response:

Is to implement a timed loop to save the data

CodePudding user response:

reference 4 floor xiaoyongxiao response:
on the first floor, where are you, are you,
Me a bit more what,
Txt_Flag:=True; Marks will be set to true, the effect of open timer, don't know how long it will take your timer performs a ah, but I think its execution time, after open timer effect or turn off the timer open sign Txt_Flag:=false, or the stream (the output of the three east) to empty, otherwise it is not circulating preservation,



  • Related