Android smartphone

2010-12-11

Multi-tier project with delphi.

First step.You must have the following things.
1. Socketserver. You can find socket server in "c:\program files\borland\delphi7\bin\".The following is below figure.

2. Server application.You can create server application you self.
3. Datasnap component for client application.


Second step.What is socket server do.
Socket server is using easy define port for client connecting.You can add and remove port with once.When you run scktsrvr.exe it is going to tray icon.
You only double click scktsrvr icon in tray icon.Socket manager is appear.And you can add and remove port no.

Third step.Create application server.
Create server application.Go to file/new/application menu.See below figure.

Add remote data module into application.See this below.
Go to file/new/Other menu.

Go to multitier tab and select remote data module icon.
Click OK button.And entry coClass name.(coClass name is server data module.)
When you have remote data module you will past connection, dataset, provider component.
In this case study I am using AdoConnection, AdoQuery, Datasetprovider.Put you component like this.
Setting con1.
Build connection string.
Define connection parameter.(This exam is connect to northwind database on local server.)
Click OK button.

Setting and entry sql command in Qry1.
Assign connection (con1) into connection property of Qry1.
And entry command into SQL Property.See figure below.
Click OK button to close SQL command editor.
Setting dataset provider.
Assign "Qry1" into Dataset property of Datasetprovider.
When you completed step.You save as projects is Appserverp.dpr. (Form1)Unit1 rename Form1 as frmAppserver and Unit1 save as Appserveru.pas.rmdataserver unit save as rmdataserveru.pas.And press F9 to run project.
TO BE CONTINUE.
















2010-07-18

How to make the whole form behave like the titlebar ?

Sometimes you want to create a fancy looking form from a bitmap, like WinAMP or K-Jöfol. This part isn't too hard. All you have to do is make a cool graphic, use the TImage component and set the form's border style to bsNone. Well, all's good until we want to move the form... Since there is no title bar there may be problems with this:) Well, as you should already know Delphi can get over any problem. All we have to do is manually take care of the WM_NCHITTEST Windows message.

In this example a TImage component named imgTitle will act like the windows title bar.

unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, ExtCtrls, jpeg;
type
TForm1 = class(TForm)
imgTitle: TImage;
private
{ Private declarations }
public
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
{ Public declarations }
end;
var Form1: TForm1;
implementation

{$R *.dfm}
procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
var P: TPoint;
begin
inherited;
P := ScreenToClient(SmallPointToPoint(Message.Pos));
with imgTitle do
if (P.X >= Left) and (P.X < Left + Width) and (P.Y >= Top) and (P.Y < Top + Height) then
Message.Result := htCaption;
end;
end.


Credit for: mailto:m3rlin@programmer.netm3rlin
 
When you left click and move mouse this form will move.

2010-06-27

Function WNetConnectionDialog() to map drive.

If WNetConnectionDialog(Handle, RESOURCETYPE_DISK) = NO_ERROR then
begin
     ShowMessage('New connection successfully set.');
end;

Technical review basic map drive

Technical review basic map drive.
Function GetNetworkDriveMappings(SList:TStrings):Integer;

Var
i:Char;
sPath:String;
dwMaxPathLen:DWord;
Begin
     SList.Clear;
     dwMaxPathLen:=MAX_PATH;
     SetLength(sPath,MAX_PATH);
     For I := 'A' to 'Z' Do
     If WNetGetConnection( PChar(''+i+':'),PChar(sPath),dwMaxPathLen)=NO_ERROR Then
          SList.Add(I+': '+sPath);
     Result := SList.Count;
End;

2010-06-17

Scrollbar, hide main form, hide the titlebar, Combobox

[quote=mailto:info@delphitips.comGustav Evertsson]



How can I get a horizontal scrollbar on a list box?

Send a LB_SetHorizontalExtent message to the listbox's window handle.For example, the message could be sent in the form's OnCreate:



procedure TForm1.FormCreate(Sender: TObject);

begin

   SendMessage(Listbox1.Handle, LB_SetHorizontalExtent, 1000, Longint(0));

end;

---------------------------------------------End----------------------------------------------

How to hide the main form ?

If you do not want your program starting up showing your main form, then add this line in your project (DPR) file, just after the Application.Initialize line.



Application.ShowMainForm := False;

---------------------------------------------End----------------------------------------------

How to hide the Titlebar ?

//Here is how to hide the titlebar:

Procedure TYourFormName.HideTitlebar;

Var

  Save : LongInt;

Begin

   If BorderStyle=bsNone then Exit;

   Save:=GetWindowLong(Handle,gwl_Style);

   If (Save and ws_Caption)=ws_Caption then

   Begin

      Case BorderStyle of bsSingle,

      bsSizeable : SetWindowLong(Handle,gwl_Style,Save and

                        (Not(ws_Caption)) or ws_border);

      bsDialog : SetWindowLong(Handle,gwl_Style,Save and

                     (Not(ws_Caption)) or ds_modalframe or ws_dlgframe);

      End;

      Height:=Height-getSystemMetrics(sm_cyCaption);

      Refresh;

   End;

end;

//And here is how we show it again:

Procedure TYourFormName.ShowTitlebar;

Var

  Save : LongInt;

begin

   If BorderStyle=bsNone then Exit;

   Save:=GetWindowLong(Handle,gwl_Style);

   If (Save and ws_Caption)<>ws_Caption then

   Begin

      Case BorderStyle of bsSingle,

      bsSizeable : SetWindowLong(Handle,gwl_Style,Save or

                        ws_Caption or ws_border);

      bsDialog : SetWindowLong(Handle,gwl_Style,Save or

                     ws_Caption or ds_modalframe or ws_dlgframe);

      End;

      Height:=Height+getSystemMetrics(sm_cyCaption);

      Refresh;

   End;

end;

---------------------------------------------End----------------------------------------------

How to make a TComboBox drop?

There is a windows API call to do it.



function SendMessage(Handle of the ComboBox, 1039, 1, 0);

So, if I had a TComboBox that was named LouieCombo, I would use the following code:

Procedure DropCombo(LouieCombo : TComboBox);

var

  ReturnValue : Longint;

begin

   ReturnValue := SendMessage(LouieCombo.Handle, 1039, 1, 0);

end;

---------------------------------------------End----------------------------------------------

[/quote]

2010-06-15

Get all videomodes supported by the system

[quote="zieglersoft@zieglersoft.dkZieglerSoft" ]

procedure GetVideoModes(ModeList: TStringList);
{ proc to retrieve a list of acceptable video modes of the current video card. }
{ **********************************************
Usage:
procedure TForm1.FormCreate(Sender: TObject);
var
StrList: TStringList;
begin
StrList := TStringList.Create;
try
GetVideoModes(StrList);
Memo1.Lines := StrList;
finally
StrList.Clear;
StrList.Free;
end;
end;
{************************************************ }
var
i, j: integer;
MoreModes,
AddMode: boolean;
dm: TDeviceMode;
Mode: string;
begin
ModeList.Clear;
MoreModes := True;
Mode := '';
i := 0;
while MoreModes do
begin
MoreModes := EnumDisplaySettings(nil, i, dm);
Mode := IntToStr(dm.dmBitsPerPel) + ' Bits Per Pixel ' +
IntToStr(dm.dmPelsWidth) + ' x ' +
IntToStr(dm.dmPelsHeight);
AddMode := True;
{ Check to make sure this mode is not already in the list. }
for j := 0 to ModeList.Count-1 do
if Mode = ModeList[j] then
AddMode := False;
if AddMode then
ModeList.Add(Mode);
Inc(i);
end;
end;
[/quote]

2010-01-25

detect, which version of ADO is installed ?

Author: Simon Carter

With different versions of MDAC available it is sometimes

useful to know that your application won't fail because a user
hasn't got the latest version installed.
The following function returns the ADO version installed,
you need to place ComObj in the uses clause to use this function. }

function GetADOVersion: Double;
var
ADO: Variant;
begin
try
ADO := CreateOLEObject('adodb.connection');
Result := StrToFloat(ADO.Version);
ADO := Null;
except
Result := 0.0;
end;
end;

// To use this function try something like:

procedure TForm1.Button1Click(Sender: TObject);
const
ADOVersionNeeded = 2.5;
begin
if
GetADOVersion <>then
ShowMessage('Need to install MDAC version 2.7')
else
ShowMessage(Format('ADO Version %n, is OK', [GetADOVersion]));
end;

make an ADODB Connection using OLE-Automation ?

Author: Daniel Henrique Monteiro de Carvalho (Brasil)

{...}

uses
ComObj;
{...}

function OpenConnection(ConnectionString: AnsiString): integer;
var
ADODBConnection: OleVariant;
begin
ADODBConnection := CreateOleObject('ADODB.Connection');
ADODBConnection.CursorLocation := 3; // User client
ADODBConnection.ConnectionString := ConnectionString;
Result := 0;
try
ADODBConnection.Open;
except
Result := -1;
end;
end;

function DataBaseConnection_Test(bMessage: boolean): AnsiString;
var
asTimeout,
asUserName,
asPassword,
asDataSource,
ConnectionString: AnsiString;
iReturn: Integer;
OldCursor: TCursor;
begin
OldCursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
asTimeout := '150';
asUserName := 'NT_Server';
asPassword := 'SA';
asDataSource := 'SQL Server - My DataBase';

ConnectionString := 'Data Source = ' + asDataSource +
'User ID = ' + asUserName +
'Password = ' + asPassword +
'Mode = Read|Write;Connect Timeout = ' + asTimeout;
try
iReturn := OpenConnection(ConnectionString);

if (bMessage) then
begin
if
(iReturn = 0) then
Application.MessageBox('Connection OK!', 'Information', MB_OK)
else if (iReturn = -1) then
Application.MessageBox('Connection Error!', 'Error', MB_ICONERROR

+ MB_OK);
end;
if (iReturn = 0) then

Result := ConnectionString
else if (iReturn = -1) then
Result := '';
finally
Screen.Cursor := OldCursor;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
DataBaseConnection_Test(true);
end;

check, if the Borland Database Engine (BDE) is installed ?

Author: tom

Uses
Bde;

function BDEInstalled : boolean;
begin
result := (dbiInit(nil) = 0)
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if
BDEInstalled then
ShowMessage('BDE is installed.')
else
ShowMessage('BDE is not installed.')
end;


Get the table version ?

Author: SwissDelphiCenter.ch

Homepage: http://www.swissdelphicenter.ch

function GetTableVersion(table: TTable): LongInt;
var
hCursor : hDBICur;
DT : TBLFullDesc;
begin
Check(DbiOpenTableList(table.DBHandle, True, False,
PChar(Table.TableName), hCursor));
Check(DbiGetNextRecord(hCursor, dbiNOLOCK, @DT, nil));
Result := DT.tblExt.iRestrVersion;
Check(DbiCloseCursor(hCursor));
end;