Android smartphone

2009-10-27

Create form template. And used.

Create form template. And used.

Author: Friend88


Open Delphi program Project1 and Form1 to create and then solve the Property name of Form1 and Form1 is Templete1 Save.
Unit file name is Templeteu.pas. Elements arranged on demand and then Save project as TestTempletep.dpr.
Form elements created by this photo below.

// Feature set as the value below.

object Templete1: TTemplete1

Left = 192

Top = 107

Width = 783

Height = 540

Caption = 'Templete1'

Color = clBtnFace

Font.Charset = DEFAULT_CHARSET

Font.Color = clWindowText

Font.Height = -15

Font.Name = 'Tahoma'

Font.Style = [fsBold]

OldCreateOrder = False

DesignSize = (

775

513)

PixelsPerInch = 96

TextHeight = 18

object Panel1: TPanel

Left = 16

Top = 8

Width = 745

Height = 41

Anchors = [akLeft, akTop, akRight]

BevelOuter = bvLowered

Caption = 'Templete'

Color = clBackground

Font.Charset = DEFAULT_CHARSET

Font.Color = clWindow

Font.Height = -15

Font.Name = 'Tahoma'

Font.Style = [fsBold]

ParentFont = False

TabOrder = 0

end

object Panel2: TPanel

Left = 16

Top = 56

Width = 169

Height = 441

Anchors = [akLeft, akTop, akBottom]

BevelInner = bvLowered

TabOrder = 1

object BitBtn1: TBitBtn

Left = 8

Top = 16

Width = 153

Height = 25

Caption = 'Function1'

TabOrder = 0

end

object BitBtn2: TBitBtn

Left = 8

Top = 48

Width = 153

Height = 25

Caption = 'Function2'

TabOrder = 1

end

end

object Memo1: TMemo

Left = 192

Top = 56

Width = 569

Height = 145

Anchors = [akLeft, akTop, akRight]

Font.Charset = DEFAULT_CHARSET

Font.Color = clWindowText

Font.Height = -48

Font.Name = 'Tahoma'

Font.Style = [fsBold]

Lines.Strings = (

'Hello!'

'')

ParentFont = False

TabOrder = 2

end

end

//---------------------------------------------------------------------------------------------------

Form to create its next project, go to File -> New -> Other -> then select the page. TestTempletep.

Will look similar to the Form Templete2.Templete we built.
***To note that the derivative TTemplete2 from Class TTemplete1.


2009-10-23

Creating shadows to TLabel.

Author: Friend88
Process.
TLabel 2 a place as one of the main text of the mirror.Set tranparent property is true.


Then Bring it back to the text shadow.
Adjust color and font that is different from the shadow of the main text used to be referred to as fine as polished like.





2009-10-22

Delphi DLL

Author:Friend88

Delphi DLL


File an extension. DLL File is still more mysterious is the File that we dare not even own your own delete it certainly did not know that the Application of which must be used. Associated with it or what. If you accidentally deleted. May cause system performance or Application error, especially File. DLL in Windows Folder, then the DLL is what stands DLL Dynamic Linked Library is bringing both snippets Procedure and Function come together in a single File. we call this type that File Library.

It is a special DLL that is not an Application to Run as self-General Application, but it will wait act. Application programming services to sub for the other sub-programs run within the File DLL 2 format is possible.


1. Static Loading means that once the Application is running and running. Snippets from the File DLL File Load which will be used to keep forever.
2. Dynamic Loading means snippets from Load File DLL is only when they want to run sub-programs only.

When the pin mold package integrated run both models will see Static Loading a result, the Application does not work when no File DLL reference. Also, the behavior. At wasting memory space than it is to the desired Load all stored in memory before when some Function may be running in just a little time. However, it is stored. In memory without using any no.
However, Dynamic Loading is even more better in terms of user memory space. Effectively. have any more busy, but its use and make work behind. Operating system worse. Therefore choose to use depends on the size of a small Application is subject to Article Ka Static Loading to no speed. If the waste area slightly larger Application packet as we often must use Dynamic Loading already.

Top.
Advantages DLL.
For a DLL that has major advantages are as follows: 3 points.
1. To share the resources of the Ne system effectively. Let us consider why the program is 5 each with the same working Function. If each of File 500 KB in size, this means we lose the region to approximately 2.5 MB, but if we separate out the same as Function of working out the same. Used in packet
File, which allows the same area as if the packet into filtration microsurgery at work when a well is approximately 300 KB and that the resources will be 5 File Ns only 1.3 MB instead of 2.5 MB.
2. Easy to change. The work must be frequently changed. We tend to keep the changes in the File DLL because it allows us to edit easily. The only change that changes in the File DLL only more work and the frequent changes. Is used by many more Application should be stored in each Share File DLL and use.
3. Bringing recyclability. Bringing back a new or Reuse is important in the development process Software can program it. Large. SOI has a piece of small packet. By each sub-store may act Function J. bring it clear. Is the same concept to create a Component sure enough, just keep Function File DLL will help us take it that no new Function to write every time if ever existing. They use what is the best to all.

Top.
Creating DLL.

We will try to create a DLL to create step by using the Function Calculator way. Electronics and electric power on measuring voltage and resistance is the power we will see a 4 Function in the work associated with the following Sut.
E = IR.
I = E / R.
R = E / I.
P = EI.
E is the voltage with the attack is Volt.
I was a power failure is the Ampare.
R is the resistance to attack Ohm.
P is the power of the attack is Watt.
We begin to create a DLL 4 Function work out
.
Delphi Open menu File> New> Other ... When Dialog New Items up Click Select DLL Wizard, and then Click the OK button image.













Delphi Code Editor will display just to Application DLL only because there is no user interface is not shown in the Form Designer to the images.












Over time we will write that we need both Code 4 Function follows.












These pictures are from a point that there are 2 points Palace Gate is a Function with a stdcall suffix and point 2 is based on exports declared Application note and the other running from the name listed if we want. build. Function / Procedure in the DLL, but do not want to be running, we do not have to end with the line name Function stdcall application then do not add names. Function / Procedure. After the write command exports after bone MRI are paid will have to Compile a File DLL Function 4 Function in the DLL of us.

To understand more Download Sample Source Code Here.

Top.
Run a DLL and Static.

After we have created the DLL, then we will try to create Application Run DLL as we write more.
Open Delphi and create a new Project was designed as a Form layout.

Double Click a button calculate voltage and write Code to bring the information to complete the calculation by measuring voltage to run the Function EVolt File ElectronicsCal.dll. We have created the following.













For activation. Will be announced prior to the Function follows from DLL.


function EVolt(IVal,RVal : double) : double; stdcall;
external 'ElectronicsCal.dll';
function IAmpare(EVal,RVal : double) : double; stdcall;
external 'ElectronicsCal.dll';
function ROhm(EVal,IVal : double) : double; stdcall;
external 'ElectronicsCal.dll';
function PWatt(EVal,IVal : double) : double; stdcall;
external 'ElectronicsCal.dll';


For activation. Will be announced prior to the Function follows from DLL.

Top.
Running a DLL Dynamic.

Examples from the past. We run a Function of Static Loading DLL that is the way to Load Application Function or Procedure to remove it from the DLL from running at startup, so if the Application for File DLL not found. Will error. And not available. The run is a Static Loading preceded by words that specify the steps announced enternal Function.
Although Static Loading is easy to use. But there are disadvantages is that the Function and Procedure are Load in memory at all times when not being used in a Dynamic Loading at any time, so it will be more appropriate. But running is more difficult. It will be run from Windows, including more specific Function LoadLibrary, FreeLibrary and GetProcAddress.
To understand we will update the original Application to Dynamic Load a following.








The code will see that we use Function LoadLibrary to run a DLL that you want to use the Function by Function Return value is called a packet Hnadle figures referred to by the File Handle This value is used to. Function calls in the DLL, we will use the Function GetProcAddress called last when finished will be used to perform Function FreeLibrary returned to the operating system resources. This makes running a Dynamic Loading is minimal because the resources do not remove the Function of Load File DLL you want it from the Terminal itself.
To understand more Download Sample Source Code Here.

Top.
Caution in the running DLL.

DLL File is created. We rely on the structure of language Object Pascal and Delphi is a tool used to create the Application that will run most ideal is generated by Delphi Application because the concepts and DLL File should be run from Application created by any language. time whether a C or Visual Basic, but practical problems might occur as well.
Primarily from the inherent structure of language. This may be the data type. The different actions. Some do not make the same. The best option for creating a DLL is usually conclude that because the C language is the original language. That works with Windows because Windows is using C, but will write a DLL to create more complex because we must understand. The C programming language and data structures. Within the Windows operating system to create a DLL in addition, we should use the Exception Handling to help because if a problem occurs. We were able to Clear the resource rebate operating system without problems. A way to create a DLL as a professional.
Use information as a standard Windows user.
Programming using the Exception Handilng.
Overload Function is used to check the name or names Function Procedure is the same name but different Parameter sets together with data by category.
Form included into DLL.
Use Windows API in the DLL.
That said, the. We must learn more. About System Programming for Windows provides a deeper below.
Work and an Event Driven Programming in Windows, which must be C and I will bring this issue into part of the C Builder.
Message Loop and Message types.
Structure of important information in Windows.
Memory management of Windows.
Process and Thread.
Top.
Windows API.

Windows API (Application Program Interface) is that thousands of other Function Function of the process has provided the Windows Application developers can run them by Function that is stored in multiple DLL File File operating system that File. that are important to know.
Function included in the KERNEL32.DLL functions associated with Process and memory management of operating systems. In addition to managing the. Use of resources. System together.
GDI32.DLL contained within the act Function Management System Graphic Display of the operating system.
USER32.DLL Function that acts within the packaging associated with the management of users. Application switcher like the right to use and the use of such Component.
To understand more Download Sample Source Code Here.
Top.
Stream.

Management about reading. And written information that we use to create the Object Class called Stream Stream management can help manage the review. And write. A range of formats such as Buffer, String, File, or Socket TStream As for a Class of Stream brings to us to deal with reading. And write. We need to identify the media. To read and write because that is inherited from Class TStream to manage, especially as Class TFileStream will read and write or File Class TMemoryStream. Will be used to read and write. Data from memory, etc. Class includes inherited from TStream.


  • THandleStream


  • TFileStream


  • TCustomMemoryStream


  • TMemoryStream


  • TStringStream


  • TResourceStream


  • TWinSocketStream

Method of Stream


Read read. We need to locate. Read the first to start the type of storage. And length of data to be read by Method Return Value This is the length of data read unit is structured as follows: Byte function Read (var Buffer; Count: longint): longint;
Write to write data. We must identify the starting point to write the type of storage. And length of data to be written by this Method Return value is the length of data written into the unit is structured as follows: Byte function Write (const Buffer; Count: longint): longint;
Top.
FileStream.

With Stream variety, but an interesting model year is that we will use FileStream Questions in reading and writing data to a File, especially in the Text File that we will use in Class TFileStream Stream to build. read and write data on a Disk File in addition to Read and Write Method major, we also recognize the need for the Create Method Create Method is a packet used to create or open the File that must be named File. that will create or open the File name and what to create or open the File Mode with any details.
fmCreate if File is not mentioned previously. To create a File if it was already open for writing File.
fmOpenRead File to open a read-only.
fmOpenWrite is open to authors only File. The packet will be overwritten as the original File.
fmOpenReadWrite File to open a read and write

Using COM Object in delphi

Author: Friend88

// Using Com object in delphi

// Declare comObj in declaratioin block

//

Unit TestCOMOjbe;

Interface

uses ComObj;

...

function functionname(parameter):<result type>

implement

function functionname(parameter):<result type>;

var OleVariantName:OleVariant

begin

OleVariantName := CreateOLEOjbect('ComObject Name');

...

OleVariantName.UnInitialize;

end;

ActiveX Script

Set objFSO = CreateObject("Scripting.FileSystemObject")

Sub CreatePath(strPath)

If Not objFSO.FolderExists( objFSO.GetParentFolderName(strPath) ) then Call CreatePath( objFSO.GetParentFolderName(strPath) )

objFSO.CreateFolder( strPath )

End Sub

Run SQL package by delphi

Author :Freiend 88

Example: The function use to calling package of SQL server.

function ExecDTS(const PackageName: String): Boolean;
var
pVarHost: OleVariant;
EmptyStr: OleVariant;
pkg: OleVariant;
i:integer;
begin
pkg := CreateOLEObject('DTS.Package');
EmptyStr := WideString('');
pkg.LoadFromSQLServer(fservername,
fusername,
fpassword,
0,
EmptyStr,
EmptyStr,
EmptyStr,
WideString(PackageName),
pVarHost);
pkg.FailOnError := True;
for i := 1 to pkg.Steps.Count do
pkg.Steps.Item(i).ExecuteInMainThread := True;
pkg.Execute;
Result := True;
pkg.UnInitialize;
end;

2009-10-12

How to use GetTempFileName to create a unique temporary file?

This tips comes from our partner SwissDelphiCenter.ch

mailto:info@delphitips.com.

Author:
Gustav Evertsson

function GetTempFile(const Extension: string): string;
var
Buffer: array[0..MAX_PATH] OF Char;
begin
GetTempPath(Sizeof(Buffer)-1,Buffer);
GetTempFileName(Buffer,'~',0,Buffer);
result := StrPas(Buffer);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetTempFile('.tmp'));
// The temp. file looks like C:\WINDOWS\TEMP\~61D5.TMP
end;

{Note:
The GetTempFile function just returns a unique filename but
doesn't create the file. }

How to show Directories in a TTreeview?

This tips comes from our partner SwissDelphiCenter.ch

mailto:info@delphitips.com

Author:
Gustav Evertsson
Ratings: 0, Votes: 0

procedure TForm1.GetDirectories(Tree: TTreeView; Directory: string; Item: TTreeNode; IncludeFiles: boolean);
var
SearchRec: TSearchRec;
ItemTemp: TTreeNode;
begin

Tree.Items.BeginUpdate;
if Directory[length(Directory)] <> '\' then Directory := Directory + '\';
if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then
begin
repeat
if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] <> '.')

then
begin
if (SearchRec.Attr and faDirectory > 0) then
Item := Tree.Items.AddChild(Item, SearchRec.Name);

ItemTemp := Item.Parent;
GetDirectories(Tree, Directory + SearchRec.Name, Item, IncludeFiles);
Item := ItemTemp;
end else

if IncludeFiles then
if SearchRec.Name[1] <> '.' then
Tree.Items.AddChild(Item, SearchRec.Name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
Tree.Items.EndUpdate;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetDirectories(TreeView1, 'C:\', nil, True);
end;

How to retrieve the UNC Paths?

This tips comes from our partner SwissDelphiCenter.ch

mailto: info@delphitips.com

Author:
Gustav Evertsson
Ratings: 0, Votes: 0

ExpandUNCFileName returns the full path of the FileName
with the network drive portion in UNC format.
The pathname in the UNC-Format has the format:
\\Servername\sharename

//Example
Label1.Caption := ExpandUNCFileName('K:\sharename.tmp'));

{where "K" is a Network Drive.}

How to get the owner of a file ?

This tips comes from our partner SwissDelphiCenter.ch

mailto:info@delphitips.com

Author:
Gustav Evertsson
Ratings: 0, Votes: 0
// When you create a file or directory, you become the owner of it.
// With GetFileOwner you get the owner of a file.
function GetFileOwner(FileName: string; var Domain, Username: string): Boolean;
var
SecDescr: PSecurityDescriptor;
SizeNeeded, SizeNeeded2: DWORD;
OwnerSID: PSID;
OwnerDefault: BOOL;
OwnerName, DomainName: PChar;
OwnerType: SID_NAME_USE;
begin
GetFileOwner := False;
GetMem(SecDescr,1024);
GetMem(OwnerSID,SizeOf(PSID));
GetMem(OwnerName,1024);
GetMem(DomainName,1024);
try
if not GetFileSecurity(PChar(FileName),
OWNER_SECURITY_INFORMATION,
SecDescr,1024,SizeNeeded) then
Exit;
if not GetSecurityDescriptorOwner(SecDescr,
OwnerSID,OwnerDefault) then
Exit;
SizeNeeded := 1024;
SizeNeeded2 := 1024;
if not LookupAccountSID(nil,OwnerSID,OwnerName,
SizeNeeded,DomainName,SizeNeeded2,OwnerType) then
Exit;
Domain := DomainName;
Username := OwnerName;
finally
FreeMem(SecDescr);
FreeMem(OwnerName);
FreeMem(DomainName);
end;
GetFileOwner := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Domain, Username: string;
begin
GetFileOwner('YourFile.xyz',domain,username);
ShowMessage(username + '@' + domain);
end;

// Note: This only works under NT.

How to check to see if a drive is ready

Gustav Evertsson
Ratings: 0, Votes: 0

The following function accepts a drive letter as a parameter, and it will return a boolean value that indicates whether or not there is a disk in the drive.

function DiskInDrive(Drive: Char): Boolean;
var
ErrorMode: word;
begin
{ make it upper case }

if Drive in ['a'..'z'] then Dec(Drive, $20);


{ make sure it's a letter }

if not (Drive in ['A'..'Z']) then
raise EConvertError.Create('Not a valid drive ID');


{ turn off critical errors }
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);


try
{ drive 1 = a, 2 = b, 3 = c, etc. }
if DiskSize(Ord(Drive) - $40) = -1 then
Result := False
else
Result := True;
finally
{ restore old error mode }
SetErrorMode(ErrorMode);
end;
end;

How do I convert "Long File Name.pas" to "longfi~1.pas"?

Author: Gustav Evertsson

mailto:info@delphitips.com


Get the shot file name:

Function GetShortFileName(Const FileName : String) : String;
var
aTmp: array[0..255] of char;
begin
if GetShortPathName(PChar(FileName),aTmp,Sizeof(aTmp)-1)=0 then
Result:= FileName
else
Result:=StrPas(aTmp);

end;

and the long name:

Function GetLongFileName(Const FileName : String) : String;
var
aInfo: TSHFileInfo;
begin
if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then
Result:= String(aInfo.szDisplayName)
else
Result:= FileName;
end;

...Select a random datarecord ?

Author: SwissDelphiCenter.ch

procedure TForm1.FormCreate(Sender:TObject);
begin
randomize;
end;

procedure TForm1.Button1Click(Sender:TObject);
begin
table1.First;
table1.MoveBy(Random(table1.recordcount));
end;

..Add a password to paradox table.

Author: SwissDelphiCenter.ch

unit Unit2;

interface
uses
bde,SysUtils,dbtables,windows;

Function TablePasswort(var table: ttable; password:string) : boolean;


implementation


function
StrToOem(const AnsiStr: string): string;
begin
SetLength(Result, Length(AnsiStr));
if Length(Result) > 0 then
CharToOem(PChar(AnsiStr), PChar(Result));
end;


Function TablePasswort(var table: TTable; password:string) : boolean;
var pTblDesc : pCRTblDesc;
hDb : hDBIDb;

begin
Result := false;
with Table do

begin
if
Active and (not Exclusive) then Close;
if (not Exclusive) then Exclusive := True;
if (not Active) then Open;
hDB := DBHandle;
Close;
end;
GetMem(pTblDesc,SizeOf(CRTblDesc));
FillChar(pTblDesc^,SizeOf(CRTblDesc),0 );
with pTblDesc^ do

begin
StrPCopy(szTblName, StrToOem(table.tablename));
szTblType:= szParadox;
StrPCopy(szPassword, StrToOem(Password));
bPack := True;
bProtected := True;
end;
if DbiDoRestructure(hDb, 1, pTblDesc, nil, nil, nil, FALSE )<> DBIERR_NONE

then exit;
if pTblDesc <> nil then FreeMem(pTblDesc, SizeOf(CRTblDesc));
result := true;
end;

..Show delete record.

Author: SwissDelphiCenter.ch

procedure deletedrecords(Table: TTable; SioNo: Boolean);
begin
Table.DisableControls;
try
Check(DbiSetProp(hDBIObj(Table.Handle), curSOFTDELETEON,
LongInt(SioNo)));
finally
Table.EnableControls;
end;
Table.Refresh;
end;

...open a password-saved paradox database without knowing the password ?

Author: Babak Sateli

If you forget your paradox table password ,then try this password , it works well

For PARADOX 7.0 use this password :"jIGGAe" or "cupcdvum"
For PARADOX 5.0 use this password : same thing
For PARADOX 4.x (DOS) use this password : "nx66ppx"

...undelete a dBASE record ?

Author: Doug Baird

procedure RecordUndelete(aTable: TTable);
begin
aTable.UpdateCursorPos;
try
Check(DbiUndeleteRecord(aTable.Handle));
except
ShowMessage('No undelete performed.');
end;
end;


2009-10-11

save a Formula One spreadsheet to a blob field

Author: Brett McLean

Uses vcf1, dbtables;


procedure SaveSpreadsheet(F1Book: TF1Book);
var
BlobStream : TBlobStream;
MyBlob : HGlobal;
pblob : Pointer;
begin
with
Datamodule1.Query1 do
begin
Set8087CW($133f);
try
Application.ProcessMessages;
F1Book.SaveWindowInfo;
MyBlob:=GlobalAlloc(GMEM_MOVEABLE, 2000);
try
F1Book.WriteToBlob(MyBlob, 0);
pBlob:=globalLock(MyBlob);
try
Blobstream:=TBlobStream.Create(TBlobField(FieldByName

('QUOTE_BLOB')),bmWrite);
try
Blobstream.Write(pBlob^,GlobalSize(myBlob));
finally
Blobstream.Free;
end;
finally
globalUnlock(MyBlob);
end;
F1book.IF1Book_Modified:=False;
finally
globalFree(myblob);
end;
finally
Set8087CW(Default8087CW);
Application.ProcessMessages;
end;
end;
end;

//Depending on your Delphi Version (<D4), you will need:
//D4 und frühere Versionen brauchen noch:

var
Default8087CW: Word = $1332;

procedure Set8087CW(NewCW: Word);
asm
MOV Default8087CW,AX
FLDCW Default8087CW
end;



Hotmail: Trusted email with powerful SPAM protection. Sign up now.

Remove a dbase index flag


Author: Alex Carrillo

function UnCheckIndex( FileDbf: String ): Boolean;
var
Dbf: File;
Car: Char;
begin
Result:= T;
AssignFile( Dbf, FileDbf );
Car := #0;
{$I-}
Reset(Dbf, 1);
If Not ErrorIO( FileDbf, IoResult ) then

Begin
Seek(Dbf, 28);
{Flag's position}
If Not ErrorIO( FileDbf, IoResult ) then
BlockWrite( Dbf, Car, 1, Num_R )
Else
Result:= F;
CloseFile(Dbf);
If ErrorIO( FileDbf, IoResult ) then
Result:= F;
End
Else
Result:= F;
{$I+}
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
If
UnCheckIndex('MyBase.dbf') Then
ShowMessage('Flag removed');
end;




Hotmail: Trusted email with Microsoft's powerful SPAM protection. Sign up now.

...pack a Table ?

...pack a Table ?

Author: Bernhard Angerer

Homepage: http://www.bluestep.com/

function dgPackParadoxTable(Tbl: TTable; Db: TDatabase):DBIResult;

{ Packs a Paradox table by calling the BDE DbiDoRestructure
function. The TTable passed as the first parameter must
be closed. The TDatabase passed as the second parameter
must be connected. }

var
TblDesc: CRTblDesc;
begin
Result := DBIERR_NA;
FillChar(TblDesc, SizeOf(CRTblDesc), 0);
StrPCopy(TblDesc.szTblName, Tbl.TableName);
TblDesc.bPack := True;
Result := DbiDoRestructure(Db.Handle, 1, @TblDesc,
nil, nil, nil, False);
end;



function dgPackDbaseTable(Tbl: TTable): DBIResult;

{ Pack a dBASE table by calling DbiPackTable. The table
passed as a parameter will be opened if it isn't open. }

begin
Result := DBIERR_NA;
if Tbl.Active = False then
Tbl.Open;
Result := DbiPackTable(Tbl.DBHandle, Tbl.Handle,
nil, nil, True);
end;




Hotmail: Trusted email with Microsoft's powerful SPAM protection. Sign up now.