TBytesStream

I guess that you all already worked with a TBytesStream. It is derived from a TMemoryStream and offers direct access to the underlying TBytes:

  
...
TBytesStream = class(TMemoryStream)
  private
  ...
    property Bytes: TBytes read FBytes;
  end;
...

So far so good, the problem is that a TMemoryStream allocates more memory than the current Size. The reason is that not necessary to realloc memory for every write operation. You can see this in the Realloc method

...
const
  MemoryDelta = $2000; { Must be a power of 2 }
...
function TBytesStream.Realloc(var NewCapacity: Longint): Pointer;
begin
  if (NewCapacity > 0) and (NewCapacity <> FSize) then
    NewCapacity := (NewCapacity + (MemoryDelta - 1)) and not (MemoryDelta - 1);
  Result := Pointer(FBytes);
  if NewCapacity <> FCapacity then
  begin
    SetLength(FBytes, NewCapacity);
    Result := Pointer(FBytes);
  ...
  end;
end;
...

As you can see the NewCapacity is larger than the Size of the Stream. If you look deeper at the code you can see that the NewCapacity is of power of 2.

But anyway, the point is that the property Bytes can include more bytes than the Size of the Stream. That’s why you must be very careful if you want to access directly to the Bytes property.

In order to avoid any issues I created a record helper for TBytes with the property BytesReal that includes the used bytes:

...
  TBytesStreamHelper = class helper for TBytesStream
  strict private
    function get_BytesReal: TBytes; 
  public
    property BytesReal: TBytes read get_BytesReal;
  end;
...
function TBytesStreamHelper.get_BytesReal: TBytes;
begin
  if Capacity > Size then
    Result := Copy(Bytes, 0, Size)
  else
    Result := Bytes;
end;
...

If you like than add the TBytesStreamHelper to your project and use the new property BytesReal.
 

Posted in Delphi, RAD Studio 10.4 Sydney, Tips and Tricks, Uncategorized | Comments Off on TBytesStream

Improved the Demo for Web Application

Today we updated our TMS Web Core demo application. If you are interested to see it, don’t hesitate to contact us.

Posted in Uncategorized | Comments Off on Improved the Demo for Web Application

Hybrid Web applications

This week TMS held a webinar about the next release 1.8 of TMS Web Core which includes the next version of Miletus.

Miletus is a framework that allows you to create HTML and CSS based web applications for the desktop. It can be compared with the Electron framework but has several advantages, particularly the non-dependency of Electron and the smaller size of the binaries. In addition to the existing Miletus version which only works for Win32, the next release will support Win32, Win64, macOS64 and Linux64.

And all this can be done in the great RAD Studio IDE!

But I went a step further. I created a Delphi project, that is a so called Hybrid application. This means that it supports a regular Web application, PWA, Electron and Miletus. In order to repeat this fact again, this kind of Delphi project allows you to run your application everywhere. On smartphones, tablets, Windows desktop, Linux desktop and macOS including the new M1 architecture. I would say this is the most flexible project type I have ever seen.

If you would like to learn more about the details you are welcome to contact me and ask for commercial consultancy.

Posted in CSS, HTML, RAD Studio 10.4 Sydney, TMS Software, TMS Web Core, Uncategorized | Comments Off on Hybrid Web applications

Demo for Web Application

Today we created a demo for a Web Application which is responsive, supports light and dark mode and where the language can be selected. We have written this application with HTML, CSS, JavaScript and TMS Web Core.

For everybody who is interested and would like to write an amazing Web Application with Object Pascal, please contact us and we will provide further details.

Posted in CSS, Delphi, HTML, JavaScript, TMS Web Core, Uncategorized | Comments Off on Demo for Web Application

PowerPDF

I fixed an issue in the PowerPDF components. The problem was that the C++Builder IDE didn’t show the installed components.

For all who are waiting for such a fix, please be patient since I’m doing this in my spare time. Most of the time I’m involved in commercial projects.

Posted in C++-Builder, Third Party Components, TurboPack, Uncategorized | Comments Off on PowerPDF

MustangPeak

This week I added some minor changes to the MustangPeak components. It is some time ago that I worked on these components, but this week a customer needed these changes. I hope that someone can profit from this work.

Posted in C++-Builder, Delphi, RAD Studio 10.4 Sydney, Third Party Components, TurboPack, Uncategorized | Comments Off on MustangPeak

VirtualTreeView

Today I merged the VirtualTreeView from TurboPack with the version from GitHub. As soon as EMBT has updated GetIt, you can download this library directly from inside the RAD Studio IDE.

Posted in C++-Builder, Delphi, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio 10.3 Rio, RAD Studio 10.4 Sydney, Third Party Components, TurboPack, Uncategorized | Comments Off on VirtualTreeView

Videos about Miletus

Today TMS Software announced the version 1.7 of TMS Web Core. One of the new features is the Miletus framework, that allows you to write desktop applications with JavaScript, HTML and CSS. But I do not want to spoiler too many details. Simply look at our videos at tmssoftwareTV, here and here.

Posted in CSS, Delphi, HTML, JavaScript, TMS Software, TMS Web Core | Comments Off on Videos about Miletus

Encoding of .pas files part 2

In my last post I explained that it is a good strategy to encode .pas files in UTF8. From RAD Studio 10.4 you can set under “Tools/Options/User Interface/Editor” the “Default file encoding” to UTF8. In older versions of RAD Studio like e.g. Tokyo (version 19.0) you can set the hidden registry key

HKEY_CURRENT_USER\Software\Embarcadero\BDS\19.0\Editor]
“DefaultFileFilter”=”Borland.FileFilter.UTF8ToUTF8”.

Posted in RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio 10.3 Rio, RAD Studio 10.4 Sydney, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Tips and Tricks, Uncategorized | Comments Off on Encoding of .pas files part 2

Encoding of .pas files

This week I would like to talk about the encoding of .pas files. Normally they are ANSI encoded which is no problem since all Delphi statements are ASCII encoded. But the exception are comments. Many developers overlook this issue, but they write comments in their native language and then it can happen that their are non-ASCII chars like German umlauts. In this case it is necessary to encode the source files in UTF8. Be careful, look at your comments or simply always encode the sources in UTF8.

Posted in C++-Builder, Delphi, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio 10.3 Rio, RAD Studio 10.4 Sydney, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Tips and Tricks, Uncategorized | Comments Off on Encoding of .pas files