delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


Make a shareware easily (Component)Component available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Make a shareware easily (Component)
Product:
Delphi all versions
Category:
N/A
Skill Level:
Scoring:
Last Update:
02/22/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet shareware share ware times restriction registry
Times Scored:
3
Visits:
3383
Uploader: liquid snake
Company:
Reference: N/A
Component Download: http://under7.multimania.com/ShareWareDemo.ZiP
 
Question/Problem/Abstract:
How can i determine the number of times to use my application ?(shareware)
Answer:



Unit ShareWareTimes;
{********************************************************}
{                                                        }
{             Creating a shareware easily !!             }
{                   Under7@iFrance.com                   }
{                                                        }
{********************************************************}
Interface

Uses Registry, Classes, SysUtils, Windows;
(******************************************************}
Introduction
============
To use this component install it using delphi menu
Component > Install a Component
give the correct address to the unit and then compile
the package.

After installing the component just drop it to your
main form.

How to use :
============
You can read the number of times that the application was
used by :
ShareWareTimes1.Read; (Integer value)

You can add what you want to the current value using :
ShareWareTimes1.Add(3);
You should set WriteSession to false after writing to
avoid adding 1 when the component is destroyed.

If you don't have access to the registry an error will be raised.

Hints :
=======
1) The number max uses is seen in your resources and it
can be easily modified !!! so you have to set it on runtime
by : ShareWare1.MaxUses := 10;

2) You should also write alone the number of times that the
app was used because the current writing wait until the app
destroys the component ! The problem is that who use your
application can terminate its process and the component will
not write ...
You can see that just by running your app under delphi and
then use terminate the program (Ctrl+F2)

3) You should use other keys, for example :
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion

Sorry, my english is too bad !

                 Liquid Snake.
(******************************************************)
Type TOnElapsed = Procedure of object;
Type TRootKeys  = (Classes_Root,Current_User,Local_Machine,
     Users,Performance_Data,Current_Config,Dyn_Data);
Type
TShareWareTimes = Class(TComponent)

Private
  FRootKey      :TRootKeys;
  FKeyName,
  FKeyValue     :String;
  FMax          :Byte;
  FElapsed      :TOnElapsed;
  FWriteSession :Boolean;
Public
  Function    Read:Integer;
  Constructor Create(Aowner :TComponent);override;
  Destructor  Destroy; override;
  Procedure   Add(Index:ShortInt);
Published
  Property    MaxUses     : Byte       read FMax          write FMax;
  Property    RootKey     : TRootKeys  read FRootKey      write FRootKey;
  Property    KeyName     : String     read FKeyName      write FKeyName;
  Property    KeyValue    : String     read FKeyValue     write FKeyValue;
  Property    OnElapsed   : TOnElapsed read FElapsed      write FElapsed;
  Property    WriteSession: Boolean    read FWriteSession write FWriteSession;
end;

Procedure Register;

Implementation

Procedure Register;
begin
RegisterComponents('ShareWare', [TShareWareTimes]);
end;

Function RootKeyConvert(R:TRootKeys):HKEY;
begin
{Convert the rootkeys values to cardinals ...}
Result:=HKEY_CURRENT_USER;
if R=Local_Machine then Result:=HKEY_LOCAL_MACHINE;
if R=Classes_Root then Result:=HKEY_CLASSES_ROOT;
if R=Users then Result:=HKEY_USERS;
if R=Performance_Data then Result:=HKEY_PERFORMANCE_DATA;
if R=Current_Config then Result:=HKEY_CURRENT_CONFIG;
if R=Dyn_Data then Result:=HKEY_DYN_DATA;
end;

Function IsInteger(Value :String):Boolean;
var i:integer;
begin
//See if the value given is a valid integer.
Result:=False;
if Value='' then exit;
for i:=1 to length(Value) do
if not (Value[i] in ['0'..'9','+','-']) then exit;
Result:=True;
end;

Function TShareWareTimes.Read:integer;
var F:String;
begin
//Get the number of times that your application was used.
with TRegistry.Create do try
RootKey:=RootKeyConvert(FRootKey);
OpenKey(KeyName, True);
{I don't want to use the ReadInteger because it raise an
exception for the first time !!}
F:=ReadString(KeyValue);
if not IsInteger(F) then F:='0';
Result:=StrToInt(F)+1;
if (Result>MaxUses) and Assigned(OnElapsed) then OnElapsed;
finally Free;
end;
end;

Constructor TShareWareTimes.Create(Aowner :TComponent);
begin
inherited   Create(AOwner);
RootKey     :=Current_User;
KeyName     :='ShareWare key';
KeyValue    :='ShareWare value';
MaxUses     :=10;
WriteSession:=True;
end;

Destructor TShareWareTimes.Destroy;
begin
if WriteSession then Add(1);
inherited Destroy;
end;

procedure TShareWareTimes.Add(Index:ShortInt);
begin
with TRegistry.Create do try
RootKey:=RootKeyConvert(FRootKey);
OpenKey(KeyName, True);
WriteString(KeyValue,IntToStr(Read+Index-1));
finally Free;end;
end;

end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
shareware can be easily crack
    Nenad Fidanovski (Mar 6 2002 11:49AM)

If somebody tries a bit more to check the registry, he will find out that
Max Uses is limited or no of uses increases all the time
So as soon as he change the registry
app will again work.
better to encrypt or even more use serial no of driver
that is better solution

Regards,
nenadf@freemail.org.mk
Respond

bad sample:-(
    Mike Shkolnik (Feb 27 2002 11:08AM)

IMHO this is a sample for registry work more than sample of shareware trials.

Try to add:
1. to encrypt/decrypt stored values
2. to use a few different places as storage for same values. For example, to store a trial count in registry+as time of file+record in own database+resource of exe/dll

I think that in this case this sample will show more useful information...

With best regards, Mike Shkolnik
E-Mail: mshkolnik@scalabium.com
        mshkolnik@yahoo.com
WEB: http://www.scalabium.com

Respond

:)
Liquid Snake (Mar 2 2002 5:04PM)

Hi :

The question was how to create a shareware and me i have just written an article on how to do that !!

And this sample is not the only way to create a shareware !! me i choose the Registry to create it !!! and if i wrote a way to create a shareware using Files/Dlls or something else i'm sure you'll write me that this is a sample for using Files/Dlls :-)

Ok, thanks for your comment and have fun !!
I'm not interessted by this article, i have just written it for beginners and who doesn't know how to do it ;-)

                   Liquid Snake
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
D. Wischnewski
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)