![TurboPack OnGuard | Embarcadero RAD Studio Delphi C++Builder Blogs TurboPack OnGuard](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/key-3348307_1280-9747395.jpg?resize=1140%2C675&ssl=1)
TurboPack OnGuard is a copy-protection system for VCL and FMX applications built using Delphi and C++ Builder.
In this article, I illustrate using TurboPack OnGuard and an integration with back-end Digital-River’s MyCommerce.
Digital River MyCommece platform is a sales ordering platform for customers to order software.
Table of Contents
Getting Started
In the below video you can see it takes less than a minute to install OnGuard.
Step 1. Select Tools > GetIt Package Manager, as seen below.
![GetIt OnGuard | Embarcadero RAD Studio Delphi C++Builder Blogs GetIt OnGuard](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/image5-4389240.png?resize=750%2C337&ssl=1)
When the GetIt Package Manager Window appears (shown below).
1. type in “onguard”.
2. Click on the Install Button.
![Get It OnGuard | Embarcadero RAD Studio Delphi C++Builder Blogs Get It OnGuard](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/image6-2488216.png?resize=750%2C452&ssl=1)
After installation, go to the Component Palette. Scroll to the bottom, you should see OnGuard, with all the registered components.
1. OnGuard VCL components
My First Licensed App
A sample copy-protected app takes around ~ 5 minutes to make.
Using TurboPower OnGuard, you first create a Key. You can right-click on an OnGuard component and click the “Generate Key” menu.
![Generate Key OnGuard | Embarcadero RAD Studio Delphi C++Builder Blogs Generate Key OnGuard](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/image20-1462719.png?resize=661%2C611&ssl=1)
This will bring-up a Key Maintenance Dialog Box.
1. If you have not created a key. click the Button with Folder picture, to save the OnGuard key to disk.
2. If this is your first time, click the “Add…” button to generate a key.
3. Optional – copy Key to Clipboard.
![OnGuard Key Window | Embarcadero RAD Studio Delphi C++Builder Blogs OnGuard Key Window](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/image21-2656822.png?resize=728%2C445&ssl=1)
If you selected [2] from the previous Dialog box, you will go to this small dialog box. Click on the Key Button to generate a key.
![OnGuard Add Key | Embarcadero RAD Studio Delphi C++Builder Blogs OnGuard Add Key](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/image22-8410370.png?resize=717%2C162&ssl=1)
Errors Occurred during Development
![OnGuard Error | Embarcadero RAD Studio Delphi C++Builder Blogs OnGuard Error](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/2020-12-20_5-43-06-4179482.png?resize=599%2C161&ssl=1)
You need to add code to the Component Event OnGetKey:
1 2 3 4 5 |
procedure TForm1.OgRegistrationCode1GetKey(Sender: TObject; var Key: TKey); const CKey: TKey = ($E5, $8F, $84, $D6, $92, $C9, $A4, $D8, $1A, $FA, $6F, $8D, $AB, $FC, $DF, $B4); begin Key := CKey; end; |
Then, add code to Event GetCode:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
procedure TForm1.OgRegistrationCode1GetCode(Sender: TObject; var Code: TCode); var Reg: TRegistry; S: string; begin Reg := TRegistry.Create(KEY_READ or KEY_WRITE); Reg.RootKey := HKEY_CURRENT_USER; Reg.OpenKey('SoftwareYourAppReg', true); try S := ''; if Reg.ValueExists('RegistrationCode') then S := Reg.ReadString('RegistrationCode'); {convert to proper form} HexToBuffer(S, Code, SizeOf(Code)); {set code label caption} CodeLbl.Caption := S; finally Reg.Free; end; end; |
Integration with Digital River Back-End
After your first sales, you find, you need to manually issue keys for your customer. If you have many orders, this becomes time-consuming affair. Wouldn’t you wish this could be automatic?
Digital River’s Admin Panel allows Delphi Console-Based VCL App to generate keys to be uploaded!In the below, a Key Issuance console app – digitalriver.keyissuance.yourapp.dpr does the job:
You need to replace PROD constant with the Product SKU ID from Digital River’s Admin Panel.
The CKey is same as embedded in your app.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
const // Product ID. Obtain from Digital River Admin Panel PROD = 100000001; // This key must be same as in App. CKey: TKey = ($E5, $8F, $84, $D6, $92, $C9, $A4, $D8, $1A, $FA, $6F, $8D, $AB, $FC, $DF, $B4); procedure GenerateKey(productId: integer; REG_NAME, EMAIL: string; p2, p3: string); begin var UserKey, CCKey: string; var ts1, ts2: TStringList; var Work: TCode; var OgMakeCodes1 := TOgMakeCodes.Create(nil); var dtNow := EncodeDate(2021, 12, 31); OgMakeCodes1.SetKey(CKey); InitRegCode(CKey, string(REG_NAME), dtNow, Work); CCKey := BufferToHex(Work, SizeOf(Work)); UserKey := 'Username: ' + UTF8Encode(REG_NAME) + #13#10 + 'Key: ' + CCKey; ts1 := TStringList.Create; try ts1.Add(UserKey); ts1.SaveToFile(p2); ts1.Free; except exitcode := ERC_FILE_IO; end; // ts2 := TStringList.Create; try ts2.Add(CCKey); ts2.SaveToFile(p3); ts2.Free; except exitcode := ERC_FILE_IO; end; OgMakeCodes1.free; exitcode := ERC_SUCCESS; end; |
There is a small test-case included in the source-code –
1 2 3 |
".digitalriver.keyissuance.yourapp.exe" "input.300775082.txt" "output.300775082user.txt" "output.300775082serial.txt" ".digitalriver.keyissuance.yourapp.exe" "input.300775083.txt" "output.300775083user.txt" "output.300775083serial.txt" pause |
After compiling the Key Issuance Delphi console application, upload it to Digital River’s Administration Panel.
The below shows example invoice (* certain information redacted as it is test invoice)
![20201220607101837315 | Embarcadero RAD Studio Delphi C++Builder Blogs 2020 12 20 6 07 10 1837315](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/2020-12-20_6-07-10-1837315.png?resize=750%2C494&ssl=1)
![20201220609423192194 | Embarcadero RAD Studio Delphi C++Builder Blogs 2020 12 20 6 09 42 3192194](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/2020-12-20_6-09-42-3192194.png?resize=750%2C426&ssl=1)
Entering Data from into the Demonstration App, the app is licensed –
![OnGuard Example | Embarcadero RAD Studio Delphi C++Builder Blogs OnGuard Example](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/onguard-7935928.png?resize=349%2C198&ssl=1)
OnGuard also works with Chinese, Korean, Thai and Arabic Names –
![OnGuard Example | Embarcadero RAD Studio Delphi C++Builder Blogs OnGuard Example](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/onguard-7935928.png?resize=349%2C198&ssl=1)
The source-code for this demonstration project is at https://github.com/PolywickStudio/OnGuardRecipe.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition