Hello there,
i've been using C for a while until i decided to use Delphi.
now i am working on a programme in delphi that takes altitude, speed, weight ... etc. and the output it a plane.
i created a menu, and under File i have Open, Save ... etc.
what i am trying to do is to be able to save all of this information to a text file (using File>Save) and reopen it when needed (using File>Open).
i know how to do it using a button, but i want more option like file location and file name.
thanks in advance.
i've been using C for a while until i decided to use Delphi.
now i am working on a programme in delphi that takes altitude, speed, weight ... etc. and the output it a plane.
i created a menu, and under File i have Open, Save ... etc.
what i am trying to do is to be able to save all of this information to a text file (using File>Save) and reopen it when needed (using File>Open).
i know how to do it using a button, but i want more option like file location and file name.
thanks in advance.
|
|
BobbaFet (Programmer) |
18 Nov 05 5:45
|
for what you are trying to do:
This will require you to add IniFiles to your uses clause.
You can find the uses clause at the top of unit document
right below interface.
How to use the ini file:
Loading data from an ini file:
CODE
procedure TForm1.Button1Click(Sender: TObject);
var myIni: TIniFile;
var Var1, Var2, Var3: string;
begin
myIni := TIniFile.Create('C:\somedir\myini.ini');
var1 := myIni.ReadString('SectionA','SomeIdent1','DefaultString');
var2 := myIni.ReadString('SectionA','SomeIdent2','DefaultString');
var3 := myIni.ReadString('SectionA','SomeIdent3','DefaultString');
myIni.Free;
end;
var myIni: TIniFile;
var Var1, Var2, Var3: string;
begin
myIni := TIniFile.Create('C:\somedir\myini.ini');
var1 := myIni.ReadString('SectionA','SomeIdent1','DefaultString');
var2 := myIni.ReadString('SectionA','SomeIdent2','DefaultString');
var3 := myIni.ReadString('SectionA','SomeIdent3','DefaultString');
myIni.Free;
end;
the var1, var2 and var3 will hold what is loaded from the ini. Where it says SectionA it will create a group of variables. SomeIdent tell you what you saved there. For example it could be in your case what flight data you are storing there (IE: altitude, airspeed, etc etc). DefaultString is what the value will be if the entry is missing.
Saving to an ini file:
CODE
procedure TForm1.Button2Click(Sender: TObject);
var myIni: TIniFile;
begin
myIni := TIniFile.Create('C:\somedir\myini.ini');
myIni.WriteString('SectionA','SomeIdent1','Your variable1');
myIni.WriteString('SectionA','SomeIdent2','Your variable2');
myIni.WriteString('SectionA','SomeIdent3','Your variable3');
myIni.Free;
end;
var myIni: TIniFile;
begin
myIni := TIniFile.Create('C:\somedir\myini.ini');
myIni.WriteString('SectionA','SomeIdent1','Your variable1');
myIni.WriteString('SectionA','SomeIdent2','Your variable2');
myIni.WriteString('SectionA','SomeIdent3','Your variable3');
myIni.Free;
end;
This is almost the same as the loading bit. You do not have to declare a save routine as this is automatic. Just make sure the section names and identifiers are the same
as in the loading procedure.
Make sure that you Free; the myIni (or whatever you call it) after using it to not waste memory.
Just remember that .INI files are NOT suitable for saving
HUGE amounts of data.
Source