Skip to content

Instantly share code, notes, and snippets.

View omonien's full-sized avatar

Olaf Monien omonien

View GitHub Profile
@omonien
omonien / ForLoopExecutionOrder.dpr
Created May 4, 2024 14:01
Demo that shows that a Delphi for loop may run in reverse order
program ForLoopExecutionOrder;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
begin
try
@omonien
omonien / ForLoopOverflow.dpr
Created May 4, 2024 13:40
Demo of Delphi for loop that runs into an overflow, because of using non-matching types
program ForLoopOverflow;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
begin
// Using unsigned ints or "short" types may lead to unexpected behaviour.
@omonien
omonien / XMLDemo.dpr
Last active December 18, 2023 14:54
Simple TXMLDocument Demo
program XmlDemo;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Winapi.ActiveX,
System.Classes, System.SysUtils, System.IOUtils,
@omonien
omonien / TCPDemo.pas
Created April 13, 2023 11:32
Indy TidTCPServer OnExecute sample that shows the idea how to process an incoming XML file
procedure TFormMain.ProcessXml(const AXml: string);
begin
var
LXmlDoc := TXMLDocument.Create(nil);
try
LXmlDoc.DOMVendor := DOMVendors.Find(OmniXML4Factory.Description);
LXmlDoc.LoadFromXML(AXml);
// if AXml is invalid, then an exception will be thrown
// Do further processing here
finally
@omonien
omonien / Countries.dpr
Created February 2, 2023 18:17
Simple example of how to create a simple, enumerable class, that inherits form a generic list. Note: TList<> is sufficient for strings, as strings are managed. No need for TObjectList.
program Countries;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.Classes, System.SysUtils, System.Generics.Collections;
@omonien
omonien / test.pas
Created January 2, 2023 10:45
C# to Delphi by ChatGPT
procedure PrintValue(const Value: TObject; const ValueType: TType);
var
TypeCode: TTypeCode;
TypeData: PTypeData;
TypeInfo: PTypeInfo;
begin
if Value = nil then
begin
WriteLn(ValueType);
Exit;
program CurrencyTests;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
@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
unit JsonNaming.Foo;
interface
uses
System.Classes, System.SysUtils,
REST.Json.Types;
type
TFoo = class(TObject)
@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;