Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Inhalt von Variable per savetofile in txt datei speichern (https://www.delphipraxis.net/66582-inhalt-von-variable-per-savetofile-txt-datei-speichern.html)

ErdNussLocke 31. Mär 2006 19:15


Inhalt von Variable per savetofile in txt datei speichern
 
Hi,
ich weiß, dass man mit dem Befehl savetofile etwas in eine .txt-Datei speichern kann. Z.B. den Inhalt einer Memo Komponente:
Code:
Memo1.lines.savetofile('test.txt');
Kann man das gleiche auch mit einer normalen Variable machen? Also das einfach der Inhalt einer Variable in eine Datei gespeichert wird? Hab es so versucht
Code:
var x: string;
...
x.savetofile('test.txt');
War irgendwie nahe liegend :) Aber funktioniert leider nicht.
Danke schonmal
MfG
ErdNussLocke

toms 31. Mär 2006 19:18

Re: Inhalt von Variable per savetofile in txt datei speicher
 
Hallo!

Nimm doch ein TIniFile dafür (geeignet, um Einstellungen zu speichern)

ErdNussLocke 31. Mär 2006 19:19

Re: Inhalt von Variable per savetofile in txt datei speicher
 
jaaa... aber ich wollte wissen ob das net auch geht :)
Weil es war um einiges einfacher als eine ini datei zu erzeugen

_Sebastian_ 31. Mär 2006 19:24

Re: Inhalt von Variable per savetofile in txt datei speicher
 
nein geht nicht.

Das geht nur bei klassen die auch die SaveToFile methode implementiert haben.
Du kannst dir aber eine Stringklasse schreiben und da dann das Savetofile einbauen.

Ansonsten probier mal ob dir die TStringlist weiterhilft.

toms 31. Mär 2006 19:26

Re: Inhalt von Variable per savetofile in txt datei speicher
 
Du koenntest auch eine TStringList nehmen.

Delphi-Quellcode:
procedure SaveVariableToFile(const FileName: TFileName; MyVariable: Variant);
var
  sl: TStringList;
begin
  sl := TStringList.Create;
 try
  sl.Text := MyVariable;
  sl.SaveToFile(FileName);
 finally
  sl.Free;
 end;
end;
Bsp:

Delphi-Quellcode:
var
 a: Integer;
 b: string;
begin
 a := 3;
 SaveVariableToFile('c:\test1.txt',a);
 b := 'test';
 SaveVariableToFile('c:\test2.txt',b);
end;

ErdNussLocke 31. Mär 2006 19:45

Re: Inhalt von Variable per savetofile in txt datei speicher
 
hey danke!
Das is schön^^
thx


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:03 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz