<?php
class DB {
private $_connection;
private static $_instance; //The single instance
private $_host = "localhost";
private $_username = "root";
private $_password = "";
private $_database = "database";
/*
Get an instance of the Database
@return Instance
*/
public static function getInstance() {
if(!self::$_instance) { // If no instance then make one
self::$_instance = new self();
}
return self::$_instance;
}
// Constructor
private function __construct() {
$this->_connection = new mysqli($this->_host, $this->_username,
$this->_password, $this->_database);
// Error handling
if(mysqli_connect_error()) {
trigger_error("Failed to conencto to MySQL: " . mysql_connect_error(),
E_USER_ERROR);
}
}
// Magic method clone is empty to prevent duplication of connection
private function __clone() { }
// Get mysqli connection
public function getConnection() {
return $this->_connection;
}
}
?>
All About Delphi
Tuesday, June 7, 2016
Thursday, September 20, 2012
Delphi SendMessage of string
This is how you sendmessage a string passing it either WParam or LParam.
procedure MySenderFunction;
var
sText: String;
begin
sText := 'This is a test'.
SendMessage(Handle, WM_MYMESSAGE, Integer(@sText), 0) ;
end;
This is how you get the parameter being passed.
procedure MySenderFunction(Msg: TMessage);
var
sText: String;
begin
sText := PString(Msg.WParam)^;
end;
procedure MySenderFunction;
var
sText: String;
begin
sText := 'This is a test'.
SendMessage(Handle, WM_MYMESSAGE, Integer(@sText), 0) ;
end;
This is how you get the parameter being passed.
procedure MySenderFunction(Msg: TMessage);
var
sText: String;
begin
sText := PString(Msg.WParam)^;
end;
Thursday, August 9, 2012
Tuesday, July 17, 2012
String grid filter
procedure MyFilter(AFilter: String);
begin
grid.Filter.Clear;
with grid.Filter.Add do
begin
Condition:=AFilter;
Column:=1;
end;
grid.FilterActive:=active;
end;
begin
grid.Filter.Clear;
with grid.Filter.Add do
begin
Condition:=AFilter;
Column:=1;
end;
grid.FilterActive:=active;
end;
Thursday, April 7, 2011
Checking if a folder is empty.
function IsDirectoryEmpty(const ADirectory: String): Boolean;
var
searchRec: TSearchRec;
begin
try
FindClose(searchRec);
end;
end;
var
searchRec: TSearchRec;
begin
try
Result := (FindFirst(ADirectory+'\*.*', faAnyFile, searchRec) = 0) ANDfinally
(FindNext(searchRec) = 0) AND
(FindNext(searchRec) <> 0);
FindClose(searchRec);
end;
end;
Thursday, February 17, 2011
Block Alt-F4 in Delphi
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = VK_F4) and (ssAlt in Shift) then
Key := 0;
end;
begin
if (Key = VK_F4) and (ssAlt in Shift) then
Key := 0;
end;
Wednesday, February 16, 2011
How to Minimize All Windows
uses ComObj;
procedure MinimizeAll;
var
Shell : OleVariant;
begin
try
Shell := CreateOleObject('Shell.Application') ;
Shell.MinimizeAll;
finally
end;
end;
procedure MinimizeAll;
var
Shell : OleVariant;
begin
try
Shell := CreateOleObject('Shell.Application') ;
Shell.MinimizeAll;
finally
end;
end;
Subscribe to:
Comments (Atom)