Skip to content

Instantly share code, notes, and snippets.

View Pasquina's full-sized avatar

Milan Vydareny Pasquina

  • Chicago, Illinois
View GitHub Profile
@Pasquina
Pasquina / DelphiFileStreamMemo.pas
Created April 4, 2021 21:30
Sample FileStream writing TMemo lines
{ Saving from TMemo.Lines does not honor the TrailingLineBreak option of
TStrings. }
procedure TfSavingMemoLines.aSaveLinesExecute(Sender: TObject);
var
LMode: Word; // in case we need to create the file
LFileStream: TFileStream; // handle the writing
begin
if not FileExists(LogFileName) then // test for file exists
LMode := fmCreate // not present need to create
@Pasquina
Pasquina / UtilGUID_Def.SQL
Created November 8, 2020 22:31
UtilGUID External Function Declarations
DECLARE EXTERNAL FUNCTION GUIDFROMANSI
CHAR(38) CHARACTER SET ISO8859_1
RETURNS CHAR(16) CHARACTER SET OCTETS FREE_IT
ENTRY_POINT 'GUIDfromANSI' MODULE_NAME 'UtilGUID';
DECLARE EXTERNAL FUNCTION GUIDTOANSI
CHAR(16) CHARACTER SET OCTETS
RETURNS CHAR(38) CHARACTER SET ISO8859_1 FREE_IT
ENTRY_POINT 'GUIDtoANSI' MODULE_NAME 'UtilGUID';
@Pasquina
Pasquina / IBGUIDExample.pas
Created November 8, 2020 22:29
Interbase GUID Usage Example
/* Domain definitions */
CREATE DOMAIN ENTITYNAME AS VARCHAR(36) CHARACTER SET UTF8 NOT NULL;
CREATE DOMAIN ENTRYINACTIVE AS BOOLEAN
DEFAULT False NOT NULL;
CREATE DOMAIN ID_GUID AS CHAR(16) CHARACTER SET OCTETS NOT NULL;
/* Table: CM_CLIENTMASTER, Owner: SYSDBA */
CREATE TABLE CM_CLIENTMASTER
(
CM_ID ID_GUID NOT NULL,
@Pasquina
Pasquina / TUDFUtil.pas
Created November 8, 2020 22:26
TUDFUtil Class Definition
TUDFUtil = class
private
protected
class procedure BinToHex(var ASource, ATarget: IBDataArray; const ASourceByteCount: integer; var ASourceOffset: integer; var ATargetOffset: integer);
// Binary to Hexadecimal control routine
class procedure HexToBin(var ASource, ATarget: IBDataArray; const ATargetByteCount: integer; var ASourceOffset: integer; var ATargetOffset: integer);
// Hexadecimal to Binary control routine
public
class procedure GUIDtoANSI(var ASource, ATarget: IBDataArray); // from 128-bit number to formatted hexadecimal
class procedure ANSItoGUID(var ASource, ATarget: IBDataArray); // from formatted hexadecimal to 128-bit number
@Pasquina
Pasquina / TGUID.pas
Created November 8, 2020 22:22
VCL Definition of a GUID
PGUID = ^TGUID;
TGUID = record
D1: Cardinal;
D2: Word;
D3: Word;
D4: array[0..7] of Byte;
end;
@Pasquina
Pasquina / Simplified Auto Ref Counting.txt
Created September 27, 2020 22:30
A Delphi Console Application to illustrate Automatic Reference Counting (Simplified)
program AutoFreeTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes;
type
IAutoFree = interface
@Pasquina
Pasquina / TVLBO.FormCreate.pas
Created March 25, 2018 22:04
LiveBindings Demo FormCreate and FormDestroy
procedure TVLBO.FormCreate(Sender: TObject);
begin
MDLBO := TMDLBO.MDLBOGet;
end;
procedure TVLBO.FormDestroy(Sender: TObject);
begin
MDLBO.Free;
end;
@Pasquina
Pasquina / TMDLBO.absBranchesCreateAdapter.pas
Last active March 25, 2018 21:37
LiveBindings Demo Creating the TListBindSourceAdapter<TBranch> (Alias BranchListBSWrapper)
{ When the Adapter Bind Source for Branches is created, this event handler creates the
necessry BranchListBSWrapper and passes it back to the Bind Source Adapter. }
procedure TMDLBO.absBranchesCreateAdapter(
Sender: TObject;
var ABindSourceAdapter: TBindSourceAdapter);
begin
{ Begin by creating the BranchWrapper and saving it in the current form }
@Pasquina
Pasquina / TMDLBO.AfterBranchScroll.pas
Created March 25, 2018 20:47
LiveBindings Demo AfterScroll Event Handler
{ When the Branch list changes, either because of a scroll, or add or delete, this routine adjusts the
Employee list to display the appropriate employees }
procedure TMDLBO.AfterBranchScroll(ABindSourceAdapter: TBindSourceAdapter);
var
LBranch: TBranch; // currently displayed Branch
begin
{ A series of casts extracts the current TBranch object being displayed }
@Pasquina
Pasquina / DBLBO.TypeAlias.pas
Created March 25, 2018 20:31
LiveBindings Demo Type Aliases
{ These Type Aliases accomplish two things:
1. They eliminate the need to key the cumbersome generic notation every time the type is used
2. They provide meaningful names in place of confusing names used by Live Bindings }
CorpObjectBSWrapper = TObjectBindSourceAdapter<TCorp>; // the corporate object wrapper
BranchListBSWrapper = TListBindSourceAdapter<TBranch>; // the branch object list wrapper
EmployeeListBSWrapper = TListBindSourceAdapter<TEmployee>; // the employee object list wrapper