// Retourne un string sous la forme "yyyymmddhhmmss" : function AllowedStrDateTime(const sDate, sTime: string): string; var AllowedStrDate, AllowedStrTime: string; begin AllowedStrDate := Copy(sDate, 7, 4) + Copy(sDate, 4, 2) + Copy(sDate, 1, 2); AllowedStrTime := Copy(sTime, 1, 2) + Copy(sTime, 4, 2) + Copy(sTime, 7, 2); Result := AllowedStrDate + AllowedStrTime; end; // et le timer déclenche ce code : var NomFich: string; Ext: string; AllowedDateTime: string; begin NomFich := 'E:\Journal alarmes CMR\alarmes CMR.doc '; Ext := ExtractFileExt(NomFich); Delete(NomFich, Pos(Ext, NomFich), Length(Ext)); AllowedDateTime := AllowedStrDateTime(Edit1.Text, Edit2.Text); NomFich := Format('%s [%s]%s', [NomFich, LegalDateTime, Ext]); Memo.Lines.SaveToFile(NomFich); end;
var Y, M, D,H,N,S,Z : word; Path,FileName : string; begin DecodeDate( Now, Y, M , D); DecodeTime( Now, H, N, S, Z); Path := format('E:\Journaux Alarmes CMR\%.4d\%.2d\%.2d\',[Y,M,D]); if Not directoryExists(Path) then forceDirectories(Path); FileName := format('%s\journal-%.2d-%.2d-%2d-%.4d.txt',[Path,H,N,S,Z]); (*Objet*).saveToFile(FileName); end;
function getTimeCodeStr: string; begin DateTimeToString(result, 'yyyy-mm-dd-hhnnss', now); end; function TForm1.SyncTimer: word; { créée dans le public de TForm1 } var H,N,S,Z: word; begin decodeTime(now, H, N, S, Z); { synchro du timer, dans 1 heure - le temps (M,S) déjà écoulé } Timer1.Interval := 3600000 - (N*60000 + S*1000); { si on démarre le programme à 12h45 et 34secondes, 3600000 - (2700000 + 34000) = 866000 = test dans 14.43 minutes } result := H; end; procedure TForm1.Form1Create(Sender: TObject); begin SyncTimer; end; procedure TForm1.Timer1Timer(Sender: TObject); begin if SyncTimer in [4,8,12,16,20,0] then { sauve toute les 4 heures } Journalisation.SaveToFile('E:\Journaux\Journal-'+getTimeCode+'.txt'); end; procedure TForm1.ButtonSaveClick(Sender: TObject); begin Journalisation.SaveToFile('E:\Journaux\Journal-manualsave-'+getTimeCode+'.txt'); end;