The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for the ‘Delphi’ Category

Enum values in their own namespaces/scopes: Scoped Enums (Delphi)

Posted by jpluimers on 2018/08/29

A while ago, I needed several enum types in the same unit with overlapping enumeration values.

Putting each in an encompassing type wasn’t possible and I didn’t want to put each in their own unit.

Luckily, Delphi 2009 introduced the “scoped enum” feature effectively promoting the enumeration type into a scope or namespace.

It is only available at the source code level, as – at least up until Delphi 10.1 Berlin – it is not part of the compiler settings in the project options (see screenshot below).

Since the below was hard to find combined with the word “namespace” I’ve quoted it in full (note an earlier version of the post had a typo here as it was copied from the Delphi 2009 documentation which had SCOPEDEUNMS wrong):

Type
Switch
Syntax
{$SCOPEDENUMS ON}, or {$SCOPEDENUMS OFF}
Default
{$SCOPEDENUMS OFF}
Scope
Local

Remarks

The $SCOPEDENUMS directive enables or disables the use of scoped enumerations in Delphi code. More specifically, $SCOPEDENUMS affects only definitions of new enumerations, and only controls the addition of the enumeration’s value symbols to the global scope.

In the {$SCOPEDENUMS ON} state, enumerations are scoped, and enum values are not added to the global scope. To specify a member of a scoped enum, you must include the type of the enum. For example:

type
  TFoo = (A, B, Foo);
  {$SCOPEDENUMS ON}
  TBar = (A, B, Bar);
  {$SCOPEDENUMS OFF}

begin
  WriteLn(Integer(Foo)); 
  WriteLn(Integer(A)); // TFoo.A
  WriteLn(Integer(TBar.B));
  WriteLn(Integer(TBar.Bar));
  WriteLn(Integer(Bar)); // Error
end;

Note that this is also valid:

 Writeln(Integer(TFoo.A));

Even though TFoo was not declared with $SCOPEDENUMS ON, the A value can still be explicitly resolved using the enumeration name.

Read the rest of this entry »

Posted in Delphi, Development, Software Development | 4 Comments »

Embarcadero community RSS links

Posted by jpluimers on 2018/08/28

As G+ refused to put this in a comment at [WayBack] Does anybody know whether the Embarcadero blogs have got individual RSS feeds? And what’s the URL of the RSS feed for all blogs? … – Thomas Mueller (dummzeuch) – Google+:

No RSS logo is visible for me on the blog pages, but inspecting the source reveals the 404 link below; deducting from that I got 200 results:

What doesn’t work for RSS (CC +Marco Cantù) as you get 404:

  • events
  • individual questions
  • individual blog posts

Failure examples:

–jeroen

Read the rest of this entry »

Posted in Delphi, Development, Software Development | 4 Comments »

Delphi: create or append to a TFileStream

Posted by jpluimers on 2018/08/23

It looks like the Delphi [WayBackTFileStream.Create does not have an overload that allows you to create or append. Luckily, [Archive.is] TFile.Open allows you to do this when passing the correct [Archive.isTFileMode enumeration value:

TempStream := TFile.Open(TempPath, TFileMode.fmOpenOrCreate, TFileAccess.faReadWrite, TFileShare.fsRead);

I still wonder why that never made it into a TFileStream.Create overload, or why these overloads fail to use enumerations or sets of modes.

–jeroen

Posted in Delphi, Development, Software Development | 6 Comments »

Is there a reason why third party component vendors still ship dfm in binary files …

Posted by jpluimers on 2018/08/23

I knew it was backward compatibility, but TeeChart author David Berneda knew exactly what version:

One old issue with the XE5 osx compiler, some forms in text format raised a “Bad file format” exception, fix was leave them binary

–jeroen

Source: [WayBackIs there a reason why third party component vendors still ship dfm in binary files? – Google+, Stefan Glienke

Posted in Delphi, Development, Software Development | Leave a Comment »

Property/event differences between Delphi forms and frames

Posted by jpluimers on 2018/08/22

From a while back, but still interesting especially because there some differences similar to base/inherited designer objects: [WayBackvcl – How to do bulk -transformation of form to frame- in Delphi? – Stack Overflow:

Observe the differences of a Form and a Frame in your project.

First the project.dpr source:

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit3 in 'Unit3.pas' {Frame3: TFrame};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Differences:

  1. Frame as a more elaborated comment to tell the IDE which designer it should use
  2. Form can be autocreate

Dfm files:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 348
  ClientWidth = 643
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
end

and

object Frame3: TFrame3
  Left = 0
  Top = 0
  Width = 320
  Height = 240
  TabOrder = 0
end

Frame does not have these properties:

  • Caption
  • ClientHeight
  • ClientWidth
  • Color
  • Font.Charset
  • Font.Color
  • Font.Height
  • Font.Name
  • Font.Style
  • OldCreateOrder
  • PixelsPerInch
  • TextHeight

Sidenote: Frame does not have these events:

  • OnCreate
  • OnDestroy

A Frame has not global variable like this:

var
  Form1: TForm1;

And a Frame descends from TFrame, whereas a form descends from TForm.

Note: with Frame/Form inheritence, your steps become a bit longer.

–jeroen

Some of these are similar to the differences you see here:

–jeroen

PS: Idea: make a wizard or conversion tool for this.

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

Reminder to self – check some of the Delphi bug reports to see of they are solved

Posted by jpluimers on 2018/08/22

Reminder to self: check the entries referenced in [WayBack] Judging from recent QP bug resolutions, current status of Delphi compiler is “Leaks all the way” or “Broken by design”. Take your pick… – Dalija Prasnikar – Google+

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi SOAP service: only publish WSDL in RELEASE mode

Posted by jpluimers on 2018/08/21

If you want to restrict the WSDL publishing so it only is published in DEBUG mode, then add a [WayBack] TWSDLHTMLPublish to your [WayBackTWebModule descendant, then add this in the [WayBack] OnCreate event handler of that TWebModule descendant:

// Enable/disable handling of "/wsdl*" requests during DEBUG/RELEASE mode. Enabling sends them via
//  Handled := WSDLHTMLPublish1.DispatchRequest(Sender, Request, Response);
{$ifdef DEBUG}
  WSDLHTMLPublish1.WebDispatch.Enabled := True;
{$endif DEBUG}
{$ifdef RELEASE}
  WSDLHTMLPublish1.WebDispatch.Enabled := False;
{$endif DEBUG}
end;

I have limited this because there are so many hard coded strings in the TWSDLHTMLPublish, see the thread by [WayBack] Marjan Venema at [WayBack] Hide WSDL document in SOAP app – delphi

–jeroen

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

For my research list: Delphi and ZeroMQ

Posted by jpluimers on 2018/08/21

Last year, ZeroMQ – of late Pieter Hintjens ancestry – got a decent support library for Delphi https://github.com/grijjy/DelphiZeroMQ.

While writing, there is a reasonable chance I need to do message queue work and ZeroMQ is excellent. I’ve done MQ already in other environments with various projects involving Wintel/iSeries, WebSphere MQ (now IBM MQ, formerly MQSeries), Oracle AQ and Microsofts MSMQ stacks so I’m anxious to see if and how this works out.

via:

–jeroen

https://wiert.me/2017/05/10/one-year-ago-im-writer-and-free-software-author-pieter-hintjens-and-im-dying-of-cancer-ask-me-anything-iama/

Posted in Delphi, Development, Software Development | 2 Comments »

Reading files that are locked by other references: c# – Notepad beats them all? – Stack Overflow

Posted by jpluimers on 2018/08/16

Cool feature borrowed from Notepad, which can read files locked by other references (for instance a process having the handle open): [WayBackc# – Notepad beats them all? – Stack Overflow.

The example from the answer is in .NET, but can be used in a native environment as well (Notepad is a native application).

Notepad reads files by first mapping them into memory, rather than using the “usual” file reading mechanisms presumably used by the other editors you tried. This method allows reading of files even if they have an exclusive range-based locks.

You can achieve the same in C# with something along the lines of:

using (var f = new FileStream(processIdPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var m = MemoryMappedFile.CreateFromFile(f, null, 0, MemoryMappedFileAccess.Read, null, HandleInheritability.None, true))
using (var s = m.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))
using (var r = new StreamReader(s))
{
    var l = r.ReadToEnd();
    Console.WriteLine(l);
}

Via: [WayBack] Maintaining Notepad is not a full-time job, but it’s not an empty job either – The Old New Thing

–jeroen

Posted in .NET, Delphi, Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »

Have NoMessageBoxes depend on a global boolean · Issue #58 · pleriche/FastMM4 · GitHub

Posted by jpluimers on 2018/08/16

Reminder to self: [WayBackHave NoMessageBoxes depend on a global boolean · Issue #58 · pleriche/FastMM4 · GitHub

–jeroen

Posted in Delphi, Development, FastMM, Software Development | Leave a Comment »