Link to home
Start Free TrialLog in
Avatar of TCSCode
TCSCode

asked on

Read/Save contents of 2 Listboxs, 2 Memos to one file.

Hi,

How can i get my program to to save all the settings in one file? but i have 2 sections i want to reload
when i click on the title of a listbox.

For example:

Listbox1 line 1 has : "Hello World"
Memo1 has           : "Hello to the world"          

Listbox2 Line 2 has : "Yard Sale"
Memo1 has           : "Yard sale friday at 8:00am"

So if i have "Hello World" selected in the listbox1 I want Memo1 to show "Hello to the world" without
quotes of course or if i have "Yard Sale" selected I would like it to show "Yard Sale friday at 8:00am"

When i close or open my program, I want it to save/load it to one file or load it from that file to
do the above!

When I load my program I would like to click on "Hello World" and "Yard Sale" and have memo1 display
the text that was saved on exit.

I will give more points if needed thank's


Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

add two buttons, listbox, memo, and edit
button1 to add from edit1 to listbox1
button2 to save the text for select item in listbox with it's text in memo to the file, all that will store in one file, when u run the program it will load all the data

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Inifiles;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    Edit1: TEdit;
    Memo1: TMemo;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ListBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  MyFile : TIniFile;

implementation

{$R *.DFM}


procedure TForm1.FormCreate(Sender: TObject);
begin
  MyFile := TIniFile.Create('c:\data.txt');
  MyFile.ReadSections(ListBox1.Items);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MyFile.Free;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  Memo1.Text := MyFile.ReadString(ListBox1.Items[ListBox1.ItemIndex],'Memo','');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.Add(Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  MyFile.WriteString(ListBox1.Items[ListBox1.ItemIndex],'Memo',Memo1.Text);
end;

end.
Avatar of TCSCode
TCSCode

ASKER

Hi mnasman,

 I would like to save all data in a stream, any ideas?
I think you asked this question before, and you got answer
why u dont' use the same answer?
here's the same question with answer
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20121469
Avatar of TCSCode

ASKER

Hi mnasman,

 Yes TomasHelgi did infact answer but since i had a hd crash, i have tryied to get the code togather but i am lost and still trying to figure it out.... or i would'nt have asked the same question over again.
why u don't try to use database, it's better for you storing and retrieving the data, you can easily add, delete or search in the database with few lines, fast way
Avatar of TCSCode

ASKER

I don't want to use bde databse.. to many files to install to run.
you can use ADO, it's not require BDE, and if you have win2000 or 98/Me, will not require any files, but maybe it's need Mdac library from microsoft, to install in the system for only one time, and then u can use the database like access that u can store many data, images, files and more
to use ADO you need to have at least Delphi 5 enterprize edition
Avatar of TCSCode

ASKER

I only have Delphi 4.0..
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TCSCode

ASKER

Ok Great... my email is hyperon@eudoramail.com
Avatar of TCSCode

ASKER

Thank's Again...