FMXExpress
FMXExpress
Reputation Top 5%
FMXExpress
4 Snippets  (163rd place)
Published
1 Channel
Created
1 Channel
Following
Nov 12, 2014
Last Visit
Mar 3, 2014
Registered
126 points  (237th place)
Reputation
Junior Code Generator
Serious Code Generator
Junior Publisher
Junior Topic Creator
Junior Topic Hub
Junior Trend Maker
Junior Judge
Junior Popular Coder
Junior Autobiographer
Serious Autobiographer
Junior Snip2Coder
Junior Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by FMXExpress

public by FMXExpress created Nov 13, 2014  9406  95  7  1

Non Blocking Message Dialog For Delphi XE7 Firemonkey

MessageDlg(‘Do you want to press yes or no?’, System.UITypes.TMsgDlgType.mtInformation,
  [System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo], 0,
    procedure(const AResult: TModalResult)
    begin
      case AResult of
        { Detect which button was pushed and show a different message }
        mrYes:
            begin
            // pressed yes
            end;
        mrNo:
            begin
            // pressed no
            end;
      end;
    end
  );
// code here would get executed right away
;

public by FMXExpress created Mar 3, 2014  7741  10  9  4

Install A Shortcut On Android With Delphi XE5 Firemonkey

http://www.fmxexpress.com/install-shortcuts-on-the-android-home-screen-with-delphi-xe5-firemonkey/
//Android permission required:
//<uses-permission android:name=”com.android.launcher.permission.INSTALL_SHORTCUT”/>
    
Uses
Androidapi.JNI.GraphicsContentViewText, FMX.Helpers.Android,
Androidapi.JNI.JavaTypes, FMX.Platform.Android, AndroidApi.JniBridge, AndroidApi.Jni.App,
AndroidAPI.jni.OS;

{$IFDEF ANDROID}
var
ShortcutIntent: JIntent;
addIntent: JIntent;
wIconIdentifier : integer;
wIconResource : JIntent_ShortcutIconResource;
{$ENDIF}
begin
{$IFDEF ANDROID}

ShortcutIntent := TJIntent.JavaClass.init(SharedActivityContext, SharedActivityContext.getClass);
ShortcutIntent.setAction(TJIntent.JavaClass.ACTION_MAIN);

addIntent := TJIntent.Create;
addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_INTENT, TJParcelable.Wrap((shortcutIntent as ILocalObject).GetObjectID));// here we need to cast the intent as it’s not done in delphi by default, not like java
addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_NAME, StringToJString(Application.Title));
addIntent.setAction(StringToJString(‘com.android.launcher.action.INSTALL_SHORTCUT’));
// get icon resource identifier
wIconIdentifier := SharedActivity.getResources.getIdentifier(StringToJString(‘ic_launcher’), StringToJString(‘drawable’), StringToJString(‘com.embarcadero.HeaderFooterApplication’)); // if the app name change, you must change the package name
wIconResource := TJIntent_ShortcutIconResource.JavaClass.fromContext(SharedActivityContext, wIconIdentifier);
// set icon for shortcut
addIntent.putExtra(TJIntent.JavaClass.EXTRA_SHORTCUT_ICON_RESOURCE, TJParcelable.Wrap((wIconResource as ILocalObject).GetObjectID));

SharedActivityContext.sendBroadcast(addIntent);

{$ENDIF}
 
;

public by FMXExpress created Nov 12, 2014  4501  20  6  1

Decode GZIP Content From TRESTClient In Delphi XE7 Firemonkey

RESTClient.AcceptEncoding := 'gzip, deflate';
RESTClient.Execute;

if RESTResponse.ContentEncoding=’gzip’ then
DecodeGZIPContent(RESTResponse.RawBytes) // decode and do something with the content
else
RESTResponse.Content; // do something with the content

function DecodeGZIPContent(RawBytes: System.TArray<System.Byte>): String;
var
MSI: TMemoryStream;
MSO: TStringStream;
begin
MSI := TMemoryStream.Create;
MSO := TStringStream.Create;
MSI.WriteData(RawBytes,Length(RawBytes));
MSI.Seek(0,0);
// Zlib is a TIdCompressorZlib
Zlib.DecompressGZipStream(MSI,MSO);
MSI.DisposeOf;
MSO.Seek(0,0);
Result := MSO.DataString;
MSO.Free;
end;
;

public by FMXExpress created Nov 12, 2014  4910  2  7  1

Process Strings Using A Parallel For Loop In Delphi XE7 Firemonkey

TParallel.For(0,1000,
 procedure(I: Integer)
  begin
   TThread.Queue(TThread.CurrentThread,
    procedure
     begin
      Memo1.Lines.Append(I.ToString);
     end);
  end);
;