Skip to content

Instantly share code, notes, and snippets.

View omonien's full-sized avatar

Olaf Monien omonien

View GitHub Profile
@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;
@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 / 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