• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Is it possible to do this WITHOUT a database?

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
joelsilva
Asked:
joelsilva
  • 12
  • 9
  • 3
1 Solution
 
LMuadDIbCommented:
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
 
joelsilvaAuthor Commented:
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
 
joelsilvaAuthor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
HypoviaxCommented:
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
 
HypoviaxCommented:
You could do searches easily my using a simple for loop
0
 
HypoviaxCommented:
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
 
joelsilvaAuthor Commented:
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
 
joelsilvaAuthor Commented:
Is it possible that my BIRTHDAYS.INI file only shows me:
=============================
[Birthdays]
joel=01/01/1978
=============================

???
0
 
LMuadDIbCommented:
"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
 
LMuadDIbCommented:
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
 
joelsilvaAuthor Commented:
Thanks very much guys...

LMuadDIb: best regards for you. Deeply thank you for providing me special attention.
0
 
HypoviaxCommented:
Sorry, i would have responded but i think i am operating at a differnet time zone!

Regards,

Hypoviax
0
 
joelsilvaAuthor Commented:
Can you answer? :)
0
 
HypoviaxCommented:
sure...

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

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

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

Regards,

Hypoviax
0
 
joelsilvaAuthor Commented:
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
 
HypoviaxCommented:
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
 
HypoviaxCommented:
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
 
joelsilvaAuthor Commented:
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
 
HypoviaxCommented:
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
 
HypoviaxCommented:
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
 
joelsilvaAuthor Commented:
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
 
HypoviaxCommented:
Cool, no worries, any time
0
 
HypoviaxCommented:
If u test it put the days date in and, restart the app, otherwise youll have to wait until the actual date
0
 
HypoviaxCommented:
This morning for you? Because it is for me! And it is the 23rd!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 12
  • 9
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now