Last active
April 2, 2025 22:46
-
-
Save larsschenk/4093b81d9e83674ceb231f353fd01829 to your computer and use it in GitHub Desktop.
Delphi examples using the ActiveBarcode REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On a form (Form1) there are an input field (Edit1), | |
// an image (Image1) and a button (Button1). | |
// If you click on the button, a barcode with the text of the input field | |
// is retrieved via Barcode API and drawn into the image. | |
// | |
// For the retrieval the TIdHTTP (Indy Clients) component is used | |
// (included with Delphi 10.x). | |
// This component can be integrated by simply placing it on the form. | |
// Please note that for the https call the OpenSSL DLLs | |
// 'libeay32.dll' and 'ssleay32.dll' are required, e.g. in the program folder. | |
// | |
procedure TForm1.Button1Click(Sender: TObject); | |
var | |
MS : TMemoryStream; | |
MyPNG: TPNGImage; | |
tmp : STRING; | |
sURL : STRING; | |
sParam: STRING; | |
begin | |
MS := TMemoryStream.Create; | |
MyPNG := TPNGImage.Create; | |
try | |
sURL := 'https://api.activebarcode.net/v2/png?access=YOUR-KEY-HERE&'; | |
tmp := StringReplace(Edit1.Text, ' ', '%20',[rfReplaceAll]); | |
sParam := 'code=CODE128&text='+tmp+'&width='+inttostr(Image1.Width)+ | |
'&height='+inttostr(Image1.Height); | |
IdHTTP1.get(sURL+sParam,MS); | |
Ms.Seek(0,soFromBeginning); | |
MyPNG.LoadFromStream(MS); | |
Image1.Picture.Assign(MyPNG); | |
finally | |
FreeAndNil(MyPNG); | |
FreeAndNil(MS); | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment