Autor Beitrag
teamrocket0
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Mo 04.09.06 16:26 
Ich will beim klicken auf einen "MonthCalendar" eine Datei mit dem Datum des angeklicketen Tages erstellen, wenn diese Datei in einem bestimtem Verzeichnis och nicht vorhanden ist.
Wenn diese Datei mit dem Namen des angeklickten Tages bereits existiert, soll er das einfach in ein Memo laden.


ZeitGeist87 schrieb in der Shoutbox:
if not fileexists(datei) then rewrite(datei)...

Darauf mein Quelltext:
if not fileexists(DateToStr(MonthCalendar1.Date) + '.txt')
then rewrite(DateToStr(MonthCalendar1.Date) + '.txt')

folgender Fehler trit auf:
[Fehler] Unit1.pas(119): Inkompatible Typen

kann mir einer sagen woran das liegt?
tgr
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

WIN 7, XP
D2010 Ent
BeitragVerfasst: Mo 04.09.06 17:09 
rewrite erwartet als Parameter eine Variable vom Typ (XXX)File und keinen string.
vgl: AssignFile

TGR
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Mo 04.09.06 18:18 
Hallo..vllt hilft das ja :lol:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.MonthCalendar1Click(Sender: TObject);
Var f : TextFile;
    datei : String;
    DateiVerzeichniss: String;
    Dateiname: String;
begin
DateiName:=FormatDateTime('ddmmyyyy',MonthCalendar1.Date);
Dateiverzeichniss:=ExtractFilePath(ParamStr(0));//Aktuelles Ausgabeverzeichnis
Datei:= Dateiverzeichniss+'\'+DateiName+'.txt';
AssignFile(f,Datei);
 if FileExists(Datei) then
 begin
  Reset(f);
  Memo1.Lines.LoadFromFile(Datei);
  CloseFile(f)
 end
 else
 begin
   If MessageDlg('Datei nicht vorhanden'+#13+'Soll sie erstellt werden ?',mtconfirmation,[mbno,mbyes,mbcancel],0)= mryes then
    begin
     Rewrite(f); //Datei erzeugen und öffnen
     CloseFile(f)
     end
     else showMessage('Datei wurde nicht erzeugt');
 end;
end;

Gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
Masterhawk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 92

Win 2000,Win XP
D6 Pers
BeitragVerfasst: Mo 04.09.06 18:26 
Code ungetestet

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var f1:TextFile;
    Datei:String;

if not FileExists(Datei) then
 begin
  AssignFile(f1,Datei);
  Rewrite(f1);
  Writeln(f1,...);//Was du halt reischreiben möchtest
  CloseFile(f1); //Nicht vergessen ;) beliebter Fehler
 end;


ich hoffe ich konnte helfen....

MfG Masterhawk
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mo 04.09.06 19:03 
Hi
Ich denke, ihr solltet darauf hinweisen das DatetoStr(Date) 'dd.mm.yyyy' ergibt und damit das +'.Txt' völlig überflüssig wird....
Richtig ist die Function FormatDateTime('ddmmyyyy',date)
Da sind keine irreführenden Punkte in dem eigentlichen Dateinamen. Wird andersrum formatiert
FormatdateTime('yyyymmdd',Date) kann man das Datum auch sortieren.
Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Mo 04.09.06 19:09 
Hab ich ihm doch so geposte oder net ?
lies mal meinen post.
gruß

_________________
[b]Ich weiß nicht immer, wovon ich rede. Aber ich weiß, dass ich recht habe.[b]
teamrocket0 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 05.09.06 10:12 
Uhhhh :shock: , der Hammer. Der Post von "der Berliner" ist der absolute sledge hammer.

Vielen Dank, das hat mein Problem auf eindrucksvolle Weise gelöst!
:roll:
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 05.09.06 10:19 
hey in der shoutbox hab ich ja auch nich massig platz teamrocket0 =)
drum lerne..immer gleich in thread aufmachen okay*g*

Lg
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
teamrocket0 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 05.09.06 11:14 
hmm. OK ich habe das soweit in meinem Program untergebracht, aber ich würde für die ganzen Dateien die da angelegt werden gerne noch einen Unterordner benutzen.

Zeile 8:
Dateiverzeichniss:=ExtractFilePath(ParamStr(0));

wie kann ich da den Pfad bestimmen?
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Di 05.09.06 11:27 
... + 'Unterverzeichnis'; ?! :roll:

Vorher solltest du aber prüfen, ob das Unterverzeichnis existiert und gegebenenfalls anlegen. ;)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
teamrocket0 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 177
Erhaltene Danke: 1

Win ME, Win XP, Win 7, Win 10
Delphi 7, 10.2 Tokyo
BeitragVerfasst: Di 05.09.06 11:31 
Alles klar. Das funktioniert hervorragen. Danke

Ergebniss insgesamt für Zeile 8:
Dateiverzeichniss:=ExtractFilePath(ParamStr(0)) + '\Unterordner';