Skip to content

Instantly share code, notes, and snippets.

@DelphiWorlds
DelphiWorlds / GetTwitterOAuth2Token.pas
Created October 16, 2023 05:54
Get OAuth2 Access Token from Twitter
const
cAuth = 'YourKeyAndSecret';
procedure TForm1.Button1Click(Sender: TObject);
var
LHTTP: THTTPClient;
LResponse: IHTTPResponse;
LContent: TStream;
LBase64: TBase64Encoding;
begin
@DelphiWorlds
DelphiWorlds / AndroidLog.pas
Created July 30, 2023 00:00
Using the Util.Log class from Android to emit log statements
uses
Androidapi.JNIBridge, Androidapi.JNI.JavaTypes, Androidapi.Helpers;
type
Jutil_LogClass = interface(JObjectClass)
['{62108FE8-1DBB-4C4F-A0C7-35D12BD116DC}']
{class} function _GetASSERT: Integer; cdecl;
{class} function _GetDEBUG: Integer; cdecl;
{class} function _GetERROR: Integer; cdecl;
{class} function _GetINFO: Integer; cdecl;
@DelphiWorlds
DelphiWorlds / Codex.Wizard.Android.Java2OPProcess.pas
Created March 25, 2023 22:33
Source used in Codex for executing Java2OP and perform post-processing
unit Codex.Wizard.Android.Java2OPProcess;
interface
uses
System.Classes,
DW.RunProcess.Win;
type
TPostProcessState = (None, UnitStart, ForwardDeclarations, ClassDeclaration, InstanceDeclaration, ImplementationSection, IgnoreDeclaration, UnitEnd);
@DelphiWorlds
DelphiWorlds / Codex.Wizard.Android.CreateJarProcess.pas
Created March 25, 2023 22:30
Source used in Codex for building a jar from Java source
unit Codex.Wizard.Android.CreateJarProcess;
interface
uses
System.Classes,
DW.RunProcess.Win;
type
TJarProcessStep = (None, BuildJava, BuildJar, DexJar);
@DelphiWorlds
DelphiWorlds / ShakeExample.pas
Created September 22, 2022 22:45
Example of how to implement iOS shake gesture in Delphi
unit Unit1;
// Form just has a button and a label on it
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Controls.Presentation,
System.TypInfo,
@DelphiWorlds
DelphiWorlds / HideMapToolbar.pas
Created August 12, 2022 07:32
How to hide the toolbar in TMapView
uses
Androidapi.JNI.PlayServices.Maps;
procedure TForm1.FormCreate(Sender: TObject);
var
LMap: JGoogleMap;
begin
if Supports(MapView1, JGoogleMap, LMap) then
LMap.getUiSettings.setMapToolbarEnabled(False);
end;
@DelphiWorlds
DelphiWorlds / PublicIP.pas
Created August 7, 2022 22:43
Get public IP address using IPify
// Inspired by:
// https://en.delphipraxis.net/topic/7258-printer-ip/?do=findComment&comment=61498
//
// Implemented in the simplest way I could think of that is also practical
// Note: This was thrown together in a few minutes, so please take care. Saving it as a Gist for posterity
uses
System.Net.HttpClient, System.JSON;
const
@DelphiWorlds
DelphiWorlds / DW.Multipeer.Mac.pas
Last active July 31, 2022 20:15
Work in progress implementation of multipeer connectivity for iOS and macOS
unit DW.Multipeer.Mac;
interface
uses
System.TypInfo,
Macapi.ObjectiveC,
{$IF Defined(IOS)}
iOSapi.Foundation,
DW.iOSapi.Foundation,
@DelphiWorlds
DelphiWorlds / SendCancelNotificationFix.pas
Created June 7, 2022 08:16
A fix for the banner not showing for the SendCancelNotification demo for Delphi 11
// Original demo is at:
// https://github.com/Embarcadero/RADStudio11Demos/tree/main/Object%20Pascal/Mobile%20Snippets/Notifications/SendCancelNotification
// Code to add to the implementation section. Use code completion to add it to the interface section:
const
cNotificationChannelId = 'NotificationsDemo';
constructor TNotificationsForm.Create(AOwner: TComponent);
begin
@DelphiWorlds
DelphiWorlds / FeedDateToDateTime.pas
Last active December 25, 2021 00:46
Convert an RSS/Atom date to datetime
uses
System.SysUtils, System.DateUtils, System.StrUtils;
// examples:
// Wed, 3 Nov 2021 18:20:21 +1030
// 21 Dec 2021 19:04:06 GMT
function FeedDateToDateTime(const AFeedDate: string): TDateTime;
var
LParts: TArray<string>;
LISO8601, LDay, LMonth: string;