Skip to content

Instantly share code, notes, and snippets.

View omonien's full-sized avatar

Olaf Monien omonien

View GitHub Profile
@omonien
omonien / Unit1.pas
Last active February 1, 2020 22:25
Using other units
unit Unit1;
interface
function Foobar(AValue:integer):integer;
implementation
uses
Unit2;
@omonien
omonien / test.pas
Last active February 1, 2020 22:26
Handling NULL JSON values in Delphi
const
CUSTOMERS = '{"customers":[{"name":"Olaf"},{"name":"Big Bird"}]}';
CUSTOMERS_NULL = '{"customers":null}';
procedure TForm39.Button1Click(Sender: TObject);
var
LContainer: TJSONValue;
LCustomers: TJSONArray;
begin
//Here, the value is not nil, so you can just go ahead with GetValue
@omonien
omonien / Aurelius.Demos.Union.pas
Last active February 6, 2020 11:56
UNION in Aurelius
//Concatenate two lists - which basically is what a union of two SQL SELECTS does
LCustomersUS := LManager.Find<TCustomer>
.Where((Linq['Country'] = 'US')
.List;
LCustomersCA := LManager.Find<TCustomer>
.Where((Linq['Country'] = 'CA')
.List;
LCustomersNorthAmerica.AddRange(LCustomersUS);
LCustomersNorthAmerica.AddRange(LCustomersCA);
@omonien
omonien / Bytes.pas
Created July 16, 2020 18:50
Byte Array example
program Project46;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
SomeBytes: TBytes;
SomeByte: Byte;
@omonien
omonien / Foo.pas
Created September 2, 2020 09:37
TFoo example Gist
Unit Foo;
interface
type
TFoo = class(TObject)
end;
implementation
end.
@omonien
omonien / GenericsIssue.dpr
Last active February 17, 2021 12:33
Testing a possible generics related compiler error. UPDATE: It's a feature, not a bug.
program GenericsIssue;
{$APPTYPE CONSOLE}
{$R *.res}
//Simplified test case for https://quality.embarcadero.com/browse/RSP-32427
uses
System.SysUtils, System.Rtti;
type
@omonien
omonien / MemTest.dpr
Last active November 17, 2021 10:40
program MemTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.Classes, System.SysUtils, System.Contnrs;
const
GMaxChars = 100;
@omonien
omonien / Interfaces.dpr
Last active January 23, 2022 11:02
Simple Interface demo.
program Interfaces;
{$APPTYPE CONSOLE}
{$R *.res}
uses
LeakCheck,
System.Classes, System.SysUtils;
unit JsonNaming.Foo;
interface
uses
System.Classes, System.SysUtils,
REST.Json.Types;
type
TFoo = class(TObject)
@omonien
omonien / Forms.Base.dfm
Last active October 15, 2022 13:22
Accessing VCL controls by name, using Generics
object FormBase: TFormBase
Left = 0
Top = 0
Caption = 'FormBase'
ClientHeight = 441
ClientWidth = 624
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12