Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all 1440 articles
Browse latest View live

Thread around DCEF3 leaking memory, but DCEF4 doesn’t taught me to look at madExcept for memory leak checking too

$
0
0

This thread about [WayBack] DCEF3 memory leak in Delphi XE2  – Alberto Paganini – Google+ taught me that madExcept has a much more elaborate memory leak checking than FastMM4: it checks any Windows memory heap allocation, handle leaks, etc, not just the Delphi code induced memory allocations.

Thanks David Heffernan for commenting this part:

The madExcept leak tracking tools are much more comprehensive than those of FastMM because have much greater coverage. FastMM’s leak tracking tools are great, but only track native Delphi allocations. With the madExcept tooling you get all heap allocations (including non-native ones), handle leaks etc.

That is not to belittle the FastMM tooling at all…

Time to again look at [WayBack] madshi.net – madExcept description

–jeroen


Design Patterns & Refactoring

$
0
0

Design Patterns and Refactoring articles and guides. Design Patterns video tutorials for newbies. Simple descriptions and full source code examples in Java, C++, C#, PHP and Delphi.

Source: [WayBackDesign Patterns & Refactoring.

And indeed a lot of examples in Delphi too; few sites have that: Delphi site:sourcemaking.com.

–jeroen

Via: [WayBack] I stumbled upon this yesterday, very informative, accessible and also with Delphi examples – among other languages. – Steffen Nyeland – Google+

Delphi RTTI Context limitation: not thread safe for method RTTI

Tweaked TStringBuilder in FastCode is now 2x faster than the stock…

delphi – How to hide the inherited TObject constructor while the class has overloaded ones? – Stack Overflow

Namespaces in Delphi – Stack Overflow

$
0
0

Blast from the past, but still relevant: [WayBackNamespaces in Delphi – Stack Overflow:

Q

Are there any practical benefits in using long unit file names like MyLib.MyUtils.pas or it is just a kind of unit name prefix?

A

Namespaces, like all identifiers, are meant to organize.

So using them, only benefits if your project gets organized in a better way. This is highly subjective matter (there have been ‘wars’ on even the most simple naming conventions!), so impossible to really answer.

[WayBack] Here is some documentation on how namespaces work in Delphi.

Note that ‘true’ namespaces (where more than one generic DLL can contribute to the same namespace; this is how namespaces function in the .NET world) are not possible in Delphi: you could go the BPL way, but that is not the same as a ‘generic DLL’. This is not a limitation of Delphi itself, but the way that native DLLs in Windows ‘work’.

–jeroen

Laptop fan profiling, and debugging them – related to Profiling | CommitStrip

$
0
0

A while back, I posted the “profiling” CommitStrip on[WayBack] Profiling – Jeroen Wiert Pluimers – Google+. Boy how did I not know that within a week, I bumped into a “laptop fan profiling” artefact.

A coworker noticed, that when starting a thread based equivalent of [WayBack] TTimer Class (which cannot be used in services as it depends on the VCL), then sometimes the laptop fans would spin up.

What basically happened was that for certain combinations of Enabled and Interval the Execute would loop burning 100% of one CPU core.

With 3 or more – sometimes 2 – of these threads active on a 4+4 core (4 are hyper-threaded), the processor fan would start to spin like madness.

Finding the solution was somewhat easy too:

  • Process Explorer would show the thread IDs burning the most CPU cycles
  • Delphi shows the Thread IDs in the Thread Status pane (if they are named, the ID is at the end of the name in parenthesis)
  • At around Delphi 2010, you can Freeze or Thaw threads. This allows you to debug only a single thread by freezing all others.

Focussing on one thread, allowed a close inspection of the loop, quickly finding the actual cause and repairing it.

TTimer Thread

A similar and better class is at [WayBack] multithreading – TTimerThread – Threaded timer class – Code Review Stack Exchange, based on [WayBack] timer – Using VCL TTimer in Delphi console application – Stack Overflow.

[WayBack] Profiling | CommitStrip

 

 

delphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow

$
0
0

Blast from the past: [WayBackdelphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow

Q

Why variables are declared as TStrings and created as TStringList?

A

Because that way you could put another TStrings descendant in the SL variable (I’d probably call that Strings, not SL).

In your case, that is moot, since the logic around SL contains the creation of a TStringList and no external assignment or parameter parsing.

But if you ever split the logic away from the assignment, then you could benefit from using any TStrings descendant.

For instance, a TMemoy.LinesTListBox.ItemsTComboBox.Items, etc.
From the outside it looks like they are TStrings, but internally they do not use a TStringList but their own descendant.

A few examples of classes that descend from TStrings:

source\DUnit\Contrib\DUnitWizard\Source\DelphiExperts\Common\XP_OTAEditorUtils.pas:
     TXPEditorStrings = class(TStrings)
source\fmx\FMX.ListBox.pas:
       TListBoxStrings = class(TStrings)
source\fmx\FMX.Memo.pas:
     TMemoLines = class(TStrings)
source\rtl\common\System.Classes.pas:
     TStringList = class(TStrings)
source\vcl\Vcl.ComCtrls.pas:
     TTabStrings = class(TStrings)
     TTreeStrings = class(TStrings)
     TRichEditStrings = class(TStrings)
source\vcl\Vcl.ExtCtrls.pas:
     TPageAccess = class(TStrings)
     THeaderStrings = class(TStrings)
source\vcl\Vcl.Grids.pas:
     TStringGridStrings = class(TStrings)
     TStringSparseList = class(TStrings)
source\vcl\Vcl.Outline.pas:
     TOutlineStrings = class(TStrings)
source\vcl\Vcl.StdCtrls.pas:
     TCustomComboBoxStrings = class(TStrings)
     TMemoStrings = class(TStrings)
     TListBoxStrings = class(TStrings)
source\vcl\Vcl.TabNotBk.pas:
     TTabPageAccess = class(TStrings)

–jeroen


Delphi dcc32 error E2506 Method of parameterized type declared in interface section must not use local symbol ‘TExceptionThread`1’

$
0
0

Need to check on this compiler error that you can solve by moving the generic class TExceptionThread<T> from the implementation section of a unit to the interface section.

[dcc32 Error] Test.ExceptionLogging.pas(246): E2506 Method of parameterized type declared in interface section must not use local symbol 'TExceptionThread`1'

My gut feeling is that that this either has to do with RTTI generation, or is a limitation of the compiler.

I need to trim that one done since it does not match any of these:

–jeroen

Sometimes a race condition is in just two lines of code

$
0
0

A race condition can be this small:

if Assigned(Setting.OnChanged) then
  Setting.OnChanged(Setting);

If in between these lines, the value of Setting.OnChanged becomes nil, then you have an access violation.

It is a very slim, but real chance.

–jeroen

It’s a blong, blong, blong road…: ‘What if?’ scenario analysis in the CPU window

$
0
0

Patching code at debug-time: [WayBackIt’s a blong, blong, blong road…: ‘What if?’ scenario analysis in the CPU window.

Remember:

  • There are dragons
  • Patching too many bytes will kill a kitten and likely your application.
  • Bytes in memory might not be what they seem, especially when having breakpoints (and the debugger frantically trying to set/remove $CC bytes for the INT 3 instruction)

I’ve done this for 20+ years and usually use the $90 byte (NOP instruction) though your experience may be different.

–jeroen

 

New in 10.2.2: Component icons – Community Blogs – Embarcadero Community

$
0
0

A well balanced post that shows what you can attain by thinking in advance and remembering backward compatibility: [WayBack] New in 10.2.2: Component icons – Community Blogs – Embarcadero Community

Larger icons can now be in PNG format (future IDE versions will use 128×128 for HiDPI screens) so older IDE versions do not get confused. Since newer IDE versions prefer PNG over BMP icons, backward compatibility is easier.

Via: [WayBack] A look at the new component icons in 10.2.2.  – David Millington – Google+

–jeroen

Delphi XE2: IDE out of memory problem? Check the library path length

$
0
0

Curious, but somehow shortening the library path solved the problem Alberto had: [WayBack] Hello Everybody, I have an application developed in XE2 (Hot Fix 2 + IDE Fix Pack installed) that has started giving me the “out of memory” error message… – Alberto Paganini – Google+:

Alberto Paganini

It turned out the length of the library path was the culprit of the IDE out of memory error messages.
I have reduced the length of the library path and the error messages have reduced dramatically.
There are still a few out of memory messages tho.

–jeroen

GitHub – Purik/AIO: Coroutine-based multithreading library for Delphi

$
0
0

On my list of things to try: [WayBack] GitHub – Purik/AIO: Coroutine-based multithreading library for Delphi which are similar to what golang does.

Coroutine-based multithreading library for Delphi. Contribute to Purik/AIO development by creating an account on GitHub.

Via [WayBack] What you think about coroutine-based multithreading concurrency in Delphi like GoLang https://github.com/Purik/AIO Probably evolution paths, actuality… – Павел Миненков – Google+

–jeroen

More on new .NET path handling – Jeremy Kuhne’s Blog

$
0
0

When it was at the age natural people are allowed to drive in the USA, the .NET framework behaved far less brain dead handling various (especially long or strange) paths: [WayBackMore on new .NET path handling – Jeremy Kuhne’s Blog.

Path handling has frustrated me in many development environments, so I wonder if ones that are beyond the (USA) legal age of drinking follow.

–jeroen

via: [WayBack] Some time ago, the .net developers finally saw sense and removed path normalization and long path limit code in System.IO… Does anybody know if Embarcadero have come to their senses… – David Heffernan – Google+


Using PE Flags in Delphi – twm’s blog

$
0
0

NativeInt / NativeUInt type in various Delphi versions – twm’s blog

$
0
0

Reminder to Self (and note that Delphi <= 2007 does not reference NativeInt/NativeUInt in System.pas): [WayBack] NativeInt / NativeUInt type in various Delphi versions – twm’s blog

Just in case you are maintaining Delphi code for several older versions of Delphi: Be aware that the declarations of NativeInt and NativeUInt are wrong in some of them.

Delphi version SizeOf(Native(U)Int) Win32 SizeOf(Native(U)Int) Win64
1 to 6 not available not available
7 to 2007
8 ← this is wrong
not available
2009 to XE 4 not available
XE2 to XE8 4 8
10.x 4 8

Relevant GExperts commit: [WayBack] GExperts / Code / Commit [r2399]

Via  [WayBack] Just in case you are maintaining Delphi code for several older versions of Delphi: Be aware that the declarations of NativeInt and NativeUInt are wrong … – Thomas Mueller (dummzeuch) – Google+

–jeroen

QualityCentral 56524: tanh function from Delphi 7 till Delphi XE was buggy; XE2 fixed it

$
0
0

In case you maintain code in older versions of Delphi, be aware that the function tanh was broken starting in Delphi 7 and only got fixed in Delphi XE2: QualityCentral QualityCentral 56524: tanh function from Delphi 7 till Delphi XE was buggy; XE2 fixed it.

For big inputs, it would just fail, instead of returning 1.

The reason is that in the buggy versions, tanh got replaced from an old working version into a simple sinh/cosh, which mathematically is correct, but if your numeric data type has limited accuracy, you need to account for the boundaries where the result fits, but intermediates do not.

the [WayBack] Math.Tanh Function implements the hyperbolic tangent, for which you can find the definition at Hyperbolic function – Wikipedia: Definitions.

By now it is implemented for all floating point types the same way (only the parameter type changes in each implementation)

function Tanh(const X: Extended): Extended; overload;
const
  MaxTanhDomain = 23;
  C1of3 = 1/3;
  CBorder = 1.8145860519450699870567321328132e-5; // 2 ^(-63 / 4)
  CLn2Div2 = 0.34657359027997265470861606072909; // Ln2 / 2
var
  y, z: Extended;
begin
  FClearExcept;
  case TExtendedRec(X).SpecialType of
    fsPositive,
    fsNegative:
      begin
        z := X;
        if X < 0 then z := -z;
        if (z > MaxTanhDomain) then
          Result := 1.0
        else if (z < CBorder) then
          Result := z  - z * z * z * c1of3
        else if (z < CLn2Div2) then
        begin
          y := ExpMinus1(2*z);
          Result := y / (2 + y);
        end
        else
        begin
          y := Exp(2*z);
          Result := 1 - (2/(y + 1));
        end;
        if X < 0 then Result := -Result;
      end;
    else
      Result := X;
  end;
  FCheckExcept;
end;

–jeroen

Delphi, SHA-3 and streaming

TestInsight provides a local JSON web-server from the IDE for the test-runner to communicate from

$
0
0

Stefan Glienke shared the TestInsight default JSON web-server location with me through chat; I like it!

Some endpoints:

The mechanism for accessing this JSON server are implemented in the TestInsight.Client.pas

You can find the endpoint base URL in TestInsightSettings.ini which by default looks like this:

[Config]
BaseUrl=http://WIN10-DELPHI:8102

–jeroen

Viewing all 1440 articles
Browse latest View live