WindowsStore コンポーネントの利用
TWindowsStore コンポーネントにより、Windows アプリケーションを Windows ストアに接続させ、ユーザーが所有するアプリケーション、利用可能なアドオン、購入済みのアドオンのリストを取得したり、トライアル モードを処理する、といった機能を使用することができます。
TWindowsStore コンポーネントは、Windows プラットフォームに対してのみサポートされており、RAD Studio 10.3 Athens は、VCL 版と FireMonkey 版を同梱しています。 TWindowsStore は、TWindowsStoreCore のコンポーネント ラッパーです。
ユーザーが所有するアプリケーションやアドオンの確認
ユーザーが所有する Windows アプリケーションやアドオンのリストを抽出するには、TWindowsStore コンポーネントをフォームに入れるか、実行時に作成し、TButton を追加して、次のコードを含める必要があります:
procedure TStoreForm.lbInfoClick(Sender: TObject);
var
LMsg: string;
const
//These consts mirrors the name of the Add-Ons ad defined
//in the MS Windows Store. Using this approach you can “Ask” to the
//store what the current user has bought.
//The current user is indentified automatically because the
//app has been downloaded from the store.
HENRYFORDQUOTES = 'henryfordquotes';
SAVETOFILE = 'savetofile';
SAVEASFAVOURITE = 'saveasfavourite';
begin
LMsg := '**You current situation**' + sLineBreak;
LMsg := LMsg + 'You ' + IfThen(WindowsStore1.UserHasBought(HENRYFORDQUOTES),
'have bought', 'don''t have bought') +
' the great Henry Ford aphorisms archive.' + sLineBreak;
LMsg := LMsg + 'You ' + IfThen(WindowsStore1.UserHasBought(SAVETOFILE),
'have bought', 'don''t have bought') +
' the ability to save aphorisms to file.' + sLineBreak;
LMsg := LMsg + 'You ' + IfThen(WindowsStore1.UserHasBought(SAVEASFAVOURITE),
'have bought', 'don''t have bought') +
' the ability to save aphorisms as favourite.' + sLineBreak;
ShowMessage(LMsg);
end;
利用可能なアドオンへのアクセス
また次のコードのように、このコンポーネントにより、AppProducts インデックス付きプロパティ(sgAvailableProducts は TStringGrid です)にアクセスして、すべての利用可能なアドオンを調査することができます。
procedure TStoreForm.UpdateAvailableProducts;
var
LProdsCount: Integer;
I: Integer;
LRow: TStrings;
begin
LProdsCount := WindowsStore1.AppProducts.Count;
for I := 0 to LProdsCount - 1 do
begin
LRow := sgAvailableProducts.Rows[I + 1];
LRow.Add(WindowsStore1.AppProducts[I].StoreId.ToString);
LRow.Add(WindowsStore1.AppProducts[I].Title.ToString);
LRow.Add(WindowsStore1.AppProducts[I].Price.FormattedBasePrice.ToString);
LRow.Add(WindowsStore1.AppProducts[I].ProductKind.ToString);
LRow.Add(
WindowsStore1.AppProducts[I].Price.IsOnSale.ToString(TUseBoolStrs.True)
);
LRow.Add(
WindowsStore1.AppProducts[I].IsInUserCollection
.ToString(TUseBoolStrs.True)
);
end;
End;
ユーザーが所有するアドオンの確認
ユーザーが所有するアドオンのリストを抽出するには、UserCollection インデックス付きプロパティを使用します。これは、AppProducts と同様に動作します。
トライアル モードの処理
AppLicense プロパティを使用すると、下のようにアプリケーションを TrialMode で処理することができます。
procedure TStoreForm.lbTrialInformationClick(Sender: TObject);
var
LRemainingTrialDays: Integer;
begin
if WindowsStore1.AppLicense.IsActive then
begin
if WindowsStore1.AppLicense.IsTrial then
begin
LRemainingTrialDays := WindowsStore1.AppLicense.TrialTimeRemaining.Days;
ShowMessage(
Format('You can use this app for %d more days before the trial period ends.',
[LRemainingTrialDays]));
end
else
begin
ShowMessage('You have a full license. The trial time is not meaningful.');
end;
end
else
begin
ShowMessage('You don''t have a license. The trial time can''t be determined.');
end;
End;
https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/Store/cs/Scenario1_TrialMode.xaml.cs#L82.}} に記載されているものを基にしています。}}