Source Code Delphi Samples with Sources

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
My sample to create your "re-TRY" another or same command line: like "try reconnect again my login"
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Here my sample to works with Class Helper to Strings to divide it in "before" and "after" Delimiter char! - very easy!

Код:
unit uMainForm;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    btnUsinSPLIT_function: TButton;
    ListBox1: TListBox;
    btnUsingListBox: TButton;
    ListBox2: TListBox;
    Memo1: TMemo;
    btnMyNewSplitStrings: TButton;
    procedure btnUsinSPLIT_functionClick(Sender: TObject);
    procedure btnUsingListBoxClick(Sender: TObject);
    procedure btnMyNewSplitStringsClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnUsinSPLIT_functionClick(Sender: TObject);
var
  lMyArraySpplited: TArray<string>;
  lMyRegKey       : string;
  lNewRegKey      : string;
  i               : Integer;
  lLastDelimiter  : integer;
begin
  memo1.Lines.Clear;
  //
  // if lMyRegKey = ''  or '\'  -> it's necessary verify too!
  // But DONT problem if lLastDelimiter <= 0
  // on the end, your "string" resulted can be EMPTY!
  // None exception will be raised!
  //
  lMyRegKey := 'part1\part2\part3\value';
  //
  lMyArraySpplited := lMyRegKey.Split(['\']);
  //
  lLastDelimiter := lMyRegKey.LastDelimiter('\') + 1; // +1 here or below (Rigth substring)
  //
  memo1.Lines.Add('SubString Left  = ' + lMyRegKey.Substring(-lLastDelimiter, lLastDelimiter));
  memo1.Lines.Add('SubString Right = ' + lMyRegKey.Substring(lLastDelimiter));
  //
  memo1.Lines.Add('LastDelimiter = ' + lMyRegKey.LastDelimiter('\').ToString);
  //
  memo1.Lines.Add('');
  //
  lNewRegKey := lMyRegKey.Join('\', lMyArraySpplited, 0, 2); // "part1\part2"
  //
  memo1.Lines.Add('Join 0 to 2 = ' + lNewRegKey);
  //
  lNewRegKey := lMyRegKey.Join('\', lMyArraySpplited, 3, 4); // "value"
  //
  memo1.Lines.Add('Join 3 to 4 = ' + lNewRegKey);
  //
  memo1.Lines.Add('');
  //
  for i := 0 to high(lMyArraySpplited) do
  begin
    if lMyArraySpplited[i] <> '' then
      memo1.Lines.Add(lMyArraySpplited[i]);
  end;
end;

procedure TForm1.btnMyNewSplitStringsClick(Sender: TObject);
var
  lMyRegKey       : string;
  lMyArraySpplited: TArray<string>;
begin
  Memo1.Lines.Clear;
  //
  lMyRegKey := 'part1\part2\part3\value';
  //
  // start from "1" and ending on "3" chars!
  // using "\" like my "Delimiter" to split my string!
  //
  lMyArraySpplited := lMyRegKey.Split(['\'], '1', '3', Length(lMyRegKey));
  //
  Memo1.Lines.Add('How many items SPLITTED = ' + Length(lMyArraySpplited).ToString);
  Memo1.Lines.Add('');
  Memo1.Lines.Add('my items:');
  //
  Memo1.Lines.AddStrings(lMyArraySpplited); // working with my items splitted (my array)
end;

procedure TForm1.btnUsingListBoxClick(Sender: TObject);
var
  lMyRegKey: string;
begin
  lMyRegKey := 'part1\part2\part3\value';
  //
  ListBox1.Items.Delimiter     := '\';
  ListBox1.Items.DelimitedText := lMyRegKey;
  //
  ListBox2.Items.Clear;
  ListBox2.Items.Add(ListBox1.Items[3]);
  //
  // another ways can help too, when using a "List"
  //
  // ListBox1.Items.IndexOf('first position to start')
  // ListBox1.Items.IndexOf('last position to end')
  // ShowMessage(ListBox1.Items.KeyNames[2]);
end;

end.
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Creating a "counter" to close your "Active window", like MessageDLG using SetTimer() and PostMessage() from API Windows
Code by Žarko Gajić (MVP Embarcadero)

 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Memory 3D – Full Source Code Delphi Game
by Žarko Gajić (MVP Embarcadero)
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
My sample to simple way to verify some info about your Wifi connection using new way to ask permissions on Android (7.0 - Nougat)
thanks to FMX Express forum!!!

Dont forget mark your permissions used on Project - Option in your project.

1585529338453

 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Auto-start custom Android applications
- Not necessary any change on sources Android!

 

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Easy way to save and use your Week Day in BIN format and reversing it to string:
like:
  • my StrigBin initial:1101010
  • my ShortDayNames used in Bin string: sun, mon, wed fri
  • my StringBin recreated: 1101010
Bin to ShortDayNames


 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Quick Tip: Fixing “Could not convert variant of type (Null) into type…”
thansk to CodeSmithing

...I often use the XML Data Binding wizard in Delphi. However, it doesn’t seem to have been given a lot of attention from Borland/Inprise/Borland/CodeGear/Embarcadero/Idera. And unfortunately, out of the box what it generates is often error prone, apparently not supporting optional elements/attributes.

 

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Easy way to change your StatusBar color on Android app by ZuBy
Developer ZuBy has made some demo code available for changing the StatusBar color on Android in your apps.
The status bar is the bar at the top of your device with the various icons and other information in it.
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Android ADB Terminator (code source)
If you need terminate ADB for any error while compiling (by Ray Vecchio)
 

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
GeekAlarm!
screenshot.png

GeekAlarm! is a unique way for you to keep track of when you should take a break while using your computer. By taking breaks you can increase your productivity, reduce eye strain, and allay fatigue. GeekAlarm! has varying degrees of break enforcement including passive, medium, and aggressive enforcement. This helpful utility is a must have for anyone that uses a computer for long periods of time.
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
My simple way to show FireMonkey Forms in Fade effect - no Animate components!!!
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Mobile GFX - Creating Icons and Launchers for Delphi Mobile Applications
by TGrubb
If you have ever tried to create the icons, spotlights, settings and launchers for Delphi Android and iOS applications, you have quickly realized that the process is fairly ridiculous.

There are 2 different platforms (iOS and Android), 3 different device types (iPhone, iPad, Android), and 7 different ratios (1:1, 1.33:1, etc) of icon/launcher graphic sizes all combining to require a whopping total of 28 different png files to be created (See Figure 1). Talk about taking the Rapid out of Rapid Application Development!



After doing this once, I realized that I never want to do that again. For my own sanity and yours, I have created a small little utility for quickly creating these 30 different png files and for helping fill in the Application Options page.
The utility works by allowing you to specify base image(s) for each graphic ratio, optionally defining what portion of the image to extract for each ratio, and then generating the png files. You have the option of creating iPhone, iPad, and/or Android files. In addition, the utility will even make the .optset files which Delphi uses to fill in the blanks (Click Apply… for each configuration and select the .optset file).
To use the Mobile Gfx Setup tool:
First, set up your images on the Graphics Tab


  • For each image ratio, enter or browse to an image file
  • Select the part of the image to be used for the format (shown in red)
  • Move the image selection around by Ctrl Dragging the red rectangle
Next, set up the output options from the Setup tab


  • Enter a base filename for the generated images. The tool will append the Width and Height of an image to this filename (e.g., ‘c:\junk.png’ becomes ‘c:\junk114x114.png’
  • Select which devices you want to generate images for
  • Finally, check the ‘Generate .optset file(s)’ checkbox if you want the .optset file generated which you can then later import into Delphi
Finally, generate your images from the Generate tab


  • When you go to the Generate tab, the tool will verify you have entered everything correctly
  • If validation has passed, click the Generate button to generate the images and, optionally, the .optset files (which will be called basename.android.optset and basename.ios.optset)
Finished!
If you generated the .optset file, do the following steps:
  • Load your Delphi project
  • Select Project->Options to show the project options (See Figure 1)
  • Click Application on the left to show application options
  • Change the Target configuration
  • Click the Apply… button
  • Browse to the .optset file
  • Modify the configuration and click OK!
 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Single File Data Storage (storing data-file in zip file like in SQLite way)
by coyoteelabs
Hi all, I've updated the library Single File Data Storage to work with all Delphi versions

About the library:
  • The Single File Data Storage library provides an efficient solution for an application to store many different types of data inside one file
  • able to access this data very fast and easily, without bothering about creating temporary files or streams (when requesting to read, the compressed data is decompressed on the fly directly from the source stream).

Look at the samples and in the help file to see how easy it is to use SFDS.

Features:
  • Single-file Virtual File System (read-only): SFDS files are ZIP like archive files (not really ZIP files) with enhanced functionality (see below). One or more SFDS files can be "mounted" in the application. Searching or requesting to open a stream for read will query all "mounted" files or you can just specify a single one.
  • Transparent streaming compression/decompression with full TStream compatibility.
  • Thread-safe (When reading from files): Read from multiple streams (located in the same SFDS file archive) at the same time (Just create a new clone of the stream in each thread - see demo).
  • High performance: SFDS is perfect for Games(and other applications such as backup, etc) which need to store many (usually small) files in just a small number of (big) archives. Storing data in a small number of SFDS files results in faster access time to data (When opening a SFDS file the list of streams inside is cached in memory), and also makes it harder to modify files inside.
  • Large file support (64-bit size) lets you store all the data you need in SFDS files of virtually unlimited size.
  • Supported compression types: none (stored), zlib, bzip2. New formats can easily be added.
  • Compression support is modular. Each application can chose to add only the compression it needs (if you need zlib compression/decompression simply add sfds_compressorzlib to the uses clause somewhere inside your project; add sfds_compressorbzip2 for BZip2).
  • Per stream compression option; store one stream uncompressed, another compressed with zlib, another with bzip2, etc.
  • No DLLs required.
  • No file name restrictions (including unicode file names allowed - strings are stored UTF-8 encoded, just like in .dfm files). If the file name is an empty string, then you can still access the data via file index.
  • Reading from compressed streams is just like reading from any other stream (even full seeking in any direction is allowed).
  • You can create links to streams inside SFDS files (the new entries will point to the same data).
  • Includes a list of opened reader objects, which are automatically destroyed if you forget about them (you only need to free the streams you open).
  • It has lots of routines for adding/extracting, testing (MD5 error checking) files to/from the SFDS file format.
  • It also has search routines, to easily find files inside SFDS archives (SFDS_FindFirst, SFDS_FindNext, SFDS_FindClose).
  • Supports metadata information: you can set any fields: string, number, date, boolean, binary (Metadata Editor Form included).
  • You can write/read SFDS files directly to/from any data source. Already implemented: Disk File [R/W], Memory Stream [R/W], Resource Stream [R]. Make a descendent of TSFDSCustomReader to read from any other custom source and a descendent of TSFDSCustomWriter to write to any other custom source. Once written, a SFDS file cannot have more data appended to it.
  • There are no components to install, so this library also works with the free Turbo Delphi.
  • Best of all: it's completely free (Even for commercial use).

I've made 2 versions:
  • 1st version (version 1.4.2) simply updates the library to work with the newest Delphi versions. Should still be compatible with sfds files created with original version but doesn't have unicode support. Use this one if you need to use files created in versions 1.4.1 or older.
  • 2nd version (version 1.5.0) also updates the library to support unicode (now uses string instead of ansistring). This version won't work with sfds files created with older versions (1.4.1 or older). Note that I only updated the demo .sfds files for the "Basic SFDS File Creator" demo only
 

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
How to add Android "app shortcuts" to a FMX application
by Andrea Magni
 

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
Introducing mORMot-JWT: a "new"” JWT implementation
JWT stands for JSON Web Tokens and it is a very popular technology used to implement custom-content tokens across REST services.
 

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
my sample: How to Insert MP3/MP4 file or other like a Resource into your executable and Play it in MediaPlayer (FireMonkey / VCL)
NOTE1: Dont forget, in Android/iOS you need privilegies like: read/write resource in Storages (internal or external), play some, etc.. study about use of "privilegies" in your apps!
  • NOTE2: Bad pratice insert a big file in your executable!
Screen0001

 
Последнее редактирование:

ermax

Well-known member
Команда форума
Moderator
Premium
Регистрация
05.05.2008
Сообщения
2 485
Реакции
2 188
Баллы
113
Местоположение
here and there
Native language | Родной язык
Other language
My easy way to filling my OnCalcFields like an Array of values in DBGrid using any field on DataSet with my conditional data
1588194254060

NOTE: if your table had all records deleted, verify if your "initial value - your vars" should be "cleaned" too! Else, the last values will be used for next "first record"

 
Последнее редактирование:
197 114Темы
634 084Сообщения
3 618 347Пользователи
AizenkurНовый пользователь
Верх