Quantcast
Channel: Planet Object Pascal
Viewing all 1725 articles
Browse latest View live

TPersistent: An Interface You Can Count On

$
0
0

Using refcounted interfaces can be difficult, especially when introducing them into legacy code.  Unfortunately, interfacing is key to breaking dependencies and making code more testable.

There are only two approaches I have seen to debugging refcount issues:

1) Create a descendant of TInterfacedObject and override the _AddRef/_Release to log class information and the current refcount.  You could also use copy/paste inheritance (although I do not recommend making a habit of it), and change the implementations.

2) Create your own Interface like I did that exposes the RefCount and ClassName properties and make it the root ancestor for all interfaces used in your project instead of IInterface.  Then you can see the implementing class, and it’s refcount in the debugger, and log it as well if you see fit.  I wonder why TInterfacedObject doesn’t have such properties to begin with…

Here is an interface you can count on ;-) :


/// Interface that should be used as the ancestor
/// for all interfaces so we can see the refcount
/// when debugging without potentially altering it
/// by calling _AddRef/_Release.

IRefCountInterface = interface(IInterface)
['{95A446C2-A9E4-4355-8DDD-5B6854EBDBD0}']
function GetRefCount :Integer;
function GetClassName: string;
property RefCount :integer read GetRefCount;
property ClassName :string read GetClassName;
end;


Firebird News: DWScript now has database support dwsDatabase

$
0
0
DWScript now has database support classes built-in, these are based on a thin, interface-based layer, and can be used Delphi-side as well to get automatic memory management for simple DB access. Here is a simple example for webservice  

Firebird News: FBScanner 3.6.1 is released

$
0
0
New version of FBScanner (3.6.1) is released. FBScanner is an unique tool to trace and audit Firebird (1.0 – 2.5) and InterBase (4.0 – XE3) SQL traffic (connections, transactions, queries), it’s very efficient tool for performance optimization and SQL bug tracking. FBScanner works like a proxy, and enables transparent data capture and analysis: FBScanner can […]

Delphi Bistro: New Year resolution for you: get a new job as a Delphi developer!

$
0
0

If  you want to come work for the coolest company that writes software using your favorite language, then now is the time to send me  your resume! Email it to afletcher at wideorbit dot com.

If you have a lot of Delphi experience, as well as SQL experience, send me your resume (afletcher at wideorbit dot com). You owe it to yourself to take a chance at working for a great company that has a team of great people that love Delphi as much as you do!

C’mon, you owe it to yourself,  take the first step and Send me your resume (afletcher at wideorbit dot com) and I’ll personally deliver it to the right person.

Positions are open in Lynnwood, WA (Seattle area) and San Francisco, CA. Must be able to work in the US.

The Podcast at Delphi.org: Buffering Sensor Data

$
0
0

Working with sensors on devices can often lead to large amounts of data coming to you really fast. For example the TMotionSensor’s OnDataChange event fires 100 times a second on my Nexus 5. When I was building my level app for Google Glass the level bar was bouncing all over the place because of the sensitivity and sample rate.

My first thought was to only take every 10th sample, but I wasn’t happy with that either because the specific sample it pulled could be the one when there was a jitter.

Example: 1,2,1,1,2,1,2,3,1,3,12,2,3,1

If I just looked at sample 1 and 11 then I would see a lot of movement, but in reality it was relatively stable most of the time.

What I ended up doing was buffering the data and taking an average. I just created a generic TList of the appropriate type, and during the OnDataChange event I would simply store the sample data. When it came time to update the display I took an average sample, which I found gave a much smoother and more representational display.

Although it was still possible the line could jump erratically if I really moved a lot. So I decided to use an animation for the movement. This keeps the line movement smooth, even if there is a lot of movement (it interpolates the positions between the current line position and the new position). I used a TFloatAnimation and set the StartFromCurrent property to true.

When the animation is finished I set the StopValue to the the average of the values, then enable again. It is important to always clear the sample values after taking an average. Otherwise the movement will continue to get slower and slower as it becomes more and more stable (averaging a large enough sample of numbers results in a smaller range of results.)

I was really pleased with how smooth things looked with a 0.1 second duration on the animation. With 100 samples a second, this translates into each animation covering the average of 10 samples. The built in animations made it really easy, and the final display looked great.

I’ll include the source code with the downloads from the Making the Connection: Programming Devices and Gadgets with RAD Studio webinar coming up next week!

RAD-in-Action Webinar Making the Connection: Programming Devices and Gadgets with RAD Studio Wednesday, January 22, 2014

The road to Delphi: VCL Styles Utils and Popup Menus Major Update

$
0
0

As you probably know the VCL Styles doesn’t support  Popup menus, this means if you apply any VCL Style  to your VCL Application  the popup menus will remain with the Windows native look and feel  (exists some workarounds for this like use a TPopupActionBar  as described here, but this only works partially, and doesn’t support the child menus of a TMainMenu) Since Sometime ago the VCL Styles Utils project can help you to overcome this limitation adding support for VCL Styled Popup Menus.

Now we just uploaded a major update to the VCL Styles Utils project. This new version fix all the issues reported via mail and the issue page related the PopUp menus like support for  the Break property, Checkboxes,  Radio Items,  Default items and so on.

Sample images

TMainMenu with VCL Styles

1

TMainMenu with VCL Styles and VCL Styles Utils

2

Popup Menu with VCL Styles

3

Popup Menu with VCL Styles and VCL Styles Utils

4

Right to left Popup Menu with VCL Styles

5

Right to left Popup Menu with VCL Styles and VCL Styles Utils

6

System Menu with VCL Styles

7

System Menu with VCL Styles and VCL Styles Utils

8

To add support for VCL Styled Popup Menus in your Application only you must add these units to your project Vcl.Styles.Utils.Menus, Vcl.Styles.Utils.SysStyleHook and Vcl.Styles.Utils.SysControls.

You can download sample application from here and the source of the Application is here.


The Podcast at Delphi.org: Maximized Side-by-Side Code Editing

$
0
0

Sometimes we forget some of the basics. Had a customer ask if you can maximize the code editor Window in RAD Studio and edit two files side-by-side. I’d heard someone talk about this a while ago, but I couldn’t remember the details.

There is an option in Tools / Options / Editor Options / Display that allows a code window to Zoom to full screen.

Zoom To Full Screen

Then right click in the code window you want full screen, bringing up the View Menu, and choose New WindowNew Edit Window

 

With Windows 7 or Windows 8, just drag this new code window to the left or right edge of the screen and it automatically gets tiled nicely.

Maximized RAD Studio Code Editor Side-by-Side

Delphi Haven: Loading the apps icon into a TImage on Android

$
0
0

Working with Delphi for Android, I wanted to load my app’s icon into a TImage. Here’s the code I came up with:

uses
  AndroidApi.JniBridge, AndroidApi.Jni.App, AndroidApi.Jni.GraphicsContentViewText,
  FMX.Helpers.Android, FMX.Surfaces;

function GetAppIcon(Dest: TBitmap): Boolean;
var
  Activity: JActivity;
  Drawable: JDrawable;
  Bitmap: JBitmap;
  Surface: TBitmapSurface;
begin
  Result := False;
  Activity := SharedActivity;
  Drawable := Activity.getPackageManager.getApplicationIcon(Activity.getApplicationInfo);
  Bitmap := TJBitmapDrawable.Wrap((Drawable as ILocalObject).GetObjectID).getBitmap;
  Surface := TBitmapSurface.Create;
  try
    if not JBitmapToSurface(Bitmap, Surface) then
      Exit;
    Dest.Assign(Surface);
  finally
    Surface.Free;
  end;
  Result := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  GetAppIcon(Image1.MultiResBitmap[0].Bitmap);
end;

The slightly awkward manner of casting from a JDrawable to a JBitmapDrawable in the middle is because Java type casts are not supported directly by the Delphi to Java bridge. As such, we have to get a handle to the raw Java object and re-wrap it to the desired derived class… but that’s too much of a faff all told, and the syntax will be familiar with anyone who has used the Delphi to Objective-C bridge before.



Delphi Code Monkey: The Best Programming Books on my Bookshelf. None are language specific.

$
0
0

I was one of the many people crying out for More Delphi Books, and I am glad to see that recently we have seen new books from Nick Hodges, and from others.  Today I'd like to cover the top five non-language-specific general books on programming that I think every developer should read.


1.  The Pragmatic Programmer - Andrew Hunt, David Thomas

This collection of snippets of advice is how I came to call myself a "Pragmatic" programmer.  I believe there are good principles in the "Agile" movement, but I hesitate to call myself "Agile".   I believe the practices in "Scrum" and "XP" can be done, and done well.  When I'm part of a team that takes those principles to heart and follows them, I'm happy to follow along too, when it works. But I don't take those monikers for myself, because I see "pragmatic" as the over-arching principle I follow. I do what works, and when it doesn't work, I change it up.  This book is chock full of fantastic advice. Some of the "get out there on the Internet and discover new stuff" sounds dated, as the last edition I have of this was updated around 2000, but the principles are timeless.   Incidentally my "change it up when it doesn't work" dictum is probably original to XP, and was borrowed by Scrum, and then by agile, so we're all cribbing from XP.  Nevertheless, of all the books I have read, there is no book that expresses more about how developers who do great work, and do it with reasonable efficiency work, in my opinion than this book.*



2. Clean Code - Robert C. Martin

Nobody, I mean nobody has written a book that cuts to the heart of modern professional Best Practices than Uncle Bob. Nobody.  Uncle Bob first hit my radar when he passionately and carefully expounded the principles of object oriented programming with the SOLID mnemonic. This book goes on to explain what it means to be a real software professional.  Yes, you have to unit test. But there's more.


3. Working Effectively with Legacy Code - Michael Feathers

How do I unit test that giant ball of mud that I can't rewrite?  This book answers that, and many other burning questions. I have not read any other book that gave me more hope that you can dig out of the holes of technical debt left for you to solve, than this book. Fine, now that you understand the benefits of cohesion and the single-responsibility-principle, the dangers of coupling, and the necessity of proving that your code works by writing code that proves the assertions you wish to believe about your code.  Now, how do you work with the code that you have right now, that does not now, and may not ever meet your ideals about Clean Code? This book can help.

4. The Mythical Man Month (and other essays) by Fred Brooks

No other book about the work that programmers do, the way we run software projects, and the sad blindness to historical lessons learned, has ever been written than this book.   It contains a series of essays, each as good as the last.  Fred Brooks is my mentor, my hero, and my model of a software engineer, a craftsperson, a pragmatic programmer, a technical communicator, and an innovator in computing.   A must read.


5. The Secrets of Consulting by Gerald M Weinberg

This is a book about giving and receiving advice.  It is not pointed out nearly enough how much of a senior developer, or architect, or team leader's role consists in giving and receiving advice. Whether it is to someone who is your boss, or to someone you are being paid only temporarily (as in the title, Consulting), you are going to be better off if you read this book, and understand the lessons inside it.   This book tells you how to give your advice in a way that will be listened to.   If you want to be an effective technical communicator you must know how to deal with people, not just with machines. This book is a must-read for that reason.

What are your favorite programming books that don't cover any language, library, or specific tool, but rather cover the practice of being a programmer?

______

* I should point out that I haven't read Extreme Programming Explained, by Kent Beck, but I hear a lot of people say the same thing about the XP book. I did read the Agile Software Development With Scrum book, and was underwhelmed.    I do, however, agree with all the practices it mentions, but I feel that Agile often becomes, as Fred Brooks would call it, a "Silver Bullet", something we hope will save us.



Firebird News: IBProvider 3.19. Changes in metadata schemas

$
0
0
Every year on January 18 we have a small celebration – IBProvider’s birthday. This year it turned 14. We thank all our users for using the provider in your projects. We promise that we will continue to improve IBProvider till it completely supersedes Firebird and Interbase Read more about the new features in Firebird and […]

Behind the connection: Delphi XE5 hotfix 4: reFInd updated

$
0
0
Embarcadero published hotfix #4 for Delphi XE5 and C++ Builder XE5. This hotfix is an update for the command line tool "reFInd". If you don't know reFInd, it is a tool to help migrating code to Delphi XE5. It is a kind of search and replace on files using Perl RegEx expressions. For example, you can migrate BDE toFireDAC. Documentation on reFInd can be found here. The hotfix is availabe for

Firebird News: Database .NET 10.3 released

$
0
0
Database .NET is an innovative, powerful and intuitive multiple database management tool. You can Browse objects, Design tables, Edit rows, Export data and Run queries with a consistent interface. What’s New (2014/01/20) Full support for Firebird database Updated to FirebirdSql.Data.FirebirdClient.dll 4.1.0 Support for Firebird 1.5.x Support for Firebird Trace Fixed date/time/timestamp dbtypes in Table Designer […]

Delphi Haven: Loading the app’s icon into a TImage on Windows

$
0
0

Last time I showed how to load the icon of an FMX for Android app into a TImage. In practice, a lot of the debugging of a Delphi mobile app is likely to be with a Win32 ‘mobile preview’ build though… in which case it would be useful to load the icon when running on Windows as well.

To do that, you need to first add a *.ico version to the project. This is done via Project Options: select the Application item on the left, then All configurations – 32 bit Windows platform from the combo box at the top. Probably stating the obvious, but the icon loaded here should be a .ico version of the .png files set up for Android.

Once done, the most direct equivalent of the Android code I presented previously would be to use the LoadIcon Windows API to load the icon, then GetIconInfo and so forth to get the bitmap bits to copy to a FMX bitmap. Easier is to use the VCL however – since Vcl.Graphics.pas doesn’t bring in anything else of the VCL, there’s little point in deliberately avoiding it. As such, here’s an expanded version of the code I presented last time with a VCL-based Windows implementation added:

unit AppIconLoader;

interface

uses
  System.SysUtils, System.Classes, FMX.Graphics;

function GetAppIcon(Dest: TBitmap): Boolean;

implementation

uses
  {$IF DEFINED(ANDROID)}
  AndroidApi.JniBridge, AndroidApi.Jni.App, AndroidApi.Jni.GraphicsContentViewText, FMX.Helpers.Android,
  {$ELSEIF DEFINED(MSWINDOWS)}
  Vcl.Graphics,
  {$ENDIF}
  FMX.Surfaces;

function GetAppIcon(Dest: FMX.Graphics.TBitmap): Boolean;
{$IF DEFINED(ANDROID)}
var
  Activity: JActivity;
  Drawable: JDrawable;
  Bitmap: JBitmap;
  Surface: TBitmapSurface;
begin
  Result := False;
  Activity := SharedActivity;
  Drawable := Activity.getPackageManager.getApplicationIcon(Activity.getApplicationInfo);
  Bitmap := TJBitmapDrawable.Wrap((Drawable as ILocalObject).GetObjectID).getBitmap;
  Surface := TBitmapSurface.Create;
  try
    if not JBitmapToSurface(Bitmap, Surface) then
      Exit;
    Dest.Assign(Surface);
  finally
    Surface.Free;
  end;
  Result := True;
end;
{$ELSEIF DEFINED(MSWINDOWS)}
var
  Icon: TIcon;
  Stream: TMemoryStream;
begin
  Result := False;
  Stream := nil;
  Icon := TIcon.Create;
  try
    Icon.LoadFromResourceName(HInstance, 'MAINICON');
    if Icon.Handle = 0 then Exit;
    Stream := TMemoryStream.Create;
    Icon.SaveToStream(Stream);
    Stream.Position := 0;
    Dest.LoadFromStream(Stream);
  finally
    Icon.Free;
    Stream.Free;
  end;
  Result := True;
end;
{$ELSE}
begin
  Result := False;
end;
{$ENDIF}

end.

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

I remember doing this in DOS ages ago (in the Turbo Pascal 5 era) for exactly the same reason: flash the keyboard LEDs to indicate some event was happening, but I’ve yet to find back the source code.

Here is how to do it in Windows using either C# or C: Faking num lock, caps lock and scroll lock leds – About My Code.

–jeroen

via: c# – Way to turn on keyboard’s caps-lock light without actually turning on caps-lock? – Stack Overflow.


Filed under: .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Development, Pascal, Software Development, Turbo Pascal

Delphi Haven: New site FMX Express

$
0
0

Seemingly come out of nowhere, a new site has appeared that collates and summarises pretty much everything that has been posted elsewhere about everyone’s favourite roasting primate. It’s called FMX Express, so if you’re working with FireMonkey, check it out:

http://www.fmxexpress.com/



Firebird News: Firebird Foreign Data Wrapper for PostgreSQL Release 0.1.5 is out

$
0
0
New version 0.1.5 is released in the unstable area and here is the ChangeLog: Add basic Firebird version detection to ensure that only functions available on the remote Firebird server are actually pushed down Push down functions COALESCE(), NULLIF() Only push down SUBSTRING() if 2nd and 3rd arguments are INTs Also fbsql is progressing (a command-line […]

Behind the connection: New blog about Delphi FireMonkey

$
0
0
There is a new blog talking mostly about Delphi FireMonkey on the mobile platform (iOS and Android). The blog also covers other topics, mostly related to FireMonkey and the various supported platforms. This new blog is named FMXexpress. Actually, this blog is collecting blog articles from everywhere, display a short abstract and redirect to the original blog article. This is a place to visit on

Firebird News: Lazarus Release Candidate 2 of 1.2

$
0
0
The Lazarus team would like to announce the second Release Candidate for the upcoming Version 1.2. Please try the New Firebird components TFBAdmin and TFBEventMonitor

Firebird News: Vote for Firebird as Database of the Year 2013 at LinuxQuestions

$
0
0
Vote for Firebird as Database of the Year 2013 at LinuxQuestions (must be registered user with at least one Linux related post) http://www.linuxquestions.org/questions/2013-linuxquestions-org-members-choice-awards-109/database-of-the-year-4175488206/ Spread the word on all forums and Firebird communities

Firebird News: Firebird Foreign Data Wrapper for PostgreSQL Release 0.1.6 is out

$
0
0
New version 0.1.6 is released in the unstable area and here is the ChangeLog: Push down bitwise operators << and >> (FB 2.1 and later) Push down two-argument form of SUBSTRING() Push down CONCAT() Push down POSITION() / STRPOS() Don’t check for mutable functions – we are explicitly whitelisting functions which can be pushed down (need […]
Viewing all 1725 articles
Browse latest View live