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

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

As I wrote before, I’m with the Delphi with haters camp, and this is why:

Using the with statement in Delphi makes your code less future proof.

The below code example is just one of many. I show it because I recently bumped into doing some long overdue code porting to Delphi XE3.

Since I’ve been bitten by using with a couple of times before, it didn’t take me long to find the cause.

Example code where FIConData is of type NOTIFYICONDATAW that used to compile fine:

    with FIconData do
    begin
      cbSize := SizeOf(FIconData);
      Wnd := Self.Handle;
      uID := $DEDB;
      uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      hIcon := Application.Icon.Handle;
      uCallbackMessage := WM_CAS400NTIcon;
      StrCopy(szTip, PChar(Caption));
    end;

Well, as of Compiler Version 20, it doesn’t compile any more.

The reason is that the _NOTIFYICONDATAW got changed, because the underlying Windows API NOTIFYICONDATA structure changed to accommodate new Windows Vista features.

But because of backward compatibiliy, you cannot pass the full new structure when you are running on Windows versions prior to Windows Vista.

Hence this piece of code to calculate the right structure size in the ShellApi unit as of Delphi 2009:

class function _NOTIFYICONDATAW.SizeOf: Integer; static;
begin
  if Win32MajorVersion >= 6 then
    // Size of complete structure
    Result := System.SizeOf(_NOTIFYICONDATAW)
  else
    // Platforms prior to Vista do not recognize the fields guidItem and hBalloonIcon
    Result := System.SizeOf(_NOTIFYICONDATAW) - System.SizeOf(TGUID) - System.SizeOf(Winapi.Windows.HICON);
end;

SizeOf is a perfectly good name for this, but it clashes when you use the with statement.

Three other SizeOf functions got added. This is the complete list of four:

  • Unit Windows:
    • class function tagNONCLIENTMETRICSA.SizeOf: Integer;
    • class function tagNONCLIENTMETRICSW.SizeOf: Integer;
  • Unit CommCtrl:
    • class function MCHITTESTINFO.SizeOf: Integer;
  • Unit ShellApi:
    • class function _NOTIFYICONDATAW.SizeOf: Integer; static;

You are tempted to rewrite the with like this:

    with FIconData do
    begin
{$if CompilerVersion >= 20}
      cbSize := SizeOf();
{$else}
      cbSize := SizeOf(FIconData);
{$ifend CompilerVersion >= 20}
      Wnd := Self.Handle;
      uID := $DEDB;
      uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
      hIcon := Application.Icon.Handle;
      uCallbackMessage := WM_CAS400NTIcon;
      StrCopy(szTip, PChar(Caption));
    end;

But you should in fact rewrite it like this, so you are sure from which entity each value comes:

{$if CompilerVersion >= 20}
    FIconData.cbSize := FIconData.SizeOf();
{$else}
    FIconData.cbSize := SizeOf(FIconData);
{$ifend CompilerVersion >= 20}
    FIconData.Wnd := Self.Handle;
    FIconData.uID := $DEDB;
    FIconData.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    FIconData.hIcon := Application.Icon.Handle;
    FIconData.uCallbackMessage := WM_CAS400NTIcon;
    StrCopy(FIconData.szTip, PChar(Caption));

–jeroen


Filed under: Delphi, Delphi 1, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Development, Software Development

The road to Delphi: Getting Processor Info using Object Pascal (Delphi / FPC) and the TSMBIOS

$
0
0

New_Core_I7 The SMBIOS expose the info about the installed processors in the table type 4. Check the next snippet that shows how obtain such data using the TSMBIOS (remember, if you are using FPC, you can use this library in Windows and Linux).

{$IFDEF FPC}{$mode objfpc}{$H+}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}

uses
  Classes,
  TypInfo,
  SysUtils,
  uSMBIOS;

function SetToString(Info: PTypeInfo; const Value): String;
var
  LTypeInfo  : PTypeInfo;
  LIntegerSet: TIntegerSet;
  I: Integer;

begin
  Result := '';

    Integer(LIntegerSet) := 0;
    case GetTypeData(Info)^.OrdType of
      otSByte, otUByte: Integer(LIntegerSet)  := Byte(Value);
      otSWord, otUWord: Integer(LIntegerSet)  := Word(Value);
      otSLong, otULong: Integer(LIntegerSet)  := Integer(Value);
    end;

  LTypeInfo  := GetTypeData(Info)^.CompType{$IFNDEF FPC}^{$ENDIF};
  for I := 0 to SizeOf(Integer) * 8 - 1 do
    if I in LIntegerSet then
    begin
      if Result <> '' then Result := Result + ',';
      Result := Result + GetEnumName(LTypeInfo, I);
    end;
end;


procedure GetProcessorInfo;
Var
  SMBios             : TSMBios;
  LProcessorInfo     : TProcessorInformation;
  LSRAMTypes         : TCacheSRAMTypes;
begin
  SMBios:=TSMBios.Create;
  try
      WriteLn('Processor Information');
      if SMBios.HasProcessorInfo then
      for LProcessorInfo in SMBios.ProcessorInfo do
      begin
        WriteLn('Manufacturer       '+LProcessorInfo.ProcessorManufacturerStr);
        WriteLn('Socket Designation '+LProcessorInfo.SocketDesignationStr);
        WriteLn('Type               '+LProcessorInfo.ProcessorTypeStr);
        WriteLn('Familiy            '+LProcessorInfo.ProcessorFamilyStr);
        WriteLn('Version            '+LProcessorInfo.ProcessorVersionStr);
        WriteLn(Format('Processor ID       %x',[LProcessorInfo.RAWProcessorInformation^.ProcessorID]));
        WriteLn(Format('Voltaje            %n',[LProcessorInfo.GetProcessorVoltaje]));
        WriteLn(Format('External Clock     %d  Mhz',[LProcessorInfo.RAWProcessorInformation^.ExternalClock]));
        WriteLn(Format('Maximum processor speed %d  Mhz',[LProcessorInfo.RAWProcessorInformation^.MaxSpeed]));
        WriteLn(Format('Current processor speed %d  Mhz',[LProcessorInfo.RAWProcessorInformation^.CurrentSpeed]));
        WriteLn('Processor Upgrade   '+LProcessorInfo.ProcessorUpgradeStr);
        WriteLn(Format('External Clock     %d  Mhz',[LProcessorInfo.RAWProcessorInformation^.ExternalClock]));

        if SMBios.SmbiosVersion>='2.3' then
        begin
          WriteLn('Serial Number      '+LProcessorInfo.SerialNumberStr);
          WriteLn('Asset Tag          '+LProcessorInfo.AssetTagStr);
          WriteLn('Part Number        '+LProcessorInfo.PartNumberStr);
          if SMBios.SmbiosVersion>='2.5' then
          begin
            WriteLn(Format('Core Count         %d',[LProcessorInfo.RAWProcessorInformation^.CoreCount]));
            WriteLn(Format('Cores Enabled      %d',[LProcessorInfo.RAWProcessorInformation^.CoreEnabled]));
            WriteLn(Format('Threads Count      %d',[LProcessorInfo.RAWProcessorInformation^.ThreadCount]));
            WriteLn(Format('Processor Characteristics %.4x',[LProcessorInfo.RAWProcessorInformation^.ProcessorCharacteristics]));
          end;
        end;
        Writeln;

        if (LProcessorInfo.RAWProcessorInformation^.L1CacheHandle>0) and (LProcessorInfo.L2Chache<>nil)  then
        begin
          WriteLn('L1 Cache Handle Info');
          WriteLn('--------------------');
          WriteLn('  Socket Designation    '+LProcessorInfo.L1Chache.SocketDesignationStr);
          WriteLn(Format('  Cache Configuration   %.4x',[LProcessorInfo.L1Chache.RAWCacheInformation^.CacheConfiguration]));
          WriteLn(Format('  Maximum Cache Size    %d Kb',[LProcessorInfo.L1Chache.GetMaximumCacheSize]));
          WriteLn(Format('  Installed Cache Size  %d Kb',[LProcessorInfo.L1Chache.GetInstalledCacheSize]));
          LSRAMTypes:=LProcessorInfo.L1Chache.GetSupportedSRAMType;
          WriteLn(Format('  Supported SRAM Type   [%s]',[SetToString(TypeInfo(TCacheSRAMTypes), LSRAMTypes)]));
          LSRAMTypes:=LProcessorInfo.L1Chache.GetCurrentSRAMType;
          WriteLn(Format('  Current SRAM Type     [%s]',[SetToString(TypeInfo(TCacheSRAMTypes), LSRAMTypes)]));

          WriteLn(Format('  Error Correction Type %s',[ErrorCorrectionTypeStr[LProcessorInfo.L1Chache.GetErrorCorrectionType]]));
          WriteLn(Format('  System Cache Type     %s',[SystemCacheTypeStr[LProcessorInfo.L1Chache.GetSystemCacheType]]));
          WriteLn(Format('  Associativity         %s',[LProcessorInfo.L1Chache.AssociativityStr]));
        end;

        if (LProcessorInfo.RAWProcessorInformation^.L2CacheHandle>0)  and (LProcessorInfo.L2Chache<>nil)  then
        begin
          WriteLn('L2 Cache Handle Info');
          WriteLn('--------------------');
          WriteLn('  Socket Designation    '+LProcessorInfo.L2Chache.SocketDesignationStr);
          WriteLn(Format('  Cache Configuration   %.4x',[LProcessorInfo.L2Chache.RAWCacheInformation^.CacheConfiguration]));
          WriteLn(Format('  Maximum Cache Size    %d Kb',[LProcessorInfo.L2Chache.GetMaximumCacheSize]));
          WriteLn(Format('  Installed Cache Size  %d Kb',[LProcessorInfo.L2Chache.GetInstalledCacheSize]));
          LSRAMTypes:=LProcessorInfo.L2Chache.GetSupportedSRAMType;
          WriteLn(Format('  Supported SRAM Type   [%s]',[SetToString(TypeInfo(TCacheSRAMTypes), LSRAMTypes)]));
          LSRAMTypes:=LProcessorInfo.L2Chache.GetCurrentSRAMType;
          WriteLn(Format('  Current SRAM Type     [%s]',[SetToString(TypeInfo(TCacheSRAMTypes), LSRAMTypes)]));

          WriteLn(Format('  Error Correction Type %s',[ErrorCorrectionTypeStr[LProcessorInfo.L2Chache.GetErrorCorrectionType]]));
          WriteLn(Format('  System Cache Type     %s',[SystemCacheTypeStr[LProcessorInfo.L2Chache.GetSystemCacheType]]));
          WriteLn(Format('  Associativity         %s',[LProcessorInfo.L2Chache.AssociativityStr]));
        end;

        if (LProcessorInfo.RAWProcessorInformation^.L3CacheHandle>0) and (LProcessorInfo.L3Chache<>nil) then
        begin
          WriteLn('L3 Cache Handle Info');
          WriteLn('--------------------');
          WriteLn('  Socket Designation    '+LProcessorInfo.L3Chache.SocketDesignationStr);
          WriteLn(Format('  Cache Configuration   %.4x',[LProcessorInfo.L3Chache.RAWCacheInformation^.CacheConfiguration]));
          WriteLn(Format('  Maximum Cache Size    %d Kb',[LProcessorInfo.L3Chache.GetMaximumCacheSize]));
          WriteLn(Format('  Installed Cache Size  %d Kb',[LProcessorInfo.L3Chache.GetInstalledCacheSize]));
          LSRAMTypes:=LProcessorInfo.L3Chache.GetSupportedSRAMType;
          WriteLn(Format('  Supported SRAM Type   [%s]',[SetToString(TypeInfo(TCacheSRAMTypes), LSRAMTypes)]));
          LSRAMTypes:=LProcessorInfo.L3Chache.GetCurrentSRAMType;
          WriteLn(Format('  Current SRAM Type     [%s]',[SetToString(TypeInfo(TCacheSRAMTypes), LSRAMTypes)]));

          WriteLn(Format('  Error Correction Type %s',[ErrorCorrectionTypeStr[LProcessorInfo.L3Chache.GetErrorCorrectionType]]));
          WriteLn(Format('  System Cache Type     %s',[SystemCacheTypeStr[LProcessorInfo.L3Chache.GetSystemCacheType]]));
          WriteLn(Format('  Associativity         %s',[LProcessorInfo.L3Chache.AssociativityStr]));
        end;

        Readln;
      end
      else
      Writeln('No Processor Info was found');
  finally
   SMBios.Free;
  end;
end;        

ProcessorInfo2


Daniel Magin's Logfile: Delphi for iOS How to write a GPS Application

$
0
0

New Video about Delphi for iOS:

Here you can see how easy to write with Delphi for iOS a GPS Application:

have fun and enjoy for the Delphi iOS release :-)

Daniel Magin's Logfile: 20% Promo Delphi Enterprise and RAD Studio

$
0
0

This week is also one of the best times to get Delphi or a Delphi upgrade, because there is an "early bird" 20% off promotion running on Delphi Enterprise and RADStudio editions when purchased with an update subscription (aka maintenance or software assurance). These are the editions that are planned to include iOS when it’s available. And with the RADStudio mobile roadmap and more platforms and frequent updates and upgrades on the horizon, this is certainly way I would recommend purchasing Delphi or RADStudio today. This particular promo is ending in just a few days on March 31. Getting Delphi or RADStudio today from an Embarcadero partner or eShop with an update subscription not only gets you 12mo of updates and major upgrades, but also access to the iOS beta today before it’s released, plus you’ll save 20% the 2012 pricing.

The Wiert Corner - irregular stream of stuff: Delphi XE3 inside a Windows 7 VMware Fusion VM at 2560x1600 on a 15 inch Retina MacBook Pro at 2880x1800

$
0
0

I was amazed that this is still usable:

  • Delphi XE3 inside a
  • Windows 7 VMware Fusion 4 VM at 2560×1600 on a
  • 15 inch Retina MacBook Pro at 2880×1800

You can even run VMware Fusion 4 full screen at 2880×1800, but I prefer to have the Mac Desktop and Dock to be visible.

You need SwitchResX to get the Retina MacBook to use 2880×1800 at all (otherwise you get 1920×1200 at 1.5 scale factor, which is also a 16:10 display ratio)

All in all, I’m very happy with this setup.

–jeroen

via: Screen Shot 2013-03-27 at 19.55.39 | Flickr – Photo Sharing!.

Click on the image or here for full size image.

Delphi XE3 inside a Windows 7 VMware Fusion VM at 2560x1600 on a 15 inch Retina MacBook Pro at 2880x1800


Filed under: Apple, Delphi, Delphi XE3, Development, Mac, MacBook, MacBook Retina, OS X, OS X Mountain Lion, Power User, Software Development

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

There are a couple of very interesting libraries and ideas every Delphi developer should take a look at.

The list is far from complete, but should give you a good overview on what more recent Delphi language additions like attributes, generics, helpers, overloading, are capable of.

  • ORM (Object Relational Mapping) / OPF(Object Persistence Framework)
  • Base / Data Binding
  • –jeroen


    Filed under: Delphi, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Development, Software Development

    Daniel Magin's Logfile: Apple Instruments and Delphi for iOS Movie

    $
    0
    0

    DeveloperExperts created a new Video about how to Analyze Delphi iOS Applications with Apple Instruments. Here you can see a complete Introduction about this.

    Idea and Script was created by Olaf Monien and me.

    Movie was created by Daniel Wolf and me.

    Have fun and enjoy the Introduction.

     

    Firebird News: SOCI 3.2.0 released with many Firebird changes

    $
    0
    0
    Mateusz Loskot wrote : On behalf of the whole SOCI team I extremely pleased to announce this new release of SOCI 3.2.0 version.

    Firebird News: Avanced Data Generator 3, beta 3 released

    $
    0
    0
    Upscene Productions announces a new release of: “Advanced Data Generator 3, beta 3″ This beta release includes a beta for the Firebird, MySQL and InterBase Edition. A fast test-data generator tool that comes with a library of real-life data, can generate data into your database, XML Data Files, SQL script, CSV files, has many filling [...]

    Žarko Gajić: Quick Tip: Locate / ScrollIntoView Focused Node In Virtual Tree View

    $
    0
    0

    virrtualtreeview-locatefocusedI’m a huge fan of one big gem in the Delphi third party controls arena: Virtual Tree View.

    Whatever issue I had to solve in my applications harvesting the power of the TVirtualStringTree, the component had the answer, either through vast amount of properties or through nicely exposed events.

    The only solution I was not able to find straight forward, or out of the box, is how to have a visual indication that the currently focused node is not visible in the tree. Not “not visible” as hidden but not visible as currently not in view.

    The Virtual TreeView, initially being developed by Mike Lischke and now being maintained as an open source project on Google Code is a must-use control if you are up to working with whatever you could call “nodes”.

    Again, the solution is rather simple, one only needs to know what combination of tree event + tree method + node property is required to accomplish the above.

    Therefore, here’s a simple tree having a few nodes. At one time several nodes can be selected (if allowed using the corresponding property), but only one node at one time can be focused.

    Having one node focused I needed to have a button “Locate Focused Node” made visible or hidden: visible if the focused node is “out of the view”.

    To make this work, handle the OnScroll event as (the name of the TVirtualStringtree control on my form is “tree”):

    //handles OnScroll event
    procedure TvstForm.treeScroll(
      Sender: TBaseVirtualTree; 
      DeltaX, DeltaY: Integer);
    var
      nr : TRect;
    begin
      inherited;
    
      if Assigned(sender.FocusedNode) then
        nr := sender.GetDisplayRect(sender.FocusedNode, 0, false);
    
      btnLocateFocused.Enabled := (nr.Top < 0) OR
                                  (nr.Bottom > sender.ClientHeight);
    end;
    

    The above code will make my “locate focused node” button enabled or disabled depending on the visibility of the focused node.

    When the focused node goes out of the view area of the tree, the button gets enabled.

    Clicking the button scrolls the tree so that the given node is “back” in the client area.

    procedure TvstForm.btnLocateFocusedClick(Sender: TObject);
    begin
      //get the focused node in the center of the tree!
      tree.ScrollIntoView(tree.FocusedNode, true);
    end;
    

    Note that if the node was made invisible using tree.IsVisible[node], the GetDisplayRect method would return a zero height/witdh rect structure and the button will be disabled.

    That’s it.

    Firebird News: The Firebird Book (Second Edition) released : printed and ebooks

    $
    0
    0
    The Firebird Book (Second Edition) is now available as a print on demand book (at createspace) in three parts, Volume 1: Firebird Fundamentals https://www.createspace.com/4203352 Volume 2: Developing with Firebird Data https://www.createspace.com/4206843 Volume 3: Administering Firebird Servers and Databases https://www.createspace.com/4206991 Also and also in electronic format (e-book) on the Developer DVD or as an immediate download. [...]

    DelphiTools.info: DWScript happenings

    $
    0
    0

    dws-mirrorThis is a belated news update, with only the highlights:

    Language News

    • combined property/fields declaration is now supported (same syntax as Oxygene)
    • dynamic arrays now support a Remove method, which has the same syntax as IndexOf, and can be used to remove elements by value
    • for var xxx in array syntax is now supported, which combines a local, type-inferenced variable declaration and a for … in loop.
    • unit test coverage is now at 97% for the compiler, 91% for the whole of DWScript
    • various obscure bugs found and fixed

    Script engine News

    • script engine transition from stack-based to closure-based has begun, besides internal changes, the visible impact should be improved performance for objects, records, static arrays, var and const params has been improved
    • full transition to closure-based engine (and support for anonymous methods and lambdas in the script engine) is pushed back to 2.4

    Teaser News

    Also as way of a teaser, here is a screenshot related to something brewing in the lab… it’s from a Delphi XE app running the Mandelbrot benchmark (timings are for several runs), and the “DWScript” in that screenshot is the script engine.

    dws_jit

    Note that since this screenshot was taken, performance has improved, and the pony has learned new tricks :-)

     

    The Wiert Corner - irregular stream of stuff: jpluimers

    $
    0
    0

    Just found this great answer by vcldeveloper to autoscroll a readonly logging memo in Delphi which works from Delphi 1 and up (:

    For such a simple task, you don’t need to buy a commercial component! All you need to do is to send an EM_LINESCROLL message to that memo control, to make it scroll to the last line:

    procedure ScrollToLastLine(Memo: TMemo);
    begin
      SendMessage(Memo.Handle, EM_LINESCROLL, 0,Memo.Lines.Count);
    end;
    

    If your memo is read-only to users and is updated automatically by the application, you can put a call to the above procedure in its OnChange event-handler, so that whenever the text inside the memo is changed, it is automatically scrolled down to the last line.

    –jeroen

    via: autoscrolling memo in delphi – Stack Overflow.


    Filed under: Delphi, Delphi 1, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Development, Software Development

    Firebird News: Updated Jaybird – JDBC driver Roadmap

    $
    0
    0
    Mark Rotteveel wrote on Firebird-Java group : I updated the Jaybird roadmap to outline the basic plans for Jaybird 2.3. You can find it on http://jaybirdwiki.firebirdsql.org/jaybird/doku.php?id=info:roadmap I will probably add more detail in the future. Mark

    Behind the connection: Inter Process Communication Using Pipes

    $
    0
    0
    A pipe is a communication channel between two ends. It is mostly used to communicate between processes running within a computer. As such it is an Inter Process Communication (IPC) mechanism. The concept of pipe is well known in the Linux (Unix) world. It is used on the command line to direct the output of a command as input of the next command. The so called “pipe character” is used as a syntax

    Behind the connection: Subclassing a window

    $
    0
    0
    Subclassing a window What is it? Subclassing a window is the process of intercepting all calls to the window procedure of a given window. When you subclass a window, you can get hand on every message sent/posted to the window you’ve subclassed. Why subclass? Why would you want to subclass a window ? For example if a windows does almost everything you want, but you need a few more

    Firebird News: IBObjects 4.9.14 Build 55 is released

    $
    0
    0
    Jason announced the new release : I neglected to report that I put a new release in the download area for those still using IBO 4.9.14. I back ported a number of the recent fixes that have gone into IBO 5.0.2. Here is the pertinent portion of the release notes. As always you can download [...]

    Firebird News: Django1.5.x Firebird driver with Python 3.x support ready for testing

    $
    0
    0
    Maximiliano Robaina wrote about Python3 fixes for the Firebird Django driver : I just pushed up a new commit into django-firebird github repository [1] with several python 3 fixes. If anybody can test it with python 3 and report any issue, it will be appreciated. Take into account that this improvements are available into github [...]

    Firebird News: FBLib (Firebird Pascal Library) repository has moved to Github

    $
    0
    0
    For years the FBLib (Firebird database library for Free Pascal, Delphi and Kylix) has lived in the 3rdParty directory tree of tiOPF. We are cleaning up the tiOPF repository, and so I have now moved the FBLib project out to Github, into its own repository. The repository history is intact. I still need to add [...]

    Firebird News: New version of FenixSQL 0.92 is released

    $
    0
    0
    Alessandro Batisti announced new version of FenixSQL (simple multiplatform admin tool for Firebird developed with Firebird Library and released under GPL License and produced with Lazarus ide) Code and download page is located on google code and main page is here http://fblib.altervista.org
    Viewing all 1725 articles
    Browse latest View live