Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
Correct way to merge multiple TBytes
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
[SOLVED] Lazreport Horizo...
by
Petrus Vorster
[
Today
at 08:03:05 am]
We are starting to use La...
by
ALLIGATOR
[
Today
at 05:19:46 am]
The Future of FPC
by
ALLIGATOR
[
Today
at 05:01:20 am]
ThorVG - test (lightweigh...
by
ALLIGATOR
[
Today
at 04:55:46 am]
fpGUI Toolkit v2.0.1 has ...
by
cdbc
[
Today
at 02:27:42 am]
[ANN] fpGUI Toolkit v2.0....
by
Graeme
[
Today
at 01:43:31 am]
Frustrating Error When us...
by
TYDQ
[
Today
at 01:38:26 am]
Fast Canvas Library V1.05...
by
backprop
[
Today
at 01:32:51 am]
; after then
by
Martin_fr
[
Today
at 12:38:46 am]
Are the source files for ...
by
Martin_fr
[
Today
at 12:26:57 am]
Debian removes FPC/Lazaru...
by
kupferstecher
[February 13, 2026, 10:29:53 pm]
AVRPascal – free code edi...
by
ackarwow
[February 13, 2026, 10:08:59 pm]
Select rectangle of the i...
by
backprop
[February 13, 2026, 08:16:27 pm]
How to determine the unkn...
by
LV
[February 13, 2026, 07:37:32 pm]
how to enable multihelper...
by
mas steindorff
[February 13, 2026, 07:03:20 pm]
Lazarus/FreePascal Bug
by
Bart
[February 13, 2026, 06:27:28 pm]
Questions from a Windows ...
by
CM630
[February 13, 2026, 06:15:33 pm]
Duplicated icon in the Wi...
by
w click
[February 13, 2026, 05:47:49 pm]
AdvancedHTTPServer: A Go-...
by
LeP
[February 13, 2026, 03:01:15 pm]
Status of FPC 3.4.0 or FP...
by
gidesa
[February 13, 2026, 12:35:41 pm]
Notetask 1.1.1 - Free cro...
by
AlexanderT
[February 13, 2026, 12:00:08 pm]
Bee Hive solitaire
by
TBMan
[February 13, 2026, 03:22:09 am]
AI Created Music
by
Tony Stone
[February 13, 2026, 03:02:08 am]
Send form to true left an...
by
mas steindorff
[February 13, 2026, 02:39:34 am]
Help needed compiling
by
jamie
[February 13, 2026, 02:33:02 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Correct way to merge multiple TBytes (Read 1971 times)
FlameFox
Newbie
Posts: 3
Correct way to merge multiple TBytes
«
on:
April 28, 2021, 05:25:43 pm »
What is the correct way to merge multiple TBytes ?
Logged
lucamar
Hero Member
Posts: 4217
Re: Correct way to merge multiple TBytes
«
Reply #1 on:
April 28, 2021, 07:04:32 pm »
Assuming you mean
SysUtils.TBytes
, as with any other array: depends on what you want the end result to be. A simple concatenation can be done e.g. with
Move()
:
Code: Pascal
[Select]
[+]
[-]
function
JoinBytes
(
const
a
,
b
:
TBytes
)
:
TBytes
;
begin
SetLength
(
Result
,
Length
(
a
)
+
Length
(
b
)
;
if
Length
(
Result
)
>
0
then
begin
if
Length
(
a
)
>
0
then
Move
(
a
[
0
]
,
Result
[
0
]
,
Length
(
a
)
)
;
if
Length
(
b
)
>
0
then
Move
(
b
[
0
]
,
Result
[
Length
(
a
)
]
,
Length
(
b
)
)
;
end
;
end
;
Logged
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.
FlameFox
Newbie
Posts: 3
Re: Correct way to merge multiple TBytes
«
Reply #2 on:
April 28, 2021, 08:52:18 pm »
Thanks!
Logged
engkin
Hero Member
Posts: 3112
Re: Correct way to merge multiple TBytes
«
Reply #3 on:
April 28, 2021, 10:45:19 pm »
Use
Concat
:
Code: Pascal
[Select]
[+]
[-]
var
a
,
b
,
c
,
d
,
Res
:
TBytes
;
...
begin
...
Res
:
=
Concat
(
a
,
b
,
c
,
d
)
;
Logged
wp
Hero Member
Posts: 13353
Re: Correct way to merge multiple TBytes
«
Reply #4 on:
April 28, 2021, 10:54:59 pm »
Or, in fpc trunk, you can even use the '+' operator:
Code: Pascal
[Select]
[+]
[-]
program
Project1
;
{$mode delphi}
uses
SysUtils
;
var
a
,
b
,
c
:
TBytes
;
i
:
byte
;
begin
a
:
=
[
1
,
2
,
3
]
;
b
:
=
[
5
,
6
,
7
,
8
,
9
]
;
c
:
=
a
+
b
;
for
i
in
c
do
WriteLn
(
i
)
;
ReadLn
;
end
.
Logged
PascalDragon
Hero Member
Posts: 6321
Compiler Developer
Re: Correct way to merge multiple TBytes
«
Reply #5 on:
April 29, 2021, 09:30:05 am »
Quote from: wp on April 28, 2021, 10:54:59 pm
Or, in fpc trunk, you can even use the '+' operator:
FPC 3.2.0 is enough.
Though in non-Delphi modes one needs to use
$Modeswitch ArrayOperators
(the
Concat
, which was added at the same time, does not require that).
Logged
FlameFox
Newbie
Posts: 3
Re: Correct way to merge multiple TBytes
«
Reply #6 on:
April 30, 2021, 08:12:00 pm »
Thanks to everybody!
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
Correct way to merge multiple TBytes
TinyPortal
© 2005-2018