Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Saving Projects

CeesCees Member Posts: 4
Can somebody please help me.

1 Edit1
1 Memo1
1 Button1(open)
1 Button2(save)
1 SaveDialog
1 OpenDialog
1 ActionList

I can save and open the Memo1 by using:
Memo1.Lines.SaveToFile(FileName); is no problem.
But how can i save the data in the Edit1.
Edit1.text.SaveToFile(FileName); is the big problem.

Comments

  • FractionFraction Member Posts: 20
    : Can somebody please help me.
    :
    : 1 Edit1
    : 1 Memo1
    : 1 Button1(open)
    : 1 Button2(save)
    : 1 SaveDialog
    : 1 OpenDialog
    : 1 ActionList
    :
    : I can save and open the Memo1 by using:
    : Memo1.Lines.SaveToFile(FileName); is no problem.
    : But how can i save the data in the Edit1.
    : Edit1.text.SaveToFile(FileName); is the big problem.
    :
    :

    If you want your program to save stuff you can use a TIniFile:

    // Add IniFiles to your uses clause:

    uses
    IniFiles

    // then do something like this:

    procedure TForm1.FormCreate(Sender: TObject); // Load your settings on FormCreate
    begin
    with TIniFile.Create('MyApp.ini') do begin
    Edit1.Text := ReadString('Strings', 'Edit1', ''); // in section "Strings" read string of identifer "Edit1" if it exists, else Edit1 is empty
    // etc....
    end;
    end;

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); // Save your settings on FormClose
    begin
    with TIniFile.Create('MyApp.ini') do begin
    WriteString('Strings', 'Edit1', Edit1.Text); // in section "Strings" write string to identifer "Edit1" of value in Edit1.Text
    // etc....
    end;
    end;

  • FractionFraction Member Posts: 20
    : Can somebody please help me.
    :
    : 1 Edit1
    : 1 Memo1
    : 1 Button1(open)
    : 1 Button2(save)
    : 1 SaveDialog
    : 1 OpenDialog
    : 1 ActionList
    :
    : I can save and open the Memo1 by using:
    : Memo1.Lines.SaveToFile(FileName); is no problem.
    : But how can i save the data in the Edit1.
    : Edit1.text.SaveToFile(FileName); is the big problem.
    :
    :

    And free your IniFile when you're done:

    with TIniFile.Create('MyApp.ini') do begin
    // read or write your settings...
    Free; // <-- Free it when you're done!!!
    end;

    Sorry for that!
  • CeesCees Member Posts: 4
    Can you tell me where i can find the component "TIniFile" so i can add it into my form. I'm using delphi-6
    Sorry about that, i'm just a beginner..
  • zibadianzibadian Member Posts: 6,349
    : Can somebody please help me.
    :
    : 1 Edit1
    : 1 Memo1
    : 1 Button1(open)
    : 1 Button2(save)
    : 1 SaveDialog
    : 1 OpenDialog
    : 1 ActionList
    :
    : I can save and open the Memo1 by using:
    : Memo1.Lines.SaveToFile(FileName); is no problem.
    : But how can i save the data in the Edit1.
    : Edit1.text.SaveToFile(FileName); is the big problem.
    :
    :
    The Text property is a string. You need to save it using the old pascal-style textfiles (AssignFile(), writeln(), closefile()). Or you need to add it to a TStringList and then call the SaveToFile() method.

    PS: the TIniFile is declared in the IniFiles unit.

    All this information is also shown in the online help files.
  • FractionFraction Member Posts: 20
    : Can you tell me where i can find the component "TIniFile" so i can add it into my form. I'm using delphi-6
    : Sorry about that, i'm just a beginner..
    :

    in the top of your sourcecode it looks something like this:

    [blue]
    unit Unit1;

    interface

    [/blue][red]uses[/red][blue]
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs;
    [/blue]

    Under the "uses" clause (marked with red) are the units your unit uses. Now, just add IniFiles to it like:

    [blue]
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs[/blue][red], IniFiles[/red][blue];
    [/blue]

    Good Luck!
Sign In or Register to comment.