Solved

Is it possible to do this WITHOUT a database?

Posted on 2004-09-18
24
215 Views
Last Modified: 2010-04-05
Hi folks,

I´d like to develop a very SIMPLE application which i could add some people birthday´s day and, when a day is the birthday of someone, the application alerst me. I didn´t like to use any database (even MS Access). Is it possible to implement what i want WITHOUT any database? Do you have any idea/suggestion?

Best regards...
0
Comment
Question by:joelsilva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
  • 3
24 Comments
 
LVL 4

Accepted Solution

by:
LMuadDIb earned 30 total points
ID: 12093646
Well, the way I would do it without a database is to use WriteComponent & ReadComponent
Using this, I can save and load a treeview (the object  and all of its contents) to a dat file easily without the need of a database.

Creat a project with 3 buttons (read/write & clear) and a treeview and add the following code-


var
  Form1: TForm1;
  F: TFileStream;
  CurDir : String;

implementation

{$R *.dfm}

procedure TForm1.WriteClick(Sender: TObject);
{ WRITE THE OBJECT TO A FILE VIA STREAM }
var
  i: integer;
begin
  CurDir := ExtractFileDir(Application.ExeName);
  F := TFileStream.Create(CurDir + '\tv.dat', fmCreate or fmShareCompat);
  try
    { write the object (save) }
    F.WriteComponent(TreeView1);
  finally
    F.Free;
  end;
end;

procedure TForm1.ReadClick(Sender: TObject);
{ READ THE OBJECT FROM A FILE VIA STREAM }
var
  i: integer;
begin
  CurDir := ExtractFileDir(Application.ExeName);
  if FileExists(CurDir + '\tv.dat') then begin
    F := TFileStream.Create(CurDir + '\tv.dat', fmOpenRead or fmShareDenyWrite);
    try
      F.ReadComponent(TreeView1);
    finally
      F.Free;
    end;
  end;

end;

procedure TForm1.ClearClick(Sender: TObject);
begin
  treeview1.Items.Clear;
end;

you can load and save muliple objects too.
then create a search routine to look for any birthdays whenever the app is started and a new day occurs...
0
 

Author Comment

by:joelsilva
ID: 12093708
Hi friend... I deeply appreciate your suggestion.

The point is: i dont imagine how to put the NAMES and DATES in this tv.dat file... Is there any way to put this by putting the information in a Edit1 and Edit2 and click on INSERT?

Do you a have a clue how could i implement a search? I am sorry, but i never used this kind of way that you recommend me.

Thanks very much!!!
0
 

Author Comment

by:joelsilva
ID: 12093734
I dont know if you help me on my second question or not, but what do you think about using a MEMO OR LISTVIW in order to use a TREEVIW? I dont imagine how could a TREEVIEW structure be like this: the user NAME and his BIRTHDAY.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Hypoviax
ID: 12093938
I would use inifiles:

Steps:

1/ Declare inifiles in uses

2/Form load:

var inifile:tininfile;
birthdate:string;
begin
 inifile:=tinifile.create(extractfilepath(application.exename)+'birthdays.ini');
with inifile do
begin
     birthdate:=readstring('Birthdays',datetimetostr(date),'FALSE');
     if birthday <> 'FALSE' then
        memo1.lines.add(birthdate + '  ' + readstring('Birthdays',datetimetostr(date)+'Name',''))
free
end;
end;

3/ On entering birthdays:

procedure tform1.writebirthday(Name:string; Birth:string);

var inifile:tininfile;
birthdate:string;
begin
 inifile:=tinifile.create(extractfilepath(application.exename)+'birthdays.ini');
with inifile do
begin
     writestring('Birthdays',birth,birth);
    writestring('Birthdays',birth + name,name);
free
end;
end;

Hope this helps. I did off top of my head so there may be a couple of errors.

Regards,

Hypoviax
 
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12093941
You could do searches easily my using a simple for loop
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12093953
Also using inifiles if you want to find if there is anyones birthday on anyother day other than today just write a query similar to step2 but with the specified date instead of the current day's date.

By the way this line of code from my example....

memo1.lines.add(birthdate + '  ' + readstring('Birthdays',datetimetostr(date)+'Name',''))

... will show a result like:

19/09/2004 Michael

Regards,

Hypoviax
0
 

Author Comment

by:joelsilva
ID: 12093984
Hi,

I am very glad Hypoviax, because you also create something similar to LMUAD but using other way. I love your recommendation.

Just 2 points:

1) Why my BIRTHDAYS.INI file shows me:
[Birthdays]
01/01/1978=01/01/1978
01/01/1978joel=joel

2) There a error in this line:
==========================================================
  memo1.lines.add(birthday + '  ' + readstring('Birthdays',datetimetostr(date)+'Name',''))
==========================================================
ERROR MESSAGE: Undeclared Identifier: 'readstring'

Could you help me with these?

Thanks very much for your precious comments.
0
 

Author Comment

by:joelsilva
ID: 12093992
Is it possible that my BIRTHDAYS.INI file only shows me:
=============================
[Birthdays]
joel=01/01/1978
=============================

???
0
 
LVL 4

Expert Comment

by:LMuadDIb
ID: 12094177
"The point is: i dont imagine how to put the NAMES and DATES in this tv.dat file... Is there any way to put this by putting the information in a Edit1 and Edit2 and click on INSERT?"

You can add 2 edits (1 called "editName" and another called "editBirthday") to the form and another button that will insert the edits texts into the treeview
add this code to the Insert event:

procedure TForm1.InsertClick(Sender: TObject);
var
  xItem: TTreeNode;
begin
  with treeview1 do begin
    xItem:= Items.Add ( Nil, editName.text) ;
    Items.AddChild ( xItem, editBirthday.Text );
  end;
end;

"Do you a have a clue how could i implement a search? I am sorry, but i never used this kind of way that you recommend me."

Add Another button called Search and use this code:

//  Example: Search for Birthday in TreeView1 and select item

procedure TForm1.Button1Click(Sender: TObject);
var
  Node: TTreeNode;
begin
  //either
  Node := TreeItemSuchen(TreeView1, 'Birthday');
  TreeView1.Selected := Node;

  //or
  TreeView1.Selected := TreeItemSuchen(TreeView1, '2/2/79');
end;

// Search a TreeItem through its Text property
// Return value is a TreeNodeObject

function Form1.TreeItemSearch(TV: TTreeView; sBirthday: string): TTreeNode;
var
  i: Integer;
  iItem: string;
begin
  if (TV = nil) or (sBirthday = '') then Exit;
  for i := 0 to TV.Items.Count - 1 do  
  begin
    iItem := TV.Items[i].Text;
    if sBirthday = iItem then  
    begin
      Result := TV.Items[i];
      Exit;
    end  
    else  
    begin
      Result := nil;
    end;
  end;
end;

Now you have to be careful with your birthday DATe format so you can search for it correctly.
Instead of a string for DATE you should use a TDateTime and a TDateTimePicker component to help select the dates.
0
 
LVL 4

Expert Comment

by:LMuadDIb
ID: 12094205
then everytime you start your app or destroy it you can load/save the treeview object with ReadComponent & WriteComponent
and search the treeview upon startup, and once a day

basically the same as with the memo, except instead of the info being in text, it will be in binary.
0
 

Author Comment

by:joelsilva
ID: 12095264
Thanks very much guys...

LMuadDIb: best regards for you. Deeply thank you for providing me special attention.
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12097467
Sorry, i would have responded but i think i am operating at a differnet time zone!

Regards,

Hypoviax
0
 

Author Comment

by:joelsilva
ID: 12097610
Can you answer? :)
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12099465
sure...

writestring('Birthdays','Joel',datehere);

readstring('Birthdays','Joel','');

I might write in delphi and repost if this doesnt help you out

Regards,

Hypoviax
0
 

Author Comment

by:joelsilva
ID: 12100238
OH man... Thankx very much. Could you rewrite in delphi, because i don´t know what question did you answer me (the first or the second) :)
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12100458
yeah i did in delphi but i did off top of me head

Im doing my HSC so give me a couple of days
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12100472
Simply,

1/Alerts can be done by say showmessage('Its ' + name + 'birthday today');

2/ My method is using inifiles - no databases at all - better yet they are easy to transport
0
 

Author Comment

by:joelsilva
ID: 12109463
HSC? What does it mean?

No problem friend... When you have time, if you could, do that (don´t matter).
I deeply thank you.
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12119105
haha,

Obviously u dont come from Australia. HSC stands for Higher School Certificate.

Yeah, ill post it up soon, the HSC exams are in about 27 days

Regards,

Hypoviax
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12119684
Here's the code. Any birthdays on the day will be displayed in the memo control. You can change this around depending on how you want it:

procedure TForm1.Button1Click(Sender: TObject); //This is for adding dates
var inifile:tinifile;
birthdate:string;
begin
birthdate:=inputbox('date','enter a date','');
name:=inputbox('name','enter a name','');
 inifile:=tinifile.create(extractfilepath(application.exename)+'birthdays.ini');
with inifile do
begin
     writestring('Birthdays',birthdate,birthdate);
    writestring('Birthdays',birthdate + 'name',name);
free
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
var inifile:tinifile;
birthdate:string;
begin
 inifile:=tinifile.create(extractfilepath(application.exename)+'birthdays.ini');
with inifile do
begin
     birthdate:=readstring('Birthdays',datetimetostr(date),'FALSE'); //determine if there is a birthday today
     if birthdate <> 'FALSE' then
        memo1.lines.add(birthdate + '  ' + readstring('Birthdays',datetimetostr(date)+'name','')); //read any birthdays today
free
end;
end;

Regards,

Hypoviax
0
 

Author Comment

by:joelsilva
ID: 12121066
Hey HYPO, i dont have Delphi now but i will test your code at night.

Again friend, i thank you very much for your attention and for providing help.
Best regards...

I will add you in my friend list (i´ll show you where it is).
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12127868
Cool, no worries, any time
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12127932
If u test it put the days date in and, restart the app, otherwise youll have to wait until the actual date
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12127959
This morning for you? Because it is for me! And it is the 23rd!
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question