We're updating the Delphi example to make things easier. In the meantime here's an example of reading and using a custom license field:
if isGenuine then begin // read in a custom license field named "update_expires" featureValue := ta.GetFeatureValue('update_expires', '');
// if the date has passed then kill the app immediately if (featureValue = '') Or (not ta.IsDateValid(featureValue, TA_HAS_NOT_EXPIRED)) then begin ShowMessage('Your subscription has expired. Buy a renewal.');
// Exit the app, and exit the function immediately Application.Terminate; exit; end; end;
And you'll need to modify the TurboActivateUnit.pas to directly use WideStrings rather than pointers. We'll include this in the updated delphi example (out with the next version of TurboActivate). Here it is in the meantime:
/// <summary>/// Gets the value of a feature./// </summary>/// <param name="featureName">The name of the feature to retrieve the value for.</param>{$IFDEF MACOS}function TurboActivate.GetFeatureValue(featureName: s): UnicodeString;{$ELSE}function TurboActivate.GetFeatureValue(featureName: WideString): WideString;{$ENDIF}var{$IFDEF MACOS} value : UnicodeString;{$ELSE} value : WideString;{$ENDIF}begin value := GetFeatureValue(featureName, '');
if (value = '') then begin raise ETurboActivateException.Create('Failed to get feature value. The feature doesn''t exist.'); end;
Result := value;end;
/// <summary>/// Gets the value of a feature./// </summary>/// <param name="featureName">The name of the feature to retrieve the value for.</param>/// <param name="defaultValue">The default value to return if the feature doesn't exist.</param>{$IFDEF MACOS}function TurboActivate.GetFeatureValue(featureName: UnicodeString; defaultValue: UnicodeString): UnicodeString;{$ELSE}function TurboActivate.GetFeatureValue(featureName: WideString; defaultValue: WideString): WideString;{$ENDIF}var ret : LongInt;{$IFDEF MACOS} featValue : PAnsiChar;{$ELSE} featValue : PWideChar;{$ENDIF}begin
{$IFDEF MACOS} // get the length of the string we need to allocate ret := TurboActivateUnit.TA_GetFeatureValue(self.handle, PAnsiChar(featureName), nil, 0);
// make the string featValue := AnsiStrAlloc(ret);
// get the string ret := TurboActivateUnit.TA_GetFeatureValue(self.handle, PAnsiChar(featureName), featValue, ret); {$ELSE} // Windows // get the length of the string we need to allocate ret := TurboActivateUnit.TA_GetFeatureValue(self.handle, PWideChar(featureName), nil, 0);
// make the string {$IF CompilerVersion >= 20} // for Delphi 2009 + featValue := StrAlloc(ret); {$ELSE} featValue := PWideChar(StrAlloc(ret * 2 + 2)); {$IFEND}
// get the string ret := TurboActivateUnit.TA_GetFeatureValue(self.handle, PWideChar(featureName), featValue, ret); {$ENDIF}
// free the string if an error happens if (ret <> 0) then begin {$IF CompilerVersion >= 20} // for Delphi 2009 + StrDispose(featValue); {$ELSE} StrDispose(PChar(featValue)); {$IFEND} end;
case ret of TA_E_INVALID_HANDLE: raise EInvalidHandleException.Create(); TA_OK: // success
{$IFDEF MACOS} Result := System.Utf8ToUnicodeString(featValue); {$ELSE} // Windows Result := featValue; {$ENDIF} else Result := defaultValue; end;end;