We help IT Professionals succeed at work.

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

TCSCode
TCSCode asked
on
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


Comment
Watch Question

Mohammed NasmanSoftware Developer
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
Hi mnasman,

 I would like to save all data in a stream, any ideas?
Mohammed NasmanSoftware Developer
CERTIFIED EXPERT

Commented:
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
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20121469

Author

Commented:
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.
Mohammed NasmanSoftware Developer
CERTIFIED EXPERT

Commented:
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

Author

Commented:
I don't want to use bde databse.. to many files to install to run.
Mohammed NasmanSoftware Developer
CERTIFIED EXPERT

Commented:
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

Author

Commented:
I only have Delphi 4.0..
Database Administrator / Software Engineer
CERTIFIED EXPERT
Commented:
Hi!
I still have the example code I sent to you.
If you give me your email I can post it to you.

Regards,
Tomas Helgi

Author

Commented:
Ok Great... my email is hyperon@eudoramail.com

Author

Commented:
Thank's Again...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.