Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mo 02.04.07 21:57 
hi, ich bin so ein ziemlicher delphi-noob, kann eigentlich nur copy & paste mit delphi (lol), und wollte mir jetz so ein Programm machen, wo ich ganz simpel in 5 Zeilen TV-Daten eintragen kann..kann mal einer mein code vielleicht korrigieren oder mir sagen was ich ändern muss?

ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
unit Plan;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Menus, IniFiles, jpeg, ExtCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    xxx: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    DateTimePicker3: TDateTimePicker;
    DateTimePicker4: TDateTimePicker;
    DateTimePicker5: TDateTimePicker;
    Edit1: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    Save1: TMenuItem;
    Exit1: TMenuItem;
    Load1: TMenuItem;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    MainImage: TImage;
    procedure Save1Click(Sender: TObject);
    procedure Load1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Save1Click(Sender: TObject);
var
  Ini: TIniFile;
begin
 try
    Ini:=TIniFile.Create('C:\Users\Hendrik\plan.ini');
    Ini.WriteString('xxx','Schlüssel1','Wert');
    Ini.WriteInteger('xxx','Schlüssel2',10);
    Ini.WriteBool('xxx','Schlüssel3',True);
  finally
    Ini.Free;
end;

end;

procedure TForm1.Load1Click(Sender: TObject);
var
  Ini: TIniFile;
begin
  try
    Ini:=TIniFile.Create('C:\Users\Hendrik\plan.ini');
    Ini.ReadString('xxx','Schlüssel1','Wert');
    Ini.ReadInteger('xxx','Schlüssel2',10);
    Ini.ReadBool('xxx','Schlüssel3',True);
  finally
    Ini.Free;
  end;
end;

end.
Einloggen, um Attachments anzusehen!
Magic J
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

WinXP Prof., Vista
Delphi6, Delphi 2009, Java(Eclipse), C++, Basic
BeitragVerfasst: Mo 02.04.07 22:53 
Hi Hendi,

wenn du schon etwas in eine INI-Datei speicherst sollte es doch bestimmt das sein, was n den Edit´s steht oder?
Allein dadurch, dass du die "Section" genaus nennst, wie die Edit("xxx") kommst du da nicht weiter!

Ich denke mal, owohl du´s ja nicht beschreibst, dass du sowas meintst:
Zum Speichern:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
try  
    Ini:=TIniFile.Create('C:\Users\Hendrik\plan.ini');  
    Ini.WriteString('Bereich1','Schlüssel1',xxx.text);  
    Ini.WriteString('Bereich1','Schlüssel2',Edit2.text);  
    Ini.WriteString('Bereich1','Schlüssel3',Edit3.text);  
    Ini.WriteString('Bereich1','Schlüssel4',Edit4.text); 
    //...usw.
  finally  
    Ini.Free;  
end;


und zum öffen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  try  
    Ini:=TIniFile.Create('C:\Users\Hendrik\plan.ini');  
    xxx.text:=Ini.ReadString('Bereich1','Schlüssel1','Leer');  
    Edit2.text:=Ini.ReadString('Bereich1','Schlüssel2','Leer'); 
    Edit3.text:=Ini.ReadString('Bereich1','Schlüssel3','Leer'); 
    Edit4.text:=Ini.ReadString('Bereich1','Schlüssel4','Leer'); 
    //...usw.
  finally  
    Ini.Free;  
end;


Gruß Jonas
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Di 03.04.07 09:21 
yay, danke es funktioniert jetzt und ich habs auch verstanden!! :wink:
kann ich denn jetz noch irgendwie einbauen das er die ini sofort mit dem programmstart lädt?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 03.04.07 11:04 
Dppelklick aufs Formular und dann dort in FormCreate (wo du bei nem Doppelklick direkt aufs Formular automatisch landest) die Laden-Methode aufrufen:
ausblenden Delphi-Quelltext
1:
  Load1Click(Load1);					
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Di 03.04.07 11:56 
so? und dann?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormCreate(Sender: TObject);
begin
Load1Click(Load1);

end;

end.
Magic J
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

WinXP Prof., Vista
Delphi6, Delphi 2009, Java(Eclipse), C++, Basic
BeitragVerfasst: Di 03.04.07 12:05 
Hi

Ja genau!
so müsste des doch gehen!

du kannst dir natürlich auch alles aus der "Load1Click()"-Procedure rüberkopieren...

Aber ich wüsste nicht, was hier nicht funktionieren sollte
(oder heißt deine Procedure zum Öffnen inzwischen nicht mehr "Load1Click" und dein Button nicht mehr "Load1"???)

Gruß Jonas
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Di 03.04.07 13:04 
ah stimmt es geht jetz auch, es ging nur nicht weil ich jetz auf meinem XP war und da die Laufwerksbuchstaben anders sind :lol:
ich habs einfach so gemacht jetz gehts. Danke für die Hilfe!!
ausblenden Delphi-Quelltext
1:
2:
    Ini:=TIniFile.Create('C:\Users\Hendrik\plan.ini'); //Vista-Pfad
    Ini:=TIniFile.Create('N:\Users\Hendrik\plan.ini'); //   XP-Pfad
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 03.04.07 14:06 
Du solltest für derlei Daten und Einstellungen das Anwendungsdatenverzeichnis nehmen. Das kannst du über die entsprechende Umgebungsvariable APPDATA auslesen. Dann hast du einen Pfad wie %APPDATA%\DeineAnwendung.
Und um dazu den richtigen Pfad zu bekommen hilft dir das hier:
www.delphi-library.d...aufloesen_20516.html