Delphi 6 : using scroll in a DBGrid with WheelMouse (version 2) 1 row at a time (better)

This one scrolls 1 row at a time

Enjoy

Coffee Cup

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, DBTables;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    Table1: TTable;
    DBGrid1: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure DBGridMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TWheelDBGrid = class(TDBGrid)
  public
    property OnMouseWheel;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  TWheelDBGrid(DBGrid1).OnMouseWheel := DBGridMouseWheel;
end;

function GetNumScrollLines: Integer;
begin
  SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @Result, 0);
end;

procedure TForm1.DBGridMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
  Grid: TDBGrid;
begin
  if WheelDelta = 0 then Exit;

  Grid := TDBGrid(Sender);

  if Assigned(Grid.DataSource) and Assigned(Grid.DataSource.DataSet) then
    with Grid.DataSource.DataSet do
    begin
      if WheelDelta < 0 then
      begin
        if not Eof then
          Next;
      end
      else
      begin
        if not Bof then
          Prior;
      end;

      // 👇 Force the grid to scroll to current record
      if Assigned(Grid.SelectedField) then
        Grid.SelectedField := Grid.SelectedField;
    end;

  Handled := True;
end;

end.

What is the PHP enye (“ñ”) version conversion

When you live in the Philppines, you will probably encounter names and places that have the enye (“ñ”) symbol. For us developers, it comes out diferently especially in databases and labels.

For the database, it comes out as DASMARIñAS CAVITE with the character “ñ”

Once you put this character in your code, it will translate to enye (“ñ”).

What i use when a user encodes it, is to convert it using string replace.

$mystring = str_replace("DASMARI?","DASMARIñ",$mystring);
$mystring = str_replace("DASMARI�","DASMARIñ",$mystring);

Hope this helps someone out there in the web.

Coffee Cup

Interbase – How to manually round calculate 3rd decimal [SOLVED]

I have seen a few computations done in interbase and a lot of them have trailing decimals after them and if we want to round them manually, this is what I have come up with.

Suggestions and alternative solutions are always welcome. I am using a few variables so I can see the results of the computation as they unravel.

/* 889.125 */
VINT1 = (PANNUAL_TAX * 100);
VAMT1 = (VINT1 / 100);

VINT2 = (PANNUAL_TAX - VAMT1) * 1000;
VAMT2 = VINT2;

IF (VAMT2 >= 50) THEN
     VAMT3 = VAMT1 + 0.01;
ELSE VAMT3 = VAMT1;

PANNUAL_TAX = VAMT3;

The PANNUAL_TAX is the variable that holds the 2 decimal result.

Enjoy,

Coffee Cup

Delphi: Check Internet Connection [SOLVED]

Recently a lot of apps right now are becoming internet dependent. Currently the project I am working on requires the system to know if there is internet or not.

Here is the code snippet I found

uses WinInet;
 
var
  origin: cardinal;
begin
  if InternetGetConnectedState(@origin,0) then
    ShowMessage('Connected!')
  else
    ShowMessage('Not connected')
  end;
end;

Enjoy

Coffee Cup

Loading

PHP File going to Microsoft Excel “The file is corrupt and cannot be opened” [solved]

Encoutered this issue with a website I was working on. When i convert the data to excel it comes out with message “The file is currpt and cannot be opened”.

When I tried to do research I found a page that says you open the file using notepad and then save it. Once done, you can open it normally.

To my end I was able to solve it by moving the access codes (user , password , database) of the mysql to the actual page itself. Usually I reference it from another php page. But this time, moving it solved my problem

Hope this helps somebody out there

Coffee Cup

Dephi and Quickreport – How to get Page Number

Hi guys,

Recently I encountered a challenge in quickreport that has 2 specific criteria. The invoice report I was making needs to behave both as a page footer and a summary band.

Well the page footer needs to stay because there was a gap at the bottom to write the page number and signature boxes. The summary band comes in because the total amount of the invoices needs to be positioned at the bottom

How to solve it. I took the total number of pages and when the report reaches the last page, the system will display the total amount

  1. Quickreport needs to have a PageHeaderBand
  2. Inside the PageHeaderBank BeforePrint event handler you can ask for the QuickREport1.QRPrinter.PageNumber

Those were the 2 tips that I got from stockoverflow. Really big help for me.

Hope this article helps

Coffee Cup

Delphi Buttons – Create an hour glass impression while waiting

Got a chance to receive source code from a software vendor and the button on this program made me smile.

Haven’t though of it that way. But i think it works.

procedure TSFTPClientFrame.btConnectSSHClick(Sender: TObject);
var
  OldCursor: TCursor;
begin
  OldCursor := Screen.Cursor;
  try
    Screen.Cursor := crHourGlass;
    ScSSHClient.Connect;
  finally
    Screen.Cursor := OldCursor;
  end;
end;

The hour glass cursor is within the try row. Once it is done, it revert backs the cursor to the original one used. Pretty awesome.

Just wanted to share

Coffee Cup

Oracle Virtual PC – menu missing [solved]

It’s been days since the menu on top of virtual pc dissapeared after I chose the fullscreen mode. Good thing there is google.

Found the switch. And it is RIGHT-CONTROL yeah, not the left control key. It’s RIGHT+CONTROL + C

Viola! Enjoy!

Coffee Cup