Blog Options
Archive
<< March 2026 >>-
Monday 23
- Simplify Mapping Across Platforms with TMS FNC Maps -
Wednesday 18
- The Next Evolution of Charting in Delphi: Look & Feel -
Monday 16
- Better Delphi Code from AI Agents with TMS Skills -
Friday 13
- TMS Training Days 2026 - Community Evening -
Wednesday 11
- The Next Evolution of Charting in Delphi: Data Import & Export -
Monday 9
- Meet Gjalt Vanhouwaert at TMS Training Days 2026 -
Friday 6
- Meet Pieter Scheldeman at TMS Training Days 2026 -
Thursday 5
- Enabling TLS 1.3 in TMS MQTT and TMS FNC Products -
Wednesday 4
- Meet Antonio Zapater at TMS Training Days 2026 -
Tuesday 3
- The Next Evolution of Charting in Delphi: Getting Started -
Monday 2
- Meet José Leon Serna at TMS Training Days 2026
- Meet Dennis Roehner at TMS Training Days 2026
- Meet Bradley Velghe at TMS Training Days 2026
- Unlock PDF Interactivity in Delphi with TTMSFNCPDFLib Form Fields
Authors
- Bernard Roussely (3)
- Wagner Landgraf (98)
- Dennis Röhner (1)
- Roman Yankovsky (2)
- Bart Holvoet (42)
- Aaron Decramer (82)
- Pieter Scheldeman (134)
- Nancy Lescouhier (32)
- Adrian Gallero (34)
- Bruno Fierens (450)
- Marcos Douglas B. Santos (5)
- Bernard (4)
- Bradley Velghe (36)
- Andrew Simard (86)
- Holger Flick (15)
- Gjalt Vanhouwaert (44)
- Tunde Keller (37)
- Masiha Zemarai (117)
Blog
All Blog Posts | Next Post | Previous Post
Crash Course TMS Aurelius – Blobs
Thursday, February 28, 2013
Using blobs in Aurelius is very straightforward and yet very powerful. In summary, all you have to do is declare your field/property as TBlob (declared in unit Aurelius.Types.Blob.pas). This is enough to map it to an existing blob field in your table, and you will be able to save/load the blob content is several many ways. Consider the following mapping:
[Entity, Automapping]
TCustomer = class
private
FId: integer;
FName: string;
FDocument: TBlob;
[Column('Photo', [TColumnProp.Lazy])]
FPhoto: TBlob;
[Column('Descr_Field', [], 65536)]
FDescription: string;
public
property Id: integer read FId write FId;
property Name: string read FName write FName;
property Document: TBlob read FDocument write FDocument;
property Photo: TBlob read FPhoto write FPhoto;
property Description: string read FDescription write FDescription;
end;
There is another interesting feature about blobs: Photo is declared as lazy (TColumnProp.Lazy). This indicates that Aurelius will not bring the blob from database when Customer data is retrieved. The blob is only retrieved when your code explicitly reads the content of Photo property.
The following code shows different ways of dealing with blobs (saving and loading):
function SaveCustomerWithBlobs(Manager: TObjectManager): integer;
var
Customer: TCustomer;
begin
Customer := TCustomer.Create;
Customer.Name := 'John';
Customer.Photo := TFile.ReadAllBytes('picture.bmp');
Customer.Document.AsBytes := TFile.ReadAllBytes('document.pdf');
Customer.Description := TFile.ReadAllText('description.txt');
Manager.Save(Customer);
Result := Customer.Id;
end;
procedure LoadCustomerAndExportBlobs(Manager: TObjectManager; CustomerId: integer);
var
Customer: TCustomer;
begin
Customer := Manager.Find<TCustomer>(CustomerId);
TFile.WriteAllText('description2.txt', Customer.Description);
TFile.WriteAllBytes('document2.pdf', Customer.Document);
TFile.WriteAllBytes('picture2.bmp', Customer.Photo.AsBytes);
end;
Customer.Photo := TBlob.Create(TFile.ReadAllBytes('picture.bmp'));
Customer.Document.AsString := 'Some document';
Stream := TFile.Open('picture.bmp', TFileMode.fmOpen);
Customer.Photo.LoadFromStream(Stream);
Stream.Free;
As a final note: we have added TColumnProp.Lazy to the Photo blob. We can verify if the blob is loaded using the Loaded property. We can change LoadCustomerAndExportBlobs function to check it:
Customer := Manager.Find<TCustomer>(CustomerId);
Assert(Customer.Document.Loaded);
TFile.WriteAllBytes('document2.pdf', Customer.Document);
Assert(not Customer.Photo.Loaded);
TFile.WriteAllBytes('picture2.bmp', Customer.Photo.AsBytes);
Assert(Customer.Photo.Loaded);
CREATE TABLE CUSTOMER ( ID INTEGER NOT NULL, NAME VARCHAR(255) NOT NULL, DOCUMENT BLOB, Photo BLOB, Descr_Field BLOB SUB_TYPE TEXT, CONSTRAINT PK_CUSTOMER PRIMARY KEY (ID)); CREATE GENERATOR SEQ_CUSTOMER; SELECT GEN_ID(SEQ_CUSTOMER, 1) FROM RDB$DATABASE; INSERT INTO CUSTOMER ( ID, NAME, DOCUMENT, Photo, Descr_Field) VALUES ( :A_ID, :A_NAME, :A_DOCUMENT, :A_Photo, :A_Descr_Field); SELECT A.ID AS A_ID, A.NAME AS A_NAME, A.DOCUMENT AS A_DOCUMENT, A.Descr_Field AS A_Descr_Field FROM CUSTOMER A WHERE A.ID = :p_0; SELECT A.Photo As f0_ FROM CUSTOMER A WHERE A.ID = :p_0;
Wagner Landgraf
This blog post has received 2 comments.
2. Tuesday, November 25, 2014 at 10:44:53 AM
Please contact us directly for support (see our Support menu option at our site). Basically you can use AsBytes property to read/write the content as byte array.
Wagner Landgraf
All Blog Posts | Next Post | Previous Post
Could you pleas provide source example for saving blob image from a TImage component.
Also loading Blob content to a TImage component
Thanks
Kenzo
kenzo