Solved

Is it possible to do this WITHOUT a database?

Posted on 2004-09-18
24
204 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now