Autor Beitrag
TimKellner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Fr 05.01.07 15:20 
Hallo liebe Communty,

ich habe eine in einer Textdatei geschriebene Konfiguration. Ich möchte nun die Werte aus diese Konfiguration auslesen und ua. in Textfelder einbauen. Die namen stehen ua mit $NAME = WERT oder mit $NAME: WERT1 => WERT2

könnt ihr mir vielleicht helfen?

MFG
Tim

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
*****************************************************
**************** Konfigurationsdatei ****************
*****************************************************
//=>  Konfiguration vom 05.01.2007  <=\\
$ProjectPath = C:\Programme\Programmname
$Website = Standartwebseite
$OutPutDir = C:\Inetpub\wwwroot
$vpath: / => C:\Inetpub\wwwroot
$vpath: /BHC_PRD => C:\Programme\Projekte\BHC_PRD
$vpath: /Muster => C:\Programme\Projekte\Muster
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 05.01.07 15:27 
Schau dir mal die String-Routinen Pos, Copy und Delete an. ;)
Zum Auslesen der Datei kannst du eine Stringlist verwenden.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Fr 05.01.07 15:30 
Ansatz:
Datei in eine String-Liste einlesen und jede Zeile (String) einzelnd nach Merkmalen wie ": ", " = " und " => " absuchen und entsprechend interpretieren.
Dazu brauchst du z.B. String-Befehle wie pos.
Siehe in der Online-Hilfe nach TStringList und pos und dergleichen.
Damit solltest du schon ein gnazes Stückchen vorankommen.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Fr 05.01.07 15:39 
Ok,

auf die Idee bin ich gar nicht gekommen.

Ich muss doch die Datei einfach mit config.LoadFromFile(OpenDialog.FileName) einlesen oder? Denn ich erhalte sofort eine Fehlermeldung.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TFrame_Aendern.Button_KonfigurationClick(Sender: TObject);
var config:TStringList;
begin
if OpenDialog.Execute THEN
begin
  config.LoadFromFile(OpenDialog.FileName);
end;
Path_Konfiguration.Text := OpenDialog.FileName;
end;
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 05.01.07 15:43 
Du musst vorher erst eine Instanz von TStringlist erstellen. ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TFrame_Aendern.Button_KonfigurationClick(Sender: TObject);
var config:TStringList;
begin
if OpenDialog.Execute THEN
begin
  config := TStringlist.Create;
  config.LoadFromFile(OpenDialog.FileName);
end;
Path_Konfiguration.Text := OpenDialog.FileName;
end;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Fr 05.01.07 15:48 
Und nicht vergessen, sie wieder freizugeben.
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: Fr 05.01.07 15:52 
Richtig. Manchmal glaube ich für manche wäre GC in Delphi doch ganz gut... :lol:
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 05.01.07 15:58 
user profile iconjaenicke hat folgendes geschrieben:
Richtig. Manchmal glaube ich für manche wäre GC in Delphi doch ganz gut... :lol:

Mache ich ja sonst :roll: Es ging ja jetzt nur ums Erstellen und Auslesen ...
@TimmKellner: Freigeben tust du deine Stringlist mit FreeAndNil(deineStringlist) im OnDestroy.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Fr 05.01.07 16:01 
Nein, die muss am Ende der Methode freigegeben werde, weil sie lokal ist.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 05.01.07 16:02 
user profile iconjakobwenzel hat folgendes geschrieben:
Nein, die muss am Ende der Methode freigegeben werde, weil sie lokal ist.

Achso, sie ist lokal, na denn haste Recht. :zwinker:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Fr 05.01.07 16:13 
@Marco

In welchem OnDestroy denn überhaupt?

Ich benutze immer TStringlist.Free, wo z.B. auch geprüft wird, ob das bereits nil ist.
Wenn nicht, wird destroy von free aufgerufen und plättet eh alles.
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: Fr 05.01.07 16:16 
Aber es setzt nicht unbedingt den Zeiger auf die StringList auf nil. Wenn man später evtl. auf "= nil" testen will, dann sollte man immer FreeAndNil verwenden (ruft Free auf und setzt den Zeiger auf nil). Egal ob dann beim Freigeben ein Fehler auftritt: Der Zeiger ist nil...

Wenn es wie hier lokale Variablen sind, die später nicht wiederverwendet werden, dann ist das natürlich egal.
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Fr 05.01.07 16:31 
user profile iconjaenicke hat folgendes geschrieben:
Aber es setzt nicht unbedingt den Zeiger auf die StringList auf nil. Wenn man später evtl. auf "= nil" testen will, dann sollte man immer FreeAndNil verwenden (ruft Free auf und setzt den Zeiger auf nil).

Das ist wahr. Dennoch würde mich interessieren, welches OnDestroy er meinte.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 05.01.07 16:34 
Ich meinte OnDestroy der MainForm. Das gilt aber nur, wenn die Stringlist global wäre.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot