working on it ...

Filters

snippets
489
followers
6
Published by snip2code

Pascal

This channel collects useful snippets for Pascal language
Sort by

Found 489 snippets

    public by snip2code modified Aug 13, 2017  51  0  2  0

    First Snippet: How to play with Snip2Code

    This is the first example of a snippet: - the title represents in few words which is the exact issue the snippet resolves; it can be something like the name of a method; - the description (this field) is an optional field where you can add interesting information regarding the snippet; something like the comment on the head of a method; - the c
    /* place here the actual content of your snippet. 
       It should be code or pseudo-code. 
       The less dependencies from external stuff, the better! */

    public by FMXExpress modified Nov 13, 2014  8932  88  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 modified Nov 12, 2014  7005  9  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 modified Nov 12, 2014  4123  16  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 modified Nov 12, 2014  4588  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);

    external by cahya dyazin modified Friday at 4:49:00 AM  2  0  1  0

    Semua kodingan pascal :: semester 3

    Semua kodingan pascal :: semester 3: NilaiMahasiswa.pas
    program NilaiMahasiswa;
    
    type data = record
    	npm		: String;
    	nama 	: String;
    	uts		: Real;
    	uas		: Real;
    	tugas	: Real;
    	total	: Real;
    	grade	: Char;
    end;
    
    var mhs		: data; 
    
    begin
    	with mhs do
    	begin
    		write('Masukan npm = '); readln(npm);
    		write('Masukan nama = '); readln(nama);
    		write('Masukan nilai uts = '); readln(uts);
    		write('Masukan nilai uas = '); readln(uas);
    		write('Masukan nilai tugas = '); readln(tugas);
    
    		{ This is a formula for search sum total }
    		total := (uts+uas+tugas)/3;
    
    		if (total > 0) and (total <= 30) then
    		begin 
    			{ Grade E start from 1 until 30 }
    			grade := 'E'
    		end
    		else if (total > 30) and (total <= 50) then
    		begin
    			{ Grade D start from 31 until 50 }
    			grade := 'D'
    		end
    		else if (total > 50) and (total <= 70) then
    		begin
    			{ Grade C start from 51 until 100 }
    			grade := 'C'
    		end
    		else if (total > 70) and (total <= 90) then
    		begin 
    			{ Grade B start from 71 until 100 }
    			grade := 'B'
    		end
    		else if (total > 90) and (total <= 100) then
    		begin 
    			{ Grade A start from 91 until 100 }
    			grade := 'A'
    			}
    		end
    		else
    		begin 
    			{ If result that grade is U, it's Unknow. U is acronym from UNKNOW }
    			grade := 'U';
    			}
    		end;
    
    		writeln('Npm = ', npm);
    		writeln('Nama = ', nama);
    		writeln('Nilai uts = ', round(uts));
    		writeln('Nilai uas = ', round(uas));
    		writeln('Nilai tugas = ', round(tugas));
    		writeln('Total Nilai = ', round(total));
    		writeln('Grade = ', grade);
    	end;
    end.
    
    
    

    external by Wellington Torrejais da Silva modified Sep 5, 2017  3  0  1  0

    Delphi Function FileSize

    Delphi Function FileSize: delphi-file-size.pas
    // returns file size in bytes or -1 if not found.
    function FileSize(fileName : wideString) : Int64;
    var
      sr : TSearchRec;
    begin
      if FindFirst(fileName, faAnyFile, sr ) = 0 then
         result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow)
      else
         result := -1;
      FindClose(sr);
    end;
    
    

    external by Wellington Torrejais da Silva modified Aug 30, 2017  4  0  1  0

    Delphi AnonymousThread

    Delphi AnonymousThread : delphi-anonymous-thread.pas
    var 
     myThread : TThread;
    
    begin 
    
      myThread := TThread.CreateAnonymousThread( procedure begin
    
         // seu codigo que deseja ser executado dentro da thread
    
    
      end);
    
      myThread.start();
    
    end;
    //From https://pt.stackoverflow.com/questions/105396/como-criar-uma-anonymous-thread-em-delphi
    
    

    external by Cihad GÜNDOGDU modified Aug 21, 2017  3  0  1  0

    Delphi thread msxml hatası

    Delphi thread msxml hatası: msxml.pas
    uses ActiveX;
    
    //Thread içinde
    CoInitialize(nil);
    CoUninitialize;
    
    //metodlarını kullandığımızda sorunsuz çalışır
    
    

    external by Wellington Torrejais da Silva modified Aug 17, 2017  4  0  1  0

    MD5 hash Delphi

    MD5 hash Delphi: md5-hash-delphi.pas
    class function getMd5HashString(value: string): string;
    var
        hashMessageDigest5 : TIdHashMessageDigest5;
    begin
        hashMessageDigest5 := nil;
        try
            hashMessageDigest5 := TIdHashMessageDigest5.Create;
            Result := IdGlobal.IndyLowerCase ( hashMessageDigest5.HashStringAsHex ( value ) );
        finally
            hashMessageDigest5.Free;
        end;
    end;
    
    // From:
    // https://stackoverflow.com/questions/58621/how-do-i-hash-a-string-with-delphi
    
    
    • Public Snippets
    • Channels Snippets