Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Save files change history?

Hi all,

Suppose I saved the contents of a tmemo as a text file ....

Then another 30 minutes later (just an example)

Then my computer freezes and a lost my current work ...

How can I open the latest version saved by code?

I could save the filename with a date/time in the filename but how do I get the code to know which one it has to open without me having to check the datetime in the filename?

For example ... if the file is called:

project1
then I'd like to add a "-" (without the quotes) and then the datetime stamp included in the filename...

Then if I open Project1  .... the code checks the latest and opens that one....

Hope this makes sense.

I'm opened the suggestions if this is not the best way to do it.

thanks

st3vo
 
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy 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 ST3VO

ASKER

Hmmm...Almost perfect but I cannot rely on the sorting....  The first search on the Filename ...

e.g: Project1 etc.... The filename could have a "-" after the main name to help .....

So I could have:

Project1-somethinghere.txt
Project1-somethingelse.txt
etc...

Then I select to open Project1 and the code reads Everything before the "-" (for example) and then opens the newest one depending on datetime stamp for example?

You know what I'm after?

In the code I've posted you can open the last created Project1-whatever just using the form 'c:\somedir\Project1*.*'
This means that the TSearchRec use Project1*.* as filter, then the bubble sort return the most recent, that is the newest
Avatar of ST3VO

ASKER

Hmm...I just don't get the call example..

OpenMostRecent(GetMostRecent('c:\somedir\Project1*.*')); ....

Is it something like:

Var thefile:string;
begin
thefile :=OpenMostRecent(GetMostRecent('c:\somedir\Project1*.*'));

memo1.lines.loadfromfile(thefile);

????

OpenMostRecent is a dummy function that i've hoped you might have created.
Forget that :)
Well, you should finally use this method:

Memo1.lines.loadfromfile(GetMostRecent('c:\TheDirWhereYouAreSaving\Project1*.*));

Of course change TheDirWhereYouAreSaving with the right directory where the files are stored
Avatar of ST3VO

ASKER

Great! Thanks :o)