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 2,432 other followers

Archive for May 4th, 2021

Preference variable $ConfirmPreference allows getting more or less PowerShell confirmation prompts

Posted by jpluimers on 2021/05/04

On my list to experiment with are [Wayback] about_Preference_Variables – PowerShell | Microsoft Docs, especially

$ConfirmPreference

Determines whether PowerShell automatically prompts you for confirmation before running a cmdlet or function.

The $ConfirmPreference variable’s valid values are HighMedium, or Low. Cmdlets and functions are assigned a risk of HighMedium, or Low. When the value of the $ConfirmPreference variable is less than or equal to the risk assigned to a cmdlet or function, PowerShell automatically prompts you for confirmation before running the cmdlet or function.

If the value of the $ConfirmPreference variable is None, PowerShell never automatically prompts you before running a cmdlet or function.

To change the confirming behavior for all cmdlets and functions in the session, change $ConfirmPreference variable’s value.

To override the $ConfirmPreference for a single command, use a cmdlet’s or function’s Confirm parameter. To request confirmation, use -Confirm. To suppress confirmation, use -Confirm:$false.

Valid values of $ConfirmPreference:

  • None: PowerShell doesn’t prompt automatically. To request confirmation of a particular command, use the Confirm parameter of the cmdlet or function.
  • Low: PowerShell prompts for confirmation before running cmdlets or functions with a low, medium, or high risk.
  • Medium: PowerShell prompts for confirmation before running cmdlets or functions with a medium, or high risk.
  • High: PowerShell prompts for confirmation before running cmdlets or functions with a high risk.

–jeroen

Posted in .NET, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »

From Yahoo closing Answers tonight to blocking ads on YouTube

Posted by jpluimers on 2021/05/04

The discussion on Yahoo closing Answers tonight quickly went from alternative text based question/answer sites to long YouTube videos having hardly any content but ads, to blocking these ads: [Wayback] Yahoo sluit Answers-dienst na vijftien jaar en verwijdert inhoud – IT Pro – Nieuws – Tweakers

So here are some links where I can learn a bit of browser plugin and Android development technology as well:

(What I dislike most about ads is that they start at unnatural positions in the stream and cover topics I’m totally not interested in).

–jeroen

Posted in Android, Android Devices, Development, Mobile Development, Power User, SocialMedia, Software Development, Web Development, YouTube | Leave a Comment »

Delphi …hide the scrollbars of a DBGrid?

Posted by jpluimers on 2021/05/04

Recently I needed a plain TDBGrid without a horizontal scrollbar. I based it on the below solutions, but using an interposer class (type TDBGrid = class(TDBGrid) ... end;).

Another solution is to redirect the WinProc for a single grid component to a different method (you can apply it to the similar TDBCtrlGrid class as well):

unit DBGridFormUnit;
uses
  Winapi.Messages,
  Vcl.DBGrids,
  Vcl.Forms;

type
  TDBGridForm = class(TForm)
    DBGrid: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  strict private
    OriginalDBGridWindowProc : TWndMethod;
    procedure DBGridWindowProc(var Message: TMessage);
  end;

implementation

uses
  Winapi.Windows;
procedure TDBGridForm.FormCreate(Sender: TObject);
begin
  OriginalDBGridWindowProc := DBGrid.WindowProc;
  DBGrid.WindowProc := DBGridWindowProc;
end;

procedure TDBGridForm.FormDestroy(Sender: TObject);
begin
  DBGrid.WindowProc := OriginalDBGridWindowProc;
end;

procedure TDBGridForm.DBGridWindowProc(var Message: TMessage);
const 
  ScrollStylesToExclude = WS_VSCROLL or WS_HSCROLL;
var 
  Style: Integer;
begin
  if Message.Msg = WM_NCCALCSIZE then
  begin
    Style := GetWindowLong(Handle, GWL_STYLE);
    if (Style and ScrollStylesToExclude) <> 0 then // any scroll style to exclude present?
      SetWindowLong(Handle, GWL_STYLE, Style and not ScrollStylesToExclude);
  end
  else
    OrigWndProc(Message);
end;
end.

I think the SwissDelphiCenter solution in [WayBack] …hide the scrollbars of a DBGrid? originally has been copied from the 2003 post by Peter Below at [WayBack] how to hide DBCtrlGrid scrollbars – delphi.

(*
Q:
I want to hide the vertical scrollbar on a dbgrid when the record count
exceed a number. How can I do that?

A:
Make a descendent of the TDBGrid class. Add a handler for the
WM_NCCALCSIZE message.

Title: ...hide the scrollbars of a DBGrid?

Author: P. Below 

Category: VCL
*)
type
  TNoScrollDBGrid = class(TDBGrid)
  private
    procedure WMNCCalcSize(var Msg: TMessage);
    message WM_NCCALCSIZE;
  end;

procedure TNoScrollDBGrid.WMNCCalcSize(var Msg: TMessage);
const
  Scrollstyles = WS_VSCROLL or WS_HSCROLL;
var
  Style: Integer;
begin
  Style := GetWindowLong(Handle, GWL_STYLE);
  if (Style and Scrollstyles) <> 0 then
    SetWindowLong(Handle, GWL_STYLE, Style and not Scrollstyles);
  inherited;
end;

//This removes both scrollbars. If you want to remove only the vertical one
//change the scrollstyles constant accordingly.

I like this derived class from [WayBack] Delphi VCL Component • View topic • Hiding Scrollbars in DBGRID by Chris Luck based on the code from Peter Below more (I slightly condensed it from non-relevant code):

unit NoScrollDBGrid;

interface

uses
  Windows, Messages, DBGrids;

type
  TNoScrollDBGrid = class(TDBGrid)
  private
    FVertScroll: Boolean;
    FHorzScroll: Boolean;
    procedure WMNCCalcSize(var msg: TMessage); message WM_NCCALCSIZE;
    procedure SetVertScroll(Value: Boolean);
    procedure SetHorzScroll(Value: Boolean);
  published
    property VertScroll: Boolean read FVertScroll write SetVertScroll;
    property HorzScroll: Boolean read FHorzScroll write SetHorzScroll;
  end;

procedure Register;

implementation

uses
  Classes;
procedure TNoScrollDBGrid.SetVertScroll(Value: Boolean);
begin
  if FVertScroll <> Value then
  begin
    FVertScroll := Value;
    RecreateWnd;
  end;
end;

procedure TNoScrollDBGrid.SetHorzScroll(Value: Boolean);
begin
  if FHorzScroll <> Value then
  begin
    FHorzScroll := Value;
    RecreateWnd;
  end;
end;

procedure TNoScrollDBGrid.WMNCCalcSize(var msg: TMessage);
var
  style: Integer;
begin
  style := getWindowLong( handle, GWL_STYLE );

  if (NOT(FHorzScroll)) AND ((style and WS_HSCROLL) <> 0) then
    SetWindowLong( handle, GWL_STYLE, style and not WS_HSCROLL );

  if (NOT(FVertScroll)) AND ((style and WS_VSCROLL) <> 0) then
    SetWindowLong( handle, GWL_STYLE, style and not WS_VSCROLL );

  inherited;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TNoScrollDBGrid]);
end;

end.

–jeroen

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

 
%d bloggers like this: